forked from blallo/rss-bridge
[IsoHuntBridge] code simplification
Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
parent
b5c432d66c
commit
f13f44a682
1 changed files with 442 additions and 454 deletions
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
class IsoHuntBridge extends BridgeAbstract{
|
||||
public $maintainer = 'logmanoriginal';
|
||||
public $name = 'isoHunt Bridge'; // Is replaced later!
|
||||
public $uri = 'https://isohunt.to'; // Is replaced later!
|
||||
public $name = 'isoHunt Bridge';
|
||||
public $uri = 'https://isohunt.to/';
|
||||
public $description = 'Returns the latest results by category or search result';
|
||||
|
||||
public $parameters = array(
|
||||
|
@ -17,7 +17,7 @@ class IsoHuntBridge extends BridgeAbstract{
|
|||
'type'=>'list',
|
||||
'required'=>true,
|
||||
'title'=>'Select your category',
|
||||
'defaultValue'=>'News',
|
||||
'defaultValue'=>'news',
|
||||
'values'=>array(
|
||||
'Hot Torrents'=>'hot_torrents',
|
||||
'News'=>'news',
|
||||
|
@ -38,7 +38,7 @@ class IsoHuntBridge extends BridgeAbstract{
|
|||
'type'=>'list',
|
||||
'required'=>true,
|
||||
'title'=>'Select your category',
|
||||
'defaultValue'=>'Anime',
|
||||
'defaultValue'=>'anime',
|
||||
'values'=>array(
|
||||
'Adult'=>'adult',
|
||||
'Anime'=>'anime',
|
||||
|
@ -72,7 +72,7 @@ class IsoHuntBridge extends BridgeAbstract{
|
|||
'name'=>'Category',
|
||||
'type'=>'list',
|
||||
'title'=>'Select your category',
|
||||
'defaultValue'=>'All',
|
||||
'defaultValue'=>'all',
|
||||
'values'=>array(
|
||||
'Adult'=>'adult',
|
||||
'All'=>'all',
|
||||
|
@ -89,25 +89,113 @@ class IsoHuntBridge extends BridgeAbstract{
|
|||
)
|
||||
);
|
||||
|
||||
public function getURI(){
|
||||
$uri=$this->uri;
|
||||
switch($this->queriedContext){
|
||||
case 'By "Latest" category':
|
||||
switch($this->getInput('latest_category')){
|
||||
case 'hot_torrents':
|
||||
$uri .= 'statistic/hot/torrents';
|
||||
break;
|
||||
case 'news':
|
||||
break;
|
||||
case 'releases':
|
||||
$uri .= 'releases.php';
|
||||
break;
|
||||
case 'torrents':
|
||||
$uri .= 'latest.php';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'By "Torrent" category':
|
||||
$uri .= $this->build_category_uri(
|
||||
$this->getInput('torrent_category'),
|
||||
$this->getInput('torrent_popularity')
|
||||
);
|
||||
break;
|
||||
|
||||
case 'Search torrent by name':
|
||||
$category=$this->getInput('search_category');
|
||||
$uri .= $this->build_category_uri($category);
|
||||
if($category!=='movies')
|
||||
$uri .= '&ihq=' . urlencode($this->getInput('search_name'));
|
||||
break;
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
switch($this->queriedContext){
|
||||
case 'By "Latest" category':
|
||||
$categoryName =
|
||||
array_search(
|
||||
$this->getInput('latest_category'),
|
||||
$this->parameters['By "Latest" category']['latest_category']['values']
|
||||
);
|
||||
$name = 'Latest '.$categoryName.' - ' . $this->name;
|
||||
break;
|
||||
|
||||
case 'By "Torrent" category':
|
||||
$categoryName =
|
||||
array_search(
|
||||
$this->getInput('torrent_category'),
|
||||
$this->parameters['By "Torrent" category']['torrent_category']['values']
|
||||
);
|
||||
$name = 'Category: ' . $categoryName . ' - ' . $this->name;
|
||||
break;
|
||||
|
||||
case 'Search torrent by name':
|
||||
$categoryName =
|
||||
array_search(
|
||||
$this->getInput('search_category'),
|
||||
$this->parameters['Search torrent by name']['search_category']['values']
|
||||
);
|
||||
$name = 'Search: "' . $this->getInput('search_name') . '" in category: ' . $categoryName . ' - ' . $this->name;
|
||||
break;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
|
||||
public function collectData(){
|
||||
$request_path = '/'; // We'll request the main page by default
|
||||
$html = $this->load_html($this->getURI());
|
||||
|
||||
if($this->getInput('latest_category')){ // Requesting one of the latest categories
|
||||
$this->request_latest_category($this->getInput('latest_category'));
|
||||
} elseif($this->getInput('torrent_category')){ // Requesting one of the torrent categories
|
||||
$order_popularity = false;
|
||||
switch($this->queriedContext){
|
||||
case 'By "Latest" category':
|
||||
switch($this->getInput('latest_category')){
|
||||
case 'hot_torrents':
|
||||
$this->get_latest_hot_torrents($html);
|
||||
break;
|
||||
case 'news':
|
||||
$this->get_latest_news($html);
|
||||
break;
|
||||
case 'releases':
|
||||
case 'torrents':
|
||||
$this->get_latest_torrents($html);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
if($this->getInput('torrent_popularity'))
|
||||
$order_popularity = $this->getInput('torrent_popularity');
|
||||
|
||||
$this->request_torrent_category($this->getInput('torrent_category'), $order_popularity);
|
||||
} else if($this->getInput('search_name')){ // Requesting search
|
||||
if($this->getInput('search_category'))
|
||||
$this->request_search($this->getInput('search_name'), $this->getInput('search_category'));
|
||||
else
|
||||
$this->request_search($this->getInput('search_name'));
|
||||
case 'By "Torrent" category':
|
||||
if($this->getInput('torrent_category') === 'movies'){
|
||||
// This one is special (content wise)
|
||||
$this->get_movie_torrents($html);
|
||||
}else{
|
||||
$this->returnClientError('Unknown request!');
|
||||
$this->get_latest_torrents($html);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Search torrent by name':
|
||||
if( $this->getInput('search_category') === 'movies'){
|
||||
// This one is special (content wise)
|
||||
$this->get_movie_torrents($html);
|
||||
} else {
|
||||
$this->get_latest_torrents($html);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,120 +203,6 @@ class IsoHuntBridge extends BridgeAbstract{
|
|||
return 300; // 5 minutes
|
||||
}
|
||||
|
||||
#region Helper functions for "By "Torrent" category"
|
||||
|
||||
private function request_torrent_category($category, $order_popularity){
|
||||
$category_name = $this->get_torrent_category_name($category);
|
||||
$category_index = $this->get_torrent_category_index($category);
|
||||
|
||||
$this->name = 'Category: ' . $category_name . ' - ' . $this->name;
|
||||
$this->uri .= $this->build_category_uri($category_index, $order_popularity);
|
||||
|
||||
$html = $this->load_html($this->uri);
|
||||
|
||||
if(strtolower(trim($category)) === 'movies') // This one is special (content wise)
|
||||
$this->get_movie_torrents($html);
|
||||
else
|
||||
$this->get_latest_torrents($html);
|
||||
}
|
||||
|
||||
private function get_torrent_category_name($category){
|
||||
$parameter = $this->parameters['By "Torrent" category'];
|
||||
$languages = $parameter['torrent_category']['values'];
|
||||
|
||||
foreach($languages as $name=>$value)
|
||||
if(strtolower(trim($value)) === strtolower(trim($category)))
|
||||
return $name;
|
||||
|
||||
return 'Unknown category';
|
||||
}
|
||||
|
||||
private function get_torrent_category_index($category){
|
||||
switch(strtolower(trim($category))){
|
||||
case 'anime': return 1;
|
||||
case 'software' : return 2;
|
||||
case 'games' : return 3;
|
||||
case 'adult' : return 4;
|
||||
case 'movies' : return 5;
|
||||
case 'music' : return 6;
|
||||
case 'other' : return 7;
|
||||
case 'series_tv' : return 8;
|
||||
case 'books': return 9;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private function request_latest_category($category){
|
||||
switch($category){
|
||||
case 'hot_torrents': // This is a special case! (that's why return)
|
||||
$this->name = 'Latest hot torrents - ' . $this->name;
|
||||
$this->uri .= '/statistic/hot/torrents';
|
||||
$html = $this->load_html($this->uri);
|
||||
$this->get_latest_hot_torrents($html);
|
||||
return;
|
||||
case 'news': // This is a special case! (that's why return)
|
||||
$this->name = 'Latest news - ' . $this->name;
|
||||
$this->uri .= '/';
|
||||
$html = $this->load_html($this->uri);
|
||||
$this->get_latest_news($html);
|
||||
return;
|
||||
case 'releases':
|
||||
$this->name = 'Latest releases - ' . $this->name;
|
||||
$this->uri .= '/releases.php';
|
||||
break;
|
||||
case 'torrents':
|
||||
$this->name = 'Latest torrents - ' . $this->name;
|
||||
$this->uri .= '/latest.php';
|
||||
break;
|
||||
default: // No category applies
|
||||
$this->returnClientError('Undefined category: ' . $category . '!');
|
||||
}
|
||||
|
||||
$html = $this->load_html($this->uri);
|
||||
$this->get_latest_torrents($html);
|
||||
}
|
||||
|
||||
#region Helper functions for "Search torrent by name"
|
||||
|
||||
private function request_search($name, $category = 'all'){
|
||||
$category_name = $this->get_search_category_name($category);
|
||||
$category_index = $this->get_search_category_index($category);
|
||||
|
||||
$this->name = 'Search: "' . $name . '" in category: ' . $category_name . ' - ' . $this->name;
|
||||
$this->uri .= $this->build_category_uri($category_index);
|
||||
|
||||
if(strtolower(trim($category)) === 'movies'){ // This one is special (content wise)
|
||||
$html = $this->load_html($this->uri);
|
||||
$this->get_movie_torrents($html);
|
||||
} else {
|
||||
$this->uri .= '&ihq=' . urlencode($name);
|
||||
$html = $this->load_html($this->uri);
|
||||
$this->get_latest_torrents($html);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_search_category_name($category){
|
||||
$parameter = $this->parameters['Search torrent by name'];
|
||||
$languages = $parameter['search_category']['values'];
|
||||
|
||||
foreach($languages as $name=>$value)
|
||||
if(strtolower(trim($value)) === strtolower(trim($category)))
|
||||
return $name;
|
||||
|
||||
return 'Unknown category';
|
||||
}
|
||||
|
||||
private function get_search_category_index($category){
|
||||
switch(strtolower(trim($category))){
|
||||
case 'all': return 0;
|
||||
default: return $this->get_torrent_category_index($category); // Uses the same index
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helper functions for "Movie Torrents"
|
||||
|
||||
private function get_movie_torrents($html){
|
||||
|
@ -472,11 +446,25 @@ class IsoHuntBridge extends BridgeAbstract{
|
|||
}
|
||||
|
||||
private function fix_relative_uri($uri){
|
||||
return preg_replace('/\//i', 'https://isohunt.to/', $uri, 1);
|
||||
return preg_replace('/\//i', $this->uri, $uri, 1);
|
||||
}
|
||||
|
||||
private function build_category_uri($index, $order_popularity = false){
|
||||
return '/torrents/?iht=' . $index . '&ihs=' . ($order_popularity ? 1 : 0) . '&age=0';
|
||||
private function build_category_uri($category, $order_popularity = false){
|
||||
switch($category){
|
||||
case 'anime': $index = 1; break;
|
||||
case 'software' : $index = 2; break;
|
||||
case 'games' : $index = 3; break;
|
||||
case 'adult' : $index = 4; break;
|
||||
case 'movies' : $index = 5; break;
|
||||
case 'music' : $index = 6; break;
|
||||
case 'other' : $index = 7; break;
|
||||
case 'series_tv' : $index = 8; break;
|
||||
case 'books': $index = 9; break;
|
||||
case 'all':
|
||||
default: $index = 0; break;
|
||||
}
|
||||
|
||||
return 'torrents/?iht=' . $index . '&ihs=' . ($order_popularity ? 1 : 0) . '&age=0';
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
Loading…
Reference in a new issue