2015-10-22 14:57:33 +02:00
|
|
|
<?php
|
|
|
|
class T411Bridge extends BridgeAbstract {
|
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = 'ORelio';
|
|
|
|
const NAME = 'T411 Bridge';
|
|
|
|
const URI = 'https://t411.ch/';
|
|
|
|
const DESCRIPTION = 'Returns the 10 newest torrents with specified search terms <br /> Use url part after "?" mark when using their search engine.';
|
2015-12-17 22:31:12 +01:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const PARAMETERS = array( array(
|
2016-08-27 21:03:26 +02:00
|
|
|
'search'=>array(
|
2016-08-22 01:25:56 +02:00
|
|
|
'name'=>'Search criteria',
|
|
|
|
'required'=>true
|
2016-08-27 21:03:26 +02:00
|
|
|
)
|
|
|
|
));
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2015-10-22 14:57:33 +02:00
|
|
|
|
2015-12-17 22:31:12 +01:00
|
|
|
//Utility function for retrieving text based on start and end delimiters
|
|
|
|
function ExtractFromDelimiters($string, $start, $end) {
|
|
|
|
if (strpos($string, $start) !== false) {
|
|
|
|
$section_retrieved = substr($string, strpos($string, $start) + strlen($start));
|
|
|
|
$section_retrieved = substr($section_retrieved, 0, strpos($section_retrieved, $end));
|
|
|
|
return $section_retrieved;
|
|
|
|
} return false;
|
2015-10-22 14:57:33 +02:00
|
|
|
}
|
|
|
|
|
2016-02-27 12:56:36 +01:00
|
|
|
//Retrieve torrent listing from search results, which does not contain torrent description
|
2016-08-30 11:23:55 +02:00
|
|
|
$url = self::URI.'torrents/search/?'.$this->getInput('search').'&order=added&type=desc';
|
2016-09-25 23:22:33 +02:00
|
|
|
$html = getSimpleHTMLDOM($url)
|
|
|
|
or returnServerError('Could not request t411: '.$url);
|
2016-08-29 23:19:59 +02:00
|
|
|
|
2016-02-03 20:37:09 +01:00
|
|
|
$results = $html->find('table.results', 0);
|
|
|
|
if (is_null($results))
|
2016-09-25 23:22:33 +02:00
|
|
|
returnServerError('No results from t411: '.$url);
|
2015-10-22 14:57:33 +02:00
|
|
|
$limit = 0;
|
|
|
|
|
|
|
|
//Process each item individually
|
2016-07-17 14:39:14 +02:00
|
|
|
foreach ($results->find('tr') as $element) {
|
2015-10-22 14:57:33 +02:00
|
|
|
|
2016-07-17 14:39:14 +02:00
|
|
|
//Limit total amount of requests and ignore table header
|
2016-08-29 23:19:59 +02:00
|
|
|
if ($limit >= 10){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(is_object($element->find('th', 0))){
|
|
|
|
continue;
|
|
|
|
}
|
2015-10-22 14:57:33 +02:00
|
|
|
|
2016-08-29 23:19:59 +02:00
|
|
|
//Requests are rate-limited
|
|
|
|
usleep(500000); //So we need to wait (500ms)
|
2015-10-22 14:57:33 +02:00
|
|
|
|
2016-08-29 23:19:59 +02:00
|
|
|
//Retrieve data from RSS entry
|
2016-08-30 11:23:55 +02:00
|
|
|
$item_uri = self::URI.'torrents/details/?id='.ExtractFromDelimiters($element->find('a.nfo', 0)->outertext, '?id=', '"');
|
2016-08-29 23:19:59 +02:00
|
|
|
$item_title = ExtractFromDelimiters($element->outertext, '" title="', '"');
|
|
|
|
$item_date = strtotime($element->find('dd', 0)->plaintext);
|
2015-10-22 14:57:33 +02:00
|
|
|
|
2016-08-29 23:19:59 +02:00
|
|
|
//Retrieve full description from torrent page
|
2016-09-25 23:22:33 +02:00
|
|
|
$item_html = getSimpleHTMLDOM($item_uri);
|
2016-08-29 23:19:59 +02:00
|
|
|
if (!$item_html) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-10-22 14:57:33 +02:00
|
|
|
|
2016-08-29 23:19:59 +02:00
|
|
|
//Retrieve data from page contents
|
|
|
|
$item_desc = $item_html->find('div.description', 0);
|
|
|
|
$item_author = $item_html->find('a.profile', 0)->innertext;
|
2015-10-22 14:57:33 +02:00
|
|
|
|
2016-08-29 23:19:59 +02:00
|
|
|
//Cleanup advertisments
|
|
|
|
$divs = explode('<div class="align-center">', $item_desc->innertext);
|
|
|
|
$item_desc = '';
|
|
|
|
foreach ($divs as $text)
|
|
|
|
if (strpos($text, 'adprovider.adlure.net') === false)
|
|
|
|
$item_desc = $item_desc.'<div class="align-center">'.$text;
|
|
|
|
$item_desc = preg_replace('/<h2 class="align-center">LIENS DE T..?L..?CHARGEMENT<\/h2>/i', '', $item_desc);
|
2016-07-17 14:39:14 +02:00
|
|
|
|
2016-08-29 23:19:59 +02:00
|
|
|
//Build and add final item
|
|
|
|
$item = array();
|
|
|
|
$item['uri'] = $item_uri;
|
|
|
|
$item['title'] = $item_title;
|
|
|
|
$item['author'] = $item_author;
|
|
|
|
$item['timestamp'] = $item_date;
|
|
|
|
$item['content'] = $item_desc;
|
|
|
|
$this->items[] = $item;
|
|
|
|
$limit++;
|
2015-10-22 14:57:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|