Calling a php script under certain conditions

simur612

Member
May 25, 2018
879
0
16
I have successfully set up my debian server running rtorrent and rutorrent. I also managed to set up the RSS Plugin thanks to this thread. It automatically downloads all series episodes from the given feed adding the label "series".
What I didn't manage to configure is the behavior after download completion:
  • First: Move all downloads to a different directory
  • Then: If the download is labeled "series", a php script should be called with the download's filename and path as parameter, e.g.:
Code:
php -f /var/www/myscript.php -- /media/raid/incoming/New.Episode.S04E17.mkv

I figured that that has to be done in .rtorrent.rc. But since I never really understood the syntax used there, I just got the first part working:
Code:
system.method.set_key = event.download.finished,move_complete_1,"execute=mv,-u,$d.get_base_path=,/media/raid/incoming/;d.set_directory=/media/raid/incoming/"
For the second part I tried out many variations of this:
Code:
system.method.set_key = event.download.finished,move_complete_2,"branch=\"equal={d.get_custom1=,series},execute={php,-f,/var/www/myscript.php,--,$d.get_base_path=}\""
But nothing seemed to work; even leaving out the conditional haven't had any effect:
Code:
system.method.set_key = event.download.finished,move_complete_2,"execute=php,-f,/var/www/myscript.php,--,$d.get_base_path=\""
I get the strong feeling I miss something important on the syntax here, but I cannot figure it out.
Can anybody point me in the right direction? An api reference would be great, though I couldn't find anything on google that would help.
Why isn't this working?
 

randac56

Member
May 25, 2018
915
0
16
Code:
system.method.set_key = event.download.finished,move_complete_2,"execute=php,-f,/var/www/myscript.php,--,$d.get_base_path=\""
event.download.finished,move_complete_2,"branch=$d.get_custom1=,\"execute={php,-f,/var/www/myscript.php,--,$d.get_base_path=,$d.get_custom1=}\""

and check for value of custom1 inside myscript.php.

Code:
system.method.set_key = event.download.finished,move_complete_2,"execute=php,-f,/var/www/myscript.php,--,$d.get_base_path=\""​
system.method.set_key = event.download.finished,move_complete_2,"execute={php,-f,/var/www/myscript.php,--,$d.get_base_path=}"
 

simur612

Member
May 25, 2018
879
0
16
Doing the check for the series label in the php script is a good idea: that seems to work if I only use your second command:
system.method.set_key = event.download.finished,move_complete_2,"execute={php,-f,/var/www/myscript.php,--,$d.get_base_path=}"
But this won't work in conjunction with my first command to move all finished downloads to another location:
Code:
system.method.set_key = event.download.finished,move_complete_2,"execute=php,-f,/var/www/myscript.php,--,$d.get_base_path=\""
Also, I couldn't get your first command running:
event.download.finished,move_complete_2,"branch=$d.get_custom1=,\"execute={php,-f,/var/www/myscript.php,--,$d.get_base_path=,$d.get_custom1=}\""
Without prepending system.method.set_key = , I recieve the following error message: Error in option file: ~/.rtorrent.rc:125: Could not find '='.
But with it, it wouldn't trigger calling the php script.

It's probably quite simple to fix, but since I never got the grasp on this scripting language, I'm still at a loss at how to combine those two command.
Can you give me another hint how I could make this work?
 

simur612

Member
May 25, 2018
879
0
16
After resigning for several weeks, I just invested another five hours to finally get this working.
Since it is still completely unpredictable to me how all of this works, I now handle everything in the php script:
Code:
system.method.set_key = event.download.finished,move_complete,"execute={php,-f,/var/www/myscript.php,--,$d.get_base_path=,$d.get_custom1=}
I'd love to do some more stuff like stopping or removing the torrent, but this doesn't seem to work either - so I gave up.

It is a shame that rtorrent uses such a crappy scripting language without any documentation at all. If it wasn't for that, rtorrent would be a really great tool.

sad.gif
 

lisas4567

Member
May 25, 2018
773
0
16
If you want to send xmlrpc commands back, you have to decouple (demon-fork) your process from rTorrent.