diff --git a/bridges/DemonoidBridge.php b/bridges/DemonoidBridge.php new file mode 100644 index 00000000..f99b80fb --- /dev/null +++ b/bridges/DemonoidBridge.php @@ -0,0 +1,146 @@ + array( + 'name' => 'keywords/user ID/category, separated by semicolons', + 'exampleValue' => 'first list;second list;…', + 'required' => true + ), + 'crit' => array( + 'type' => 'list', + 'name' => 'Feed type', + 'values' => array( + 'search' => 'search', + 'category' => 'cat', + 'user' => 'usr' + ) + ), + 'catCheck' => array( + 'type' => 'checkbox', + 'name' => 'Specify category for keyword search ?', + ), + 'cat' => array( + 'name' => 'Category number', + ), + )); + + public function collectData() { + + $catBool = $this->getInput('catCheck'); + if($catBool) { + $catNum = $this->getInput('cat'); + } + $critList = $this->getInput('crit'); + + $keywordsList = explode(';', $this->getInput('q')); + foreach($keywordsList as $keywords) { + switch($critList) { + case 'search': + if($catBool == false) { + $html = file_get_contents( + 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 = file_get_contents( + self::URI . + 'files/?category=' . + rawurlencode($catNum) . + '&subcategory=All&quality=All&seeded=2&external=2&query=' . + urlencode($keywords) . #not rawurlencode so space -> '+' + '&uid=0&sort=' + ) or returnServerError('Could not request Demonoid.'); + } + break; + case 'usr': + $html = file_get_contents( + self::URI . + 'files/?uid=' . + rawurlencode($keywords) . + '&seeded=2' + ) or returnServerError('Could not request Demonoid.'); + break; + case 'cat': + $html = file_get_contents( + self::URI . + 'files/?uid=0&category=' . + rawurlencode($keywords) . + '&subcategory=0&language=0&seeded=2&quality=0&query=&sort=' + ) or returnServerError('Could not request Demonoid.'); + break; + } + + if(preg_match('~No torrents found~', $html)) { + returnServerError('No result for query ' . $keywords); + } + + $bigTable = explode('', $html)[1]; + $last50 = explode('', $bigTable)[0]; + $dateChunk = explode('added_today', $last50); + $item = array (); + + for($block = 1;$block < count($dateChunk);$block++) { + preg_match('~(?<=>Add).*?(?=<)~', $dateChunk[$block], $dateStr); + if(preg_match('~today~', $dateStr[0])) { + date_default_timezone_set('UTC'); + $timestamp = mktime(0, 0, 0, gmdate('n'), gmdate('j'), gmdate('Y')); + } else { + preg_match('~(?<=ed on ).*\d+~', $dateStr[0], $fullDateStr); + date_default_timezone_set('UTC'); + $dateObj = strptime($fullDateStr[0], '%A, %b %d, %Y'); + $timestamp = mktime(0, 0, 0, $dateObj['tm_mon'] + 1, $dateObj['tm_mday'], 1900 + $dateObj['tm_year']); + } + + $itemsChunk = explode('', $dateChunk[$block]); + + for($items = 1;$items < count($itemsChunk);$items++) { + $item = array(); + $cols = explode(').*?(?=)~', $cols[1], $matches); + $item['title'] = $matches[0]; + preg_match('~(?<=green\">)\d+(?=)~', $cols[8], $matches); + $item['seeders'] = $matches[0]; + preg_match('~(?<=red\">)\d+(?=)~', $cols[9], $matches); + $item['leechers'] = $matches[0]; + preg_match('~(?<=>).*?(?=)~', $cols[5], $matches); + $item['size'] = $matches[0]; + $item['content'] = 'Uploaded by ' . $item['author'] + . ' , Size ' . $item['size'] + . '
seeders: ' + . $item['seeders'] + . ' | leechers: ' + . $item['leechers'] + . '
info page'; + if(isset($item['title'])) + $this->items[] = $item; + } + } + } + } +}