Export from Deluge to rTorrent upon completion.

Suggest, post, or discuss plugins for Deluge
Post Reply
chimpy
New User
New User
Posts: 6
Joined: Sun Mar 11, 2012 4:06 pm

Export from Deluge to rTorrent upon completion.

Post by chimpy »

In my experience, whilst Deluge is superb at downloading, and uploading whilst downloading, rTorrent beats it hands-down in terms of getting connected and uploading whilst simply seeding. So I made myself a script and I thought I'd share it. I hope this helps someone (maybe even just with experimenting! I found the documentation incredibly difficult to penetrate, or outdated, when I tried to get to grips with the JSON). I don't mean this to insult Cas in any way! I absolutely love Deluge. I'll be a happy man when I don't need this script any more.

• Copy this script and use your favourite text editor to save it somewhere.
• Download this script: http://libtorrent.rakshasa.no/downloads ... _resume.pl and put it somewhere.
• Dive into a terminal and "chmod +x" both of these files.
• Do the following for the perl script to work: sudo perl -MCPAN -e 'install Convert::Bencode'
• Configure the configurable things in the script. They're all important so don't miss one.
• Ensure you have fully completed torrents in Deluge. Any half-completed (like one episode from a series) or still downloading torrents will not be ported to rTorrent, but will still have their .torrent files removed from Deluge's session directory!
• Ensure rTorrent is setup as you would like. You basically just need the watch folder setup. Any other stuff like ruTorrent can wait if you want.
• Run the script from the command line. You'll get a bunch of output as rtorrent_fast_resume.pl adds fast_resume data to all your torrent files.
• All your Deluge torrent files are now in rTorrent's watch folder and have been added if rTorrent was running!
• Go to Deluge and remove (without data!!) all your torrents.
• Go to Preferences --> Plugins. Turn on Execute: http://cl.ly/EnBh
• Restart deluged.
• Go to Preferences --> Execute. Do your version of this (i.e. enter the path to this script!): http://cl.ly/EnOO Click Apply/Okay/etc.
• Optionally change "backup=yes" to "backup=no"
• Optionally enter a cronjob to clear out rTorrent's watch folder for .torrent files every 24 hours: "crontab -e" and enter "0 0 * * * rm $HOME/path/to/rtorrent/watch_folder/*.torrent > /dev/null 2>&1" – unadvisable if you have schedule start_tied set.
• Add a torrent to Deluge and test it!

In order to not have to start using two different web-interfaces, you could start using this UserScript to add torrents to Deluge (and hence rTorrent) with minimal effort (works on private trackers too) (use it with NinjaKit for Safari): http://userscripts.org/scripts/show/79003

Code: Select all

#!/bin/bash

####################################################################
###             Please fill in the variables below!              ###
####################################################################

# Default is "deluge", but you should have changed it...
password=deluge

# Your domain/IP here. For example, google.com or localhost or 127.0.0.1
domain=localhost

# The port you use to access the WebUI (default 8112)
port=8112

# Do you use http or https to access the WebUI (default http)?
scheme=http

# Which folder are you keeping rtorrent_fast_resume.pl in?
# Please include trailing slash.
dir=$HOME/torrents/

# Where do your torrents eventually download to? If they auto-move
# please specify that directory. Please include trailing slash.
download=$HOME/torrents/complete/

# rTorrent's watch folder. Please include trailing slash.
watch=$HOME/torrents/watchr/

# Do you want to backup whatever's in Deluge's state directory before
# rm'ing it all? (Useful the first time for the mass-transfer but
# probably not afterward).
backup=yes

# Do not change this unless you have knowingly changed Deluge's
# state folder.
files=$HOME/.config/deluge/state/

###							         ###
# This script is designed to be used alongside the Execute plugin! #
###								 ###

###################################################################
### Please remember to create the watch folder for rTorrent!    ###
### Please remember to have rTorrent fully setup and config'd!	###
### Remember to chmod +x this script and the perl script!	###
###################################################################

# Backup if you told it to.
date=`date +"%m-%d-%Y-%H.%M.%S"`
if [ "$backup" = "yes" ]; then tar -cf $HOME/deluge_state.$date.tar $files; fi

# Every torrent, "f", will have fastresume data added and then moved
# to rTorrent's watch directory, "watchr" for addition.
# $1,$2 received from Execute plugin. Need specifics when not en masse.
# If block ensures these lines don't run except via Execute plugin.
# Authenticating to deluge-web.
# Remove torrent using $1 var passed from Execute.
if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
	torrentid=$1
        torrentname=$2
        torrentpath=$3
	perl $dir/rtorrent_fast_resume.pl "$torrentpath" < "$files/$torrentid.torrent" > "$watch/$torrentname.$RANDOM.torrent"
	cookie=`curl -vskm 1 -H "Content-Type: application/json" -X POST -d "{\"id\": 1,\"method\": \"auth.login\",\"params\": [\"$password\"]}" $scheme://$domain:$port/json 2>&1 | grep -i "Set-Cookie:" | cut -d '=' -f2 | cut -d ';' -f1`
	curl -vskm 1 -b _session_id=$cookie -H "Content-Type: application/json" -X POST -d "{\"method\":\"core.remove_torrent\",\"params\":[\"$1\",false],\"id\":2}" $scheme://$domain:$port/json
else
	for f in $files/*.torrent
        do
          name=`basename $f`
          perl $dir/rtorrent_fast_resume.pl $download < $f > $watch/$name
          rm $f
        done
fi
Last edited by chimpy on Sat Apr 28, 2012 12:31 pm, edited 3 times in total.
scerwrz
New User
New User
Posts: 3
Joined: Wed Mar 14, 2012 8:01 pm

Re: Export from Deluge to rTorrent upon completion.

Post by scerwrz »

First of all thank you for this script!

I am having some problems with it, though. The script seems to work properly every time when moving the completed torrents into rTorrent's watch folder. On the other hand, these torrents are not always deleted from Deluge: sometimes they are removed, and sometimes they are not. I have not noticed a pattern on when this happens. I once added 18 torrents at once, and 8 of them were still in Deluge when they were completed (all of them were seeding to rTorrent though).

Hope this can be fixed!
chimpy
New User
New User
Posts: 6
Joined: Sun Mar 11, 2012 4:06 pm

Re: Export from Deluge to rTorrent upon completion.

Post by chimpy »

Hmm, I was wondering what would happen when it was stress tested. I haven't experienced that problem myself yet.

I'm glad at least two people have got it working! Nice to know it's not too hard to set up :D

So what seems to be happening is that the Execute plugin successfully executes the script every time (as the Perl script needs the Execute arguments to move the torrent into rTorrent), but then the problem arises with the curl commands. The first one grabs the cookie and the second one asks Deluge to remove the torrent that just completed (only the .torrent file and the listing from Deluge, not the data).

Perhaps the fact the script is being executed multiple times in quick succession is invalidating the cookie, I'm not sure. A quick thing to try might be setting the max-time argument of the second curl command down to 1 instead of 5.

Change "curl -vskm 5" to "curl -vskm 1" in the second curl command. If that doesn't work, change it back! Keep me posted!

Script edited to remove stress-test bug.

Edit

Due to a bug in the Execute plugin, sometimes this script is not fired, leaving torrents in Deluge. To combat this do the following:

• Edit the file: /usr/share/pyshared/deluge/plugins/Execute-1.2.egg/execute/core.py
• Around line 122, modify the following:

Code: Select all

        # Go through and execute all the commands
        for command in self.config["commands"]:
            if command[EXECUTE_EVENT] == event:
                command = os.path.expandvars(command[EXECUTE_COMMAND])
                command = os.path.expanduser(command)
                log.debug("[execute] running %s", command)
+               if isinstance(torrent_name, unicode):
+                   torrent_name = torrent_name.encode('utf-8')
                d = getProcessOutputAndValue(command, (torrent_id, torrent_name, save_path), env=os.environ)
                d.addCallback(log_error, command)
• Restart Deluge. The problem should now be fixed!
Post Reply