Ok Played an awfull lot with the code and came up with a solution
Code:
function getTorrentsInfo()
{
$req = new rXMLRPCRequest(
new rXMLRPCCommand( "d.multicall", array( "", "d.get_hash=", "d.get_custom1=", "d.get_name=", "d.get_up_total=", "d.get_down_total=", "d.get_size_bytes=", "d.get_custom=addtime", "d.get_ratio=" )));
if($req->success())
{
$ret = array();
for($i=0; $i<count($req->val); $i+=8)
{
$ret[] = array( "hash"=>$req->val[$i],
"label"=>$req->val[$i+1],
"name"=>$req->val[$i+2],
"UL"=>$req->val[$i+3], this in bytes size use a function to convert it to a more readable format eg mb/gb
"DL"=>$req->val[$i+4], this in bytes size use a function to convert it to a more readable format eg
"size" => floatval($req->val[$i+5]), this in bytes size use a function to convert it to a more readable format
"addtime"=>$req->val[$i+6], // needs to be coverted to date time format to get readable added time date
"ratio"=> intval($req->val[$i+7]), // array has to be divided by 1000 to get correct ratio
"tracker"=>tracker($req->val[$i]));
}
return($ret);
}
return(false);
}
Function needed for the tracker
(I did not write this function just used some code from an addon and changed it slightly)
Code:
function tracker($key)
{
$trackers = array();
$req = new rXMLRPCRequest( array(
new rXMLRPCCommand("t.multicall",
array($key,"","t.is_enabled=","t.get_type=","t.get_group=","t.get_url="))));
$req->setParseByTypes();
if($req->run() && !$req->fault)
{
$lastGroup = 65535;
for($i = 0; $i<count($req->strings); $i++)
{
if($req->i8s[$i*3+2]>$lastGroup)
break;
if(($req->i8s[$i*3]!=0) && ($req->i8s[$i*3+1]<3))
{
$lastGroup = $req->i8s[$i*3+2];
$domain = parse_url($req->strings[$i],PHP_URL_HOST);
if(preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$domain)!=1)
{
$pos = strpos($domain,'.');
if($pos!==false)
{
$tmp = substr($domain,$pos+1);
if(strpos($tmp,'.')!==false)
$domain = $tmp;
}
}
if(array_key_exists($domain,$trackers))
{
$trackers[$domain][0]+=$needTorrents[$key][0];
$trackers[$domain][1]+=$needTorrents[$key][1];
}
else
$trackers[$domain] = $needTorrents[$key];
}
}
}
return $domain;
}
Now when you call
Code:
[Select]
$result=getTorrentsInfo();
Your given all your torrents each one in it own array($result) with hash,label,name,UL(uploaded),DL(downloaded),size,ratio,addtime and tracker
To view this information nicely on screen add this function
Code:
function print_r2($val){
echo '<pre>';
print_r($val);
echo '</pre>';
}
then
Code:
print_r2($result);
Now that you have all your torrent information in a nice easy array you can do with it as you please
I'm Filtering the array to just have a list of torrents with a certain label by adding this function
Code:
function filter_by_value ($array, $index, $value){
if(is_array($array) && count($array)>0)
{
foreach(array_keys($array) as $key){
$temp[$key] = $array[$key][$index];
if ($temp[$key] == $value){
$newarray[$key] = $array[$key];
}
}
}
return $newarray;
}
And then calling the function with
Code:
$filter="movies"; // this could be anything you want from how you have your labels set up on your site
$nResults = filter_by_value($result, 'label', $filter);
Now I found the array was not numbered corectly so to fix that issue
Code:
$n2Results = array_merge($nResults);
To print out the new sorted array
Code:
print_r2($n2Results);
From here I have created a databse and added all the information into it, I have the database check every 5 mins and either insert or upadte the data. I can/have used that database information to create lots of other pages