[T411Bridge] code simplification
Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
parent
1f72a34b42
commit
eae88cf2cf
1 changed files with 44 additions and 41 deletions
|
@ -24,14 +24,11 @@ class T411Bridge extends BridgeAbstract {
|
||||||
} return false;
|
} 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
|
//Retrieve torrent listing from search results, which does not contain torrent description
|
||||||
$url = $this->uri.'torrents/search/?'.$this->getInput('search').'&order=added&type=desc';
|
$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);
|
$results = $html->find('table.results', 0);
|
||||||
if (is_null($results))
|
if (is_null($results))
|
||||||
$this->returnServerError('No results from t411: '.$url);
|
$this->returnServerError('No results from t411: '.$url);
|
||||||
|
@ -41,7 +38,12 @@ class T411Bridge extends BridgeAbstract {
|
||||||
foreach ($results->find('tr') as $element) {
|
foreach ($results->find('tr') as $element) {
|
||||||
|
|
||||||
//Limit total amount of requests and ignore table header
|
//Limit total amount of requests and ignore table header
|
||||||
if ($limit < 10 && !is_object($element->find('th', 0))) {
|
if ($limit >= 10){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(is_object($element->find('th', 0))){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
//Requests are rate-limited
|
//Requests are rate-limited
|
||||||
usleep(500000); //So we need to wait (500ms)
|
usleep(500000); //So we need to wait (500ms)
|
||||||
|
@ -52,7 +54,10 @@ class T411Bridge extends BridgeAbstract {
|
||||||
$item_date = strtotime($element->find('dd', 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 = $this->getSimpleHTMLDOM($item_uri)) {
|
$item_html = $this->getSimpleHTMLDOM($item_uri);
|
||||||
|
if (!$item_html) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
//Retrieve data from page contents
|
//Retrieve data from page contents
|
||||||
$item_desc = $item_html->find('div.description', 0);
|
$item_desc = $item_html->find('div.description', 0);
|
||||||
|
@ -77,7 +82,5 @@ class T411Bridge extends BridgeAbstract {
|
||||||
$limit++;
|
$limit++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue