1
0
Fork 0
forked from blallo/rss-bridge

Merge pull request #190 from ORelio/master

[T411] Use search instead of RSS
This commit is contained in:
Mitsu 2015-12-24 02:17:44 +01:00
commit 15021ebd78

View file

@ -1,40 +1,32 @@
<?php <?php
class T411Bridge extends BridgeAbstract { class T411Bridge extends BridgeAbstract {
public function loadMetadatas() { public function loadMetadatas() {
$this->maintainer = "ORelio"; $this->maintainer = "ORelio";
$this->name = "T411"; $this->name = "T411";
$this->uri = "https://t411.in/"; $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->description = "Returns the 5 newest torrents with specified search terms <br /> Use url part after '?' mark when using their search engine";
$this->update = "2015-10-22"; $this->update = "2015-12-17";
$this->parameters[] =
'[
{
"name" : "Search criteria",
"identifier" : "search"
}
]';
}
$this->parameters[] =
'[
{
"name" : "Search criteria",
"identifier" : "search"
}
]';
}
public function collectData(array $param) { public function collectData(array $param) {
//Utility function for extracting CDATA fields //Utility function for retrieving text based on start and end delimiters
function StripCDATA($string) { function ExtractFromDelimiters($string, $start, $end) {
$string = str_replace('<![CDATA[', '', $string); if (strpos($string, $start) !== false) {
$string = str_replace(']]>', '', $string); $section_retrieved = substr($string, strpos($string, $start) + strlen($start));
return $string; $section_retrieved = substr($section_retrieved, 0, strpos($section_retrieved, $end));
} return $section_retrieved;
} return false;
//Utility function for removing text based on specified delimiters
function StripWithDelimiters($string, $start, $end) {
while (strpos($string, $start) !== false) {
$section_to_remove = substr($string, strpos($string, $start));
$section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
$string = str_replace($section_to_remove, '', $string);
} return $string;
} }
//Ensure proper parameters have been provided //Ensure proper parameters have been provided
@ -43,12 +35,13 @@ class T411Bridge extends BridgeAbstract {
} }
//Retrieve torrent listing as truncated rss, which does not contain torrent description //Retrieve torrent listing as truncated rss, which does not contain torrent description
$url = 'http://www.t411.in/torrents/rss/?'.$param['search'].'&order=added&type=desc'; $url = 'http://www.t411.in/torrents/search/?'.$param['search'].'&order=added&type=desc';
$html = file_get_html($url) or $this->returnError('Could not request t411: '.$url, 500); $html = file_get_html($url) or $this->returnError('Could not request t411: '.$url, 500);
$results = $html->find('table.results')[0] or $this->returnError('No results from t411: '.$url, 500);
$limit = 0; $limit = 0;
//Process each item individually //Process each item individually
foreach($html->find('item') as $element) { foreach($results->find('tr') as $element) {
//Limit total amount of requests //Limit total amount of requests
if ($limit < 5) { if ($limit < 5) {
@ -57,9 +50,9 @@ class T411Bridge extends BridgeAbstract {
sleep(1); //So we need to wait sleep(1); //So we need to wait
//Retrieve data from RSS entry //Retrieve data from RSS entry
$item_uri = StripCDATA($element->find('guid', 0)->plaintext); $item_uri = 'http://'.ExtractFromDelimiters($element->outertext, '<a href="//', '"');
$item_title = StripWithDelimiters(StripCDATA($element->find('title', 0)->innertext), ' (S:', ')'); $item_title = ExtractFromDelimiters($element->outertext, '" title="', '"');
$item_date = strtotime($element->find('pubDate', 0)->plaintext); $item_date = strtotime($element->find('dd', 0)->plaintext);
//Retrieve full description from torrent page //Retrieve full description from torrent page
if ($item_html = file_get_html($item_uri)) { if ($item_html = file_get_html($item_uri)) {
@ -101,7 +94,7 @@ class T411Bridge extends BridgeAbstract {
} }
public function getCacheDuration() { public function getCacheDuration() {
return 3600*3; // 3 hours return 3600; // 1 hour
} }
} }