Rewrote DemonoidBridge. Fixes #626.

This commit is contained in:
teromene 2018-04-17 15:25:02 +02:00
parent 0620f30ae0
commit 7927d73719

View file

@ -4,130 +4,150 @@ class DemonoidBridge extends BridgeAbstract {
const MAINTAINER = 'metaMMA'; const MAINTAINER = 'metaMMA';
const NAME = 'Demonoid'; const NAME = 'Demonoid';
const URI = 'https://www.demonoid.pw/'; const URI = 'https://www.demonoid.pw/';
const DESCRIPTION = 'Returns results for the keywords (in all categories or const DESCRIPTION = 'Returns results from search';
a specific category). You can put several keywords separated by a semicolon
(e.g. "one show;another show"). Searches can by done in a specific category;
category number must be specified. (All=0, Movies=1, Music=2, TV=3, Games=4,
Applications=5, Pictures=8, Anime=9, Comics=10, Books=11 Music Videos=8,
Audio Books=17). User feed takes the Uploader ID number (not uploader name)
as keyword. Uploader ID is found by clicking on uploader, clicking on
"View this user\'s torrents", and copying the number after "uid=". An entire
category feed is accomplished by leaving "keywords" box blank and using the
corresponding category number.';
const PARAMETERS = array(array( const PARAMETERS = array(array(
'q' => array( 'q' => array(
'name' => 'keywords/user ID/category, separated by semicolons', 'name' => 'keywords',
'exampleValue' => 'first list;second list;…', 'exampleValue' => 'keyword1 keyword2…',
'required' => true 'required' => true,
), ),
'crit' => array( 'category' => array(
'name' => 'Category',
'type' => 'list', 'type' => 'list',
'name' => 'Feed type',
'values' => array( 'values' => array(
'search' => 'search', 'All' => 0,
'category' => 'cat', 'Movies' => 1,
'user' => 'usr' 'Music' => 2,
'TV' => 3,
'Games' => 4,
'Applications' => 5,
'Pictures' => 8,
'Anime' => 9,
'Comics' => 10,
'Books' => 11,
'Audiobooks' => 17
) )
)
), array(
'catOnly' => array(
'name' => 'Category',
'type' => 'list',
'values' => array(
'All' => 0,
'Movies' => 1,
'Music' => 2,
'TV' => 3,
'Games' => 4,
'Applications' => 5,
'Pictures' => 8,
'Anime' => 9,
'Comics' => 10,
'Books' => 11,
'Audiobooks' => 17
)
)
), array(
'userid' => array(
'name' => 'user id',
'exampleValue' => '00000',
'required' => true,
'type' => 'number'
), ),
'catCheck' => array( 'category' => array(
'type' => 'checkbox', 'name' => 'Category',
'name' => 'Specify category for keyword search ?', 'type' => 'list',
), 'values' => array(
'cat' => array( 'All' => 0,
'name' => 'Category number', 'Movies' => 1,
), 'Music' => 2,
)); 'TV' => 3,
'Games' => 4,
'Applications' => 5,
'Pictures' => 8,
'Anime' => 9,
'Comics' => 10,
'Books' => 11,
'Audiobooks' => 17
)
)
)
);
public function collectData() { public function collectData() {
$catBool = $this->getInput('catCheck'); if(!empty($this->getInput('q'))) {
if($catBool) {
$catNum = $this->getInput('cat');
}
$critList = $this->getInput('crit');
$keywordsList = explode(';', $this->getInput('q')); $html = getSimpleHTMLDOM(
foreach($keywordsList as $keywords) {
switch($critList) {
case 'search':
if($catBool == false) {
$html = getContents(
self::URI .
'files/?category=0&subcategory=All&quality=All&seeded=2&external=2&query=' .
urlencode($keywords) . #not rawurlencode so space -> '+'
'&uid=0&sort='
) or returnServerError('Could not request Demonoid.');
} else {
$html = getContents(
self::URI . self::URI .
'files/?category=' . 'files/?category=' .
rawurlencode($catNum) . rawurlencode($this->getInput('category')) .
'&subcategory=All&quality=All&seeded=2&external=2&query=' . '&subcategory=All&quality=All&seeded=2&external=2&query=' .
urlencode($keywords) . #not rawurlencode so space -> '+' urlencode($this->getInput('q')) .
'&uid=0&sort=' '&uid=0&sort='
) or returnServerError('Could not request Demonoid.'); ) or returnServerError('Could not request Demonoid.');
}
break; } elseif(!empty($this->getInput('catOnly'))) {
case 'usr':
$html = getContents( $html = getSimpleHTMLDOM(
self::URI .
'files/?uid=' .
rawurlencode($keywords) .
'&seeded=2'
) or returnServerError('Could not request Demonoid.');
break;
case 'cat':
$html = getContents(
self::URI . self::URI .
'files/?uid=0&category=' . 'files/?uid=0&category=' .
rawurlencode($keywords) . rawurlencode($this->getInput('catOnly')) .
'&subcategory=0&language=0&seeded=2&quality=0&query=&sort=' '&subcategory=0&language=0&seeded=2&quality=0&query=&sort='
) or returnServerError('Could not request Demonoid.'); ) or returnServerError('Could not request Demonoid.');
break;
} elseif(!empty($this->getInput('userid'))) {
$html = getSimpleHTMLDOM(
self::URI .
'files/?uid=' .
rawurlencode($this->getInput('userid')) .
'&seeded=2'
) or returnServerError('Could not request Demonoid.');
} else {
returnServerError('Invalid parameters !');
} }
if(preg_match('~No torrents found~', $html)) { if(preg_match('~No torrents found~', $html)) {
returnServerError('No result for query ' . $keywords); return;
} }
$bigTable = explode('<!-- start torrent list -->', $html)[1]; $table = $html->find('td[class=ctable_content_no_pad]', 0);
$last50 = explode('<!-- end torrent list -->', $bigTable)[0]; $cursorCount = 4;
$dateChunk = explode('added_today', $last50); $elementCount = 0;
while($elementCount != 40) {
$elementCount++;
$currentElement = $table->find('tr', $cursorCount);
if(preg_match('~items total~', $currentElement)) {
break;
}
$item = array(); $item = array();
//Do we have a date ?
for($block = 1;$block < count($dateChunk);$block++) { if(preg_match('~Added.*?(.*)~', $currentElement->plaintext, $dateStr)) {
preg_match('~(?<=>Add).*?(?=<)~', $dateChunk[$block], $dateStr);
if(preg_match('~today~', $dateStr[0])) { if(preg_match('~today~', $dateStr[0])) {
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
$timestamp = mktime(0, 0, 0, gmdate('n'), gmdate('j'), gmdate('Y')); $timestamp = mktime(0, 0, 0, gmdate('n'), gmdate('j'), gmdate('Y'));
} else { } else {
preg_match('~(?<=ed on ).*\d+~', $dateStr[0], $fullDateStr); preg_match('~(?<=ed on ).*\d+~', $currentElement->plaintext, $fullDateStr);
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
$dateObj = strptime($fullDateStr[0], '%A, %b %d, %Y'); $dateObj = strptime($fullDateStr[0], '%A, %b %d, %Y');
$timestamp = mktime(0, 0, 0, $dateObj['tm_mon'] + 1, $dateObj['tm_mday'], 1900 + $dateObj['tm_year']); $timestamp = mktime(0, 0, 0, $dateObj['tm_mon'] + 1, $dateObj['tm_mday'], 1900 + $dateObj['tm_year']);
} }
$cursorCount++;
}
$itemsChunk = explode('<!-- tstart -->', $dateChunk[$block]); $content = $table->find('tr', $cursorCount)->find('a', 1);
$cursorCount++;
for($items = 1;$items < count($itemsChunk);$items++) { $torrentInfo = $table->find('tr', $cursorCount);
$item = array();
$cols = explode('<td', $itemsChunk[$items]);
preg_match('~(?<=href=\"/).*?(?=\")~', $cols[1], $matches);
$item['id'] = self::URI . $matches[0];
preg_match('~(?<=href=\").*?(?=\")~', $cols[4], $matches);
$item['uri'] = $matches[0];
$item['timestamp'] = $timestamp; $item['timestamp'] = $timestamp;
preg_match('~(?<=href=\"/users/).*?(?=\")~', $cols[3], $matches); $item['title'] = $content->plaintext;
$item['author'] = $matches[0]; $item['id'] = self::URI . $content->href;
preg_match('~(?<=/\">).*?(?=</a>)~', $cols[1], $matches); $item['uri'] = self::URI . $content->href;
$item['title'] = $matches[0]; $item['author'] = $torrentInfo->find('a[class=user]', 0)->plaintext;
preg_match('~(?<=green\">)\d+(?=</font>)~', $cols[8], $matches); $item['seeders'] = $torrentInfo->find('font[class=green]', 0)->plaintext;
$item['seeders'] = $matches[0]; $item['leechers'] = $torrentInfo->find('font[class=red]', 0)->plaintext;
preg_match('~(?<=red\">)\d+(?=</font>)~', $cols[9], $matches); $item['size'] = $torrentInfo->find('td', 3)->plaintext;
$item['leechers'] = $matches[0];
preg_match('~(?<=>).*?(?=</td>)~', $cols[5], $matches);
$item['size'] = $matches[0];
$item['content'] = 'Uploaded by ' . $item['author'] $item['content'] = 'Uploaded by ' . $item['author']
. ' , Size ' . $item['size'] . ' , Size ' . $item['size']
. '<br>seeders: ' . '<br>seeders: '
@ -137,10 +157,10 @@ class DemonoidBridge extends BridgeAbstract {
. '<br><a href="' . '<br><a href="'
. $item['id'] . $item['id']
. '">info page</a>'; . '">info page</a>';
if(isset($item['title']))
$this->items[] = $item; $this->items[] = $item;
}
} $cursorCount++;
} }
} }
} }