2015-10-22 15:57:33 +03:00
|
|
|
<?php
|
|
|
|
class T411Bridge extends BridgeAbstract {
|
|
|
|
|
2015-12-18 00:31:12 +03:00
|
|
|
public function loadMetadatas() {
|
|
|
|
|
|
|
|
$this->maintainer = "ORelio";
|
|
|
|
$this->name = "T411";
|
|
|
|
$this->uri = "https://t411.in/";
|
|
|
|
$this->description = "Returns the 5 newest torrents with specified search terms <br /> Use url part after '?' mark when using their search engine";
|
|
|
|
$this->update = "2015-12-17";
|
|
|
|
|
|
|
|
$this->parameters[] =
|
|
|
|
'[
|
|
|
|
{
|
|
|
|
"name" : "Search criteria",
|
|
|
|
"identifier" : "search"
|
|
|
|
}
|
|
|
|
]';
|
|
|
|
}
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2015-10-22 15:57:33 +03:00
|
|
|
public function collectData(array $param) {
|
|
|
|
|
2015-12-18 00:31:12 +03: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 15:57:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//Ensure proper parameters have been provided
|
|
|
|
if (empty($param['search'])) {
|
|
|
|
$this->returnError('You must specify a search criteria', 400);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Retrieve torrent listing as truncated rss, which does not contain torrent description
|
2015-12-18 00:31:12 +03:00
|
|
|
$url = 'http://www.t411.in/torrents/search/?'.$param['search'].'&order=added&type=desc';
|
2015-10-22 15:57:33 +03:00
|
|
|
$html = file_get_html($url) or $this->returnError('Could not request t411: '.$url, 500);
|
2016-02-03 22:37:09 +03:00
|
|
|
$results = $html->find('table.results', 0);
|
|
|
|
if (is_null($results))
|
|
|
|
$this->returnError('No results from t411: '.$url, 500);
|
2015-10-22 15:57:33 +03:00
|
|
|
$limit = 0;
|
|
|
|
|
|
|
|
//Process each item individually
|
2015-12-18 00:31:12 +03:00
|
|
|
foreach($results->find('tr') as $element) {
|
2015-10-22 15:57:33 +03:00
|
|
|
|
|
|
|
//Limit total amount of requests
|
|
|
|
if ($limit < 5) {
|
|
|
|
|
|
|
|
//Requests are rate-limited
|
|
|
|
sleep(1); //So we need to wait
|
|
|
|
|
|
|
|
//Retrieve data from RSS entry
|
2015-12-18 00:31:12 +03:00
|
|
|
$item_uri = 'http://'.ExtractFromDelimiters($element->outertext, '<a href="//', '"');
|
|
|
|
$item_title = ExtractFromDelimiters($element->outertext, '" title="', '"');
|
|
|
|
$item_date = strtotime($element->find('dd', 0)->plaintext);
|
2015-10-22 15:57:33 +03:00
|
|
|
|
|
|
|
//Retrieve full description from torrent page
|
|
|
|
if ($item_html = file_get_html($item_uri)) {
|
|
|
|
|
|
|
|
//Retrieve data from page contents
|
|
|
|
$item_desc = $item_html->find('div.description', 0);
|
|
|
|
$item_author = $item_html->find('a.profile', 0)->innertext;
|
|
|
|
|
|
|
|
//Retrieve image for thumbnail or generic logo fallback
|
2015-10-22 16:01:16 +03:00
|
|
|
$item_image = 'http://www.t411.in/themes/blue/images/logo.png';
|
2015-10-22 15:57:33 +03:00
|
|
|
foreach ($item_desc->find('img') as $img) {
|
|
|
|
if (strpos($img->src, 'dreamprez') === false) {
|
|
|
|
$item_image = $img->src;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Build and add final item
|
|
|
|
$item = new \Item();
|
|
|
|
$item->uri = $item_uri;
|
|
|
|
$item->title = $item_title;
|
|
|
|
$item->author = $item_author;
|
|
|
|
$item->timestamp = $item_date;
|
|
|
|
$item->thumbnailUri = $item_image;
|
2016-02-03 22:37:09 +03:00
|
|
|
$item->content = $item_desc->innertext;
|
2015-10-22 15:57:33 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
$limit++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
return "T411 Bridge";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI() {
|
2015-10-22 16:01:16 +03:00
|
|
|
return 'https://t411.in';
|
2015-10-22 15:57:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration() {
|
2015-12-18 00:31:12 +03:00
|
|
|
return 3600; // 1 hour
|
2015-10-22 15:57:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|