-
Notifications
You must be signed in to change notification settings - Fork 1k
/
ItchioBridge.php
51 lines (46 loc) · 1.98 KB
/
ItchioBridge.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
class ItchioBridge extends BridgeAbstract
{
const NAME = 'itch.io';
const URI = 'https://itch.io';
const DESCRIPTION = 'Fetches the file uploads for a product';
const MAINTAINER = 'jacquesh';
const PARAMETERS = [[
'url' => [
'name' => 'Product URL',
'exampleValue' => 'https://remedybg.itch.io/remedybg',
'required' => true,
]
]];
const CACHE_TIMEOUT = 21600; // 6 hours
public function collectData()
{
$url = $this->getInput('url');
$html = getSimpleHTMLDOM($url);
// if the page is password protected, abort
if ($html->find('.game_password_page', 0) !== null) {
returnClientError('The requested page is password protected.');
}
$title = $html->find('.game_title', 0)->innertext;
$content = 'The following files are available to download:<br/>';
foreach ($html->find('div.upload') as $element) {
$filename = $element->find('strong.name', 0)->innertext;
$filesize = $element->find('span.file_size', 0)->first_child()->innertext;
$content = $content . $filename . ' (' . $filesize . ')<br/>';
}
// On 2021-04-28/29, itch.io changed their project page format so that the
// 'last updated' timestamp is only shown to logged-in users.
// Since we can't use the last-updated date to identify a post, we include
// the description text in the input for the UID hash so that if the
// project posts an update that changes the description but does not add
// or rename any files, we'll still flag it as an update.
$project_description = $html->find('div.formatted_description', 0)->plaintext;
$uidContent = $project_description . $content;
$item = [];
$item['uri'] = $url;
$item['uid'] = $uidContent;
$item['title'] = 'Update for ' . $title;
$item['content'] = $content;
$this->items[] = $item;
}
}