From eae88cf2cfd04710f154331750b2fd5f557309c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Mon, 29 Aug 2016 23:19:59 +0200 Subject: [PATCH] [T411Bridge] code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/T411Bridge.php | 85 ++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/bridges/T411Bridge.php b/bridges/T411Bridge.php index 793ea27..6bc2b80 100644 --- a/bridges/T411Bridge.php +++ b/bridges/T411Bridge.php @@ -24,14 +24,11 @@ class T411Bridge extends BridgeAbstract { } return false; } - //Ensure proper parameters have been provided - if (empty($this->getInput('search'))) { - $this->returnClientError('You must specify a search criteria'); - } - //Retrieve torrent listing from search results, which does not contain torrent description $url = $this->uri.'torrents/search/?'.$this->getInput('search').'&order=added&type=desc'; - $html = $this->getSimpleHTMLDOM($url) or $this->returnServerError('Could not request t411: '.$url); + $html = $this->getSimpleHTMLDOM($url) + or $this->returnServerError('Could not request t411: '.$url); + $results = $html->find('table.results', 0); if (is_null($results)) $this->returnServerError('No results from t411: '.$url); @@ -41,42 +38,48 @@ class T411Bridge extends BridgeAbstract { foreach ($results->find('tr') as $element) { //Limit total amount of requests and ignore table header - if ($limit < 10 && !is_object($element->find('th', 0))) { - - //Requests are rate-limited - usleep(500000); //So we need to wait (500ms) - - //Retrieve data from RSS entry - $item_uri = $this->uri.'torrents/details/?id='.ExtractFromDelimiters($element->find('a.nfo', 0)->outertext, '?id=', '"'); - $item_title = ExtractFromDelimiters($element->outertext, '" title="', '"'); - $item_date = strtotime($element->find('dd', 0)->plaintext); - - //Retrieve full description from torrent page - if ($item_html = $this->getSimpleHTMLDOM($item_uri)) { - - //Retrieve data from page contents - $item_desc = $item_html->find('div.description', 0); - $item_author = $item_html->find('a.profile', 0)->innertext; - - //Cleanup advertisments - $divs = explode('
', $item_desc->innertext); - $item_desc = ''; - foreach ($divs as $text) - if (strpos($text, 'adprovider.adlure.net') === false) - $item_desc = $item_desc.'
'.$text; - $item_desc = preg_replace('/

LIENS DE T..?L..?CHARGEMENT<\/h2>/i', '', $item_desc); - - //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++; - } + if ($limit >= 10){ + break; } + if(is_object($element->find('th', 0))){ + continue; + } + + //Requests are rate-limited + usleep(500000); //So we need to wait (500ms) + + //Retrieve data from RSS entry + $item_uri = $this->uri.'torrents/details/?id='.ExtractFromDelimiters($element->find('a.nfo', 0)->outertext, '?id=', '"'); + $item_title = ExtractFromDelimiters($element->outertext, '" title="', '"'); + $item_date = strtotime($element->find('dd', 0)->plaintext); + + //Retrieve full description from torrent page + $item_html = $this->getSimpleHTMLDOM($item_uri); + if (!$item_html) { + continue; + } + + //Retrieve data from page contents + $item_desc = $item_html->find('div.description', 0); + $item_author = $item_html->find('a.profile', 0)->innertext; + + //Cleanup advertisments + $divs = explode('
', $item_desc->innertext); + $item_desc = ''; + foreach ($divs as $text) + if (strpos($text, 'adprovider.adlure.net') === false) + $item_desc = $item_desc.'
'.$text; + $item_desc = preg_replace('/

LIENS DE T..?L..?CHARGEMENT<\/h2>/i', '', $item_desc); + + //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++; } } }