IPTorrents extsearch Broken

jith45

Member
May 25, 2018
960
0
16
Here is my version that currently works. I also updated the query string and category numbers and fixed a bug with wrong results being returned if there were a mix of results that included and did include a "|" in the age section.

Code:
<?php

class IPTorrentsEngine extends commonEngine
{
public $defaults = array( "public"=>false, "page_size"=>35, "cookies"=>"www.iptorrents.com|pass=XXX;uid=XXX" );
public $categories = array( 'all'=>'l72;l73;l74;l75;l76;',
'Movies'=>'l72;', 'TV'=>'l73;', 'Games'=>'l74;', 'Music'=>'l75;', 'Books'=>'l35;', 'Anime'=>'l60;',
'Appz/misc'=>'l1;', 'Mac'=>'l69;', 'Mobile'=>'l58;', 'Pics/Wallpapers'=>'l36;', 'Sports'=>'l55;', 'XXX'=>'l88;' );

protected static $seconds = array
(
'minutes' =>60,
'hours' =>3600,
'days' =>86400,
'weeks' =>604800,
'months' =>2592000,
'years' =>31536000,
);

protected static function getTime( $now, $ago, $unit )
{
$delta = (array_key_exists($unit,self::$seconds) ? self::$seconds[$unit] : 0);
return( $now-$delta );
}

public function action($what,$cat,&$ret,$limit,$useGlobalCats)
{
$added = 0;
$url = 'http://www.iptorrents.com';
if($useGlobalCats)
$categories = array( 'all'=>'l72;l73;l74;l75;l76;',
'movies'=>'l72;', 'tv'=>'l73;', 'music'=>'l75;', 'games'=>'l74;',
'anime'=>'l60;', 'software'=>'l1;', 'pictures'=>'l36;', 'books'=>'l35;l64;' );
else
$categories = &$this->categories;
if(!array_key_exists($cat,$categories))
$cat = $categories['all'];
else
$cat = $categories[$cat];
for($pg = 1; $pg<11; $pg++)
{
$cli = $this->fetch( $url.'/t?'.$cat.'q='.$what.';p='.$pg.'#torrents' );
if( ($cli==false) || (strpos($cli->results, ">Nothing found!<")!==false) ||
(strpos($cli->results, ">Password:<")!==false))
break;

$res = preg_match_all('`<img class=".*" width="90" height="50" src=.* alt="(?P<cat>.*)"></a>.*'.
' href="/details\.php\?id=(?P<id>\d+)">(?P<name>.*)</a>.*'.
't_ctime">(?:.* \| )?(?P<ago>[0-9\.]+) (?P<unit>(minutes|hours|days|weeks|months|years)) ago(?: by .*)?</div>.*'.
'<td .*>.*href="/download\.php/\d+\/(?P<tname>.*)".*</a></td>'.
'<td .*>.*</td><td .*>(?P<size>.*)</td><td .*>.*</td>'.
'<td .*>(?P<seeds>.*)</td>'.
'<td .*>(?P<leech>.*)</td>'.
'`siU', $cli->results, $matches);

if($res)
{
$now = time();
for($i=0; $i<$res; $i++)
{
$link = $url."/download.php/".$matches["id"][$i]."/".$matches["tname"][$i];
if(!array_key_exists($link,$ret))
{
$item = $this->getNewEntry();
$item["cat"] = self::removeTags($matches["cat"][$i]);
$item["desc"] = $url."/details.php?id=".$matches["id"][$i];
$item["name"] = self::removeTags($matches["name"][$i]);
$item["size"] = self::formatSize($matches["size"][$i]);
$item["time"] = self::getTime( $now, $matches["ago"][$i], $matches["unit"][$i] );
$item["seeds"] = intval(self::removeTags($matches["seeds"][$i]));
$item["peers"] = intval(self::removeTags($matches["leech"][$i]));
$ret[$link] = $item;
$added++;
if($added>=$limit)
return;
}
}
}
else
break;
}
}
}