[Solved] I coded a PHP class to talk to Transmission
-
- Posts: 10
- Joined: Wed Jun 30, 2010 10:56 pm
[Solved] I coded a PHP class to talk to Transmission
Hi all,
I was fed up with all other heavier torrent clients; the only reason I used them was because of the RSS features. I had a look at the Transmission API documentation and coded a PHP class that can manage your Transmission torrents. I am a PHP programmer and decided that I would write my own RSS feature with support for settings like target folder and ratio management.
It is a bare class with some tests and examples, but it is well documented and should be usefull for anyone with basic PHP knowledge.
http://code.google.com/p/php-transmissi ... loads/list
Let me know what you think, you can report any bugs or requests in the google code issues page.
Regards,
Johan
I was fed up with all other heavier torrent clients; the only reason I used them was because of the RSS features. I had a look at the Transmission API documentation and coded a PHP class that can manage your Transmission torrents. I am a PHP programmer and decided that I would write my own RSS feature with support for settings like target folder and ratio management.
It is a bare class with some tests and examples, but it is well documented and should be usefull for anyone with basic PHP knowledge.
http://code.google.com/p/php-transmissi ... loads/list
Let me know what you think, you can report any bugs or requests in the google code issues page.
Regards,
Johan
Re: I coded a PHP class to communicate with Transmission
nice. will be checking that out. thanks! 

Re: I coded a PHP class to communicate with Transmission
how exactly do you go about integrating this into an RSS torrent feed tho?
(ya stupid question... sorry)
(ya stupid question... sorry)
Re: I coded a PHP class to communicate with Transmission
webmastir,
Presuming you're writing a script from scratch (because this is a library, not a solution), you would implement an RSS parser however you saw fit, and could simply pass .torrent urls to $rpc->add($url);
Something like... (pseudo-code here)
Presuming you're writing a script from scratch (because this is a library, not a solution), you would implement an RSS parser however you saw fit, and could simply pass .torrent urls to $rpc->add($url);
Something like... (pseudo-code here)
Code: Select all
$rpc = new TransmissionRPC();
$array_of_torrents_extracted_from_rss = get_array_of_torrents_extracted_from_rss($rss_feed); //make this up
foreach($array_of_torrents_extracted_from_rss as $torrent) $rpc->add($torrent);
Re: I coded a PHP class to communicate with Transmission
awww..*headsmack*...i gotcha now. thanks & nice job 

Re: I coded a PHP class to communicate with Transmission
No problem webmastir, any time!
(P.S. You could work the $rpc->add() into the rss loop as well:)
Hope this helps!
Thanks!
(P.S. You could work the $rpc->add() into the rss loop as well:
Code: Select all
$rpc = new TransmissionRPC();
foreach($rss->items as $rss_item)
{
// do some rss feed item massage
// end up with the .torrent url in $torrent
$rpc->add($torrent);
// move on to the next item in the rss feed
}
Hope this helps!
Thanks!
-
- Posts: 7
- Joined: Wed Sep 21, 2011 9:34 am
Re: I coded a PHP class to communicate with Transmission
Hi...
Sorry but I'm not very good at php programing...
but I would be very happy if someone could help me...
I'm trying to get a page where my currently downloading torrents are shown and how much they have downloaded... and sort them with the newly added torrents first...
I have TransmissionRPC.class.php on my server and made a test.php
But I can only get the torrents to show if I have '$rpc->debug = true;'
And they are listed with the oldest torrents first...
Can someone please help me!
The reason I'm trying to get this is so that I can make a Rainmeter skin that shows currently downloading torrents
(I think there are some people looking after this)
http://rainmeter.net/forum/viewtopic.ph ... ansmission
This is what I currently have in test.php (taken from the test.php on google code
Sorry but I'm not very good at php programing...
but I would be very happy if someone could help me...
I'm trying to get a page where my currently downloading torrents are shown and how much they have downloaded... and sort them with the newly added torrents first...
I have TransmissionRPC.class.php on my server and made a test.php
But I can only get the torrents to show if I have '$rpc->debug = true;'
And they are listed with the oldest torrents first...
Can someone please help me!
The reason I'm trying to get this is so that I can make a Rainmeter skin that shows currently downloading torrents
(I think there are some people looking after this)
http://rainmeter.net/forum/viewtopic.ph ... ansmission
This is what I currently have in test.php (taken from the test.php on google code
Code: Select all
#!/usr/bin/php
<?php
require_once( dirname( __FILE__ ) . '/class/TransmissionRPC.class.php' );
$rpc = new TransmissionRPC();
$rpc->username = 'user';
$rpc->password = 'pass';
$rpc->debug = true;
try
{
$rpc->return_as_array = true;
$result = $rpc->get();
print "GET TORRENT INFO AS ARRAY TEST... [{$result['result']}]\n";
$rpc->return_as_array = false;
} catch (Exception $e) {
die('[ERROR] ' . $e->getMessage() . PHP_EOL);
}
?>
-
- Posts: 7
- Joined: Wed Sep 21, 2011 9:34 am
Re: I coded a PHP class to communicate with Transmission
ok.. I'll answer my own post 
Now I am able to show all torrents and the information I want...
But I would like to have It in reverse order... the latest added torrent first..
Is there anyone out there that would like to help me on this??
The web page created on my server...
With this code
(I have found a way to make a xml layout also, but I'll wait until I can make it in reverse order...)

Now I am able to show all torrents and the information I want...
But I would like to have It in reverse order... the latest added torrent first..
Is there anyone out there that would like to help me on this??

The web page created on my server...
Code: Select all
Array
(
[arguments] => Array
(
[torrents] => Array
(
[0] => Array
(
[addedDate] => 1308557303
[doneDate] => 1308557792
[id] => 1
[name] => Game.of.Thrones.S01E10.Fire.and.Blood.HDTV.XviD-FQM
[percentDone] => 1
[status] => 8
)
..... (don't want to print all the torrents I have)
[119] => Array
(
[addedDate] => 1316670729
[doneDate] => 1316672254
[id] => 158
[name] => Grand.Designs.S11E02.WS.PDTV.XviD-C4TV
[percentDone] => 1
[status] => 8
)
[120] => Array
(
[addedDate] => 1316670769
[doneDate] => 1316671495
[id] => 159
[name] => CSI.S12E01.HDTV.XviD-LOL
[percentDone] => 1
[status] => 8
)
[121] => Array
(
[addedDate] => 1316670926
[doneDate] => 1316671764
[id] => 160
[name] => Criminal.Minds.S07E01.HDTV.XviD-LOL
[percentDone] => 1
[status] => 8
)
)
)
[result] => success
)
Code: Select all
#!/usr/bin/php
<?php
if (!function_exists("preprint")) {
function preprint($s, $return=false) {
$x = "<pre>";
$x .= print_r($s, 1);
$x .= "</pre>";
if ($return) return $x;
else print $x;
}
}
require_once( dirname( __FILE__ ) . '/class/TransmissionRPC.class.php' );
$rpc = new TransmissionRPC();
$rpc->username = 'user';
$rpc->password = 'pass';
try
{
$rpc->return_as_array = true;
$result = $rpc->get();
preprint($result);
$rpc->return_as_array = false;
} catch (Exception $e) {
die('[ERROR] ' . $e->getMessage() . PHP_EOL);
}
?>
-
- Posts: 10
- Joined: Wed Jun 30, 2010 10:56 pm
Re: I coded a PHP class to communicate with Transmission
Hi mate,
Sorry for the late reply. Good to see you figured out your initial problem. To sort the results you can use a native PHP sort function. To reverse an array you could use: http://php.net/array_reverse
But if you would want more control over your sorting you should use a function like: http://php.net/usort
Hope that helps!
Sorry for the late reply. Good to see you figured out your initial problem. To sort the results you can use a native PHP sort function. To reverse an array you could use: http://php.net/array_reverse
But if you would want more control over your sorting you should use a function like: http://php.net/usort
Hope that helps!
-
- Posts: 7
- Joined: Wed Sep 21, 2011 9:34 am
Re: I coded a PHP class to communicate with Transmission
Hi!
Thanx for the response!
I've been looking at those functions... but my programming skills are very limited..
When I try to sort the array, the only things that get sorted are..
[arguments] => Array
[result] => success
I guess I have to go one level (or two) deeper in the array?
The optimal sorting of the array (for me) would be to sort it by [addedDate] in descending order..
But as I said, my skills are very limited!
Thanx again for your response and showing me in the right direction...!
Thanx for the response!

I've been looking at those functions... but my programming skills are very limited..
When I try to sort the array, the only things that get sorted are..
[arguments] => Array
[result] => success
Code: Select all
Array
(
[result] => success
[arguments] => Array
(
[torrents] => Array
(
[0] => Array
(
[addedDate] => 1308557303
...
The optimal sorting of the array (for me) would be to sort it by [addedDate] in descending order..
But as I said, my skills are very limited!
Thanx again for your response and showing me in the right direction...!
-
- Posts: 10
- Joined: Wed Jun 30, 2010 10:56 pm
Re: I coded a PHP class to communicate with Transmission
Indeed..
Your array is multidimensional. The part you want to sort is: $result['arguments']['torrents']
So a simple array_reverse( $result['arguments']['torrents'] ); Should reverse your torrents.
Your array is multidimensional. The part you want to sort is: $result['arguments']['torrents']
So a simple array_reverse( $result['arguments']['torrents'] ); Should reverse your torrents.

-
- Posts: 7
- Joined: Wed Sep 21, 2011 9:34 am
Re: I coded a PHP class to communicate with Transmission
Thanx so much!!!johan.adriaans wrote:Indeed..
Your array is multidimensional. The part you want to sort is: $result['arguments']['torrents']
So a simple array_reverse( $result['arguments']['torrents'] ); Should reverse your torrents.
You made my day!

Now I understand how it works...
And I've included xml function...
this is my code...
Code: Select all
#!/usr/bin/php
<?php
header('Content-Type: text/xml; charset=UTF-8');
require_once( dirname( __FILE__ ) . '/class/TransmissionRPC.class.php' );
function print_r_xml($arr,$first=true) {
$output = "";
if ($first) $output .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<data>\n";
foreach($arr as $key => $val) {
if (is_numeric($key)) $key = "arr_".$key; // <0 is not allowed
switch (gettype($val)) {
case "array":
$output .= "<".htmlspecialchars($key).">".
print_r_xml($val,false)."</".htmlspecialchars($key).">\n"; break;
case "boolean":
$output .= "<".htmlspecialchars($key).">".
"</".htmlspecialchars($key).">\n"; break;
case "integer":
$output .= "<".htmlspecialchars($key).">".
htmlspecialchars($val)."</".htmlspecialchars($key).">\n"; break;
case "double":
$output .= "<".htmlspecialchars($key).">".
htmlspecialchars($val)."</".htmlspecialchars($key).">\n"; break;
case "string":
$output .= "<".htmlspecialchars($key).">".
htmlspecialchars($val)."</".htmlspecialchars($key).">\n"; break;
default:
$output .= "<".htmlspecialchars($key).">".
"</".htmlspecialchars($key).">\n"; break;
}
}
if ($first) $output .= "</data>\n";
return $output;
}
$rpc = new TransmissionRPC();
$rpc->username = 'user';
$rpc->password = 'pass';
try
{
$rpc->return_as_array = true;
$result = $rpc->get();
$data = array_reverse( $result['arguments']['torrents'] );
echo print_r_xml($data);
$rpc->return_as_array = false;
} catch (Exception $e) {
die('[ERROR] ' . $e->getMessage() . PHP_EOL);
}
?>
Code: Select all
<data>
<arr_0>
<addedDate>1316670926</addedDate>
<doneDate>1316671764</doneDate>
<id>160</id>
<name>Criminal.Minds.S07E01.HDTV.XviD-LOL</name>
<percentDone>1</percentDone>
<status>8</status>
</arr_0>
<arr_1>
<addedDate>1316670769</addedDate>
<doneDate>1316671495</doneDate>
<id>159</id>
<name>CSI.S12E01.HDTV.XviD-LOL</name>
<percentDone>1</percentDone>
<status>8</status>
</arr_1>
.....
-
- Posts: 10
- Joined: Wed Jun 30, 2010 10:56 pm
Re: I coded a PHP class to communicate with Transmission
No problem! Good to hear you made some progress. In the future, if you want some more support on basic PHP stuff, you should try http://stackoverflow.com/, There's hundreds of people there who are willing to help you within a few minutes. Beats waiting a day for my replies 

-
- Posts: 7
- Joined: Wed Sep 21, 2011 9:34 am
Re: I coded a PHP class to communicate with Transmission
ok.. will do!johan.adriaans wrote:No problem! Good to hear you made some progress. In the future, if you want some more support on basic PHP stuff, you should try http://stackoverflow.com/, There's hundreds of people there who are willing to help you within a few minutes. Beats waiting a day for my replies

and thanx again!