From f79d699a59b0432c5fb9746541a9fec839deaa4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Mon, 29 Aug 2016 23:28:16 +0200 Subject: [PATCH] [ThePirateBayBridge] code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/ThePirateBayBridge.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bridges/ThePirateBayBridge.php b/bridges/ThePirateBayBridge.php index d4e1cd6..8fddc83 100644 --- a/bridges/ThePirateBayBridge.php +++ b/bridges/ThePirateBayBridge.php @@ -9,7 +9,8 @@ class ThePirateBayBridge extends BridgeAbstract{ public $parameters = array( array( 'q'=>array( 'name'=>'keywords, separated by semicolons', - 'exampleValue'=>'first list;second list;…' + 'exampleValue'=>'first list;second list;…', + 'required'=>true ) )); @@ -49,12 +50,10 @@ class ThePirateBayBridge extends BridgeAbstract{ } - if (!$this->getInput('q')) - $this->returnClientError('You must specify keywords (?q=...)'); - $keywordsList = explode(";",$this->getInput('q')); foreach($keywordsList as $keywords){ - $html = $this->getSimpleHTMLDOM('https://thepiratebay.org/search/'.rawurlencode($keywords).'/0/3/0') or $this->returnServerError('Could not request TPB.'); + $html = $this->getSimpleHTMLDOM($this->uri.'search/'.rawurlencode($keywords).'/0/3/0') + or $this->returnServerError('Could not request TPB.'); if ($html->find('table#searchResult', 0) == FALSE) $this->returnServerError('No result for query '.$keywords); @@ -62,7 +61,7 @@ class ThePirateBayBridge extends BridgeAbstract{ foreach($html->find('tr') as $element) { $item = array(); - $item['uri'] = 'https://thepiratebay.org/'.$element->find('a.detLink',0)->href; + $item['uri'] = $this->uri.$element->find('a.detLink',0)->href; $item['id'] = $item['uri']; $item['timestamp'] = parseDateTimestamp($element); $item['title'] = $element->find('a.detLink',0)->plaintext;