A script to migrate your torrents from Ktorrent...

Post Reply
timmyclub

A script to migrate your torrents from Ktorrent...

Post by timmyclub »

Hi all...

This is pretty sketchy (I'm no 'programmer'!) and I'm sure there are probably better/easier ways to do this but I thought I'd share it anyway. As per the topic, it just gives you a little help in changing to deluge as your primary client, if you're a previous user of ktorrent. It does it sort of 'automatically manually'. It'd be much better if it was all done in the background, just working with the data in the deluge/ktorrent config folders.. However, as it is, you'll have deluge opening and closing itself every 20 seconds... so if you have a fair few torrents, you better go read a good book. :) - I hope someone finds it useful anyway... I couldn't find any other method on the interwebs.

Anyway, here's the the instructions...

1)Open deluge, go to preferences and make sure that there is a default download folder set. It doesn't matter where.

2)Close deluge

3)Run my bizarre script:

Code: Select all

#VERY dirty script to migrate from ktorrent to deluge.
#Works under Ubuntu 'Gutsy' at least.. 
#!/bin/bash

#Better make sure you run this as the user who uses the torrent clients..
user=`whoami`


#Get a list of all the torrents Ktorrent has stored...
for dir in `ls /home/$user/.kde/share/apps/ktorrent/ |grep tor`

do
	
	echo Working on $dir...

	#Get the intended (ktorrent) destination dir
	stats=`grep OUTPUTDIR /home/$user/.kde/share/apps/ktorrent/$dir/stats`
	dldir="${stats#*=}"

	#Get Deluge's current default destination dir
	delconf=(`grep -A1 p58 /home/$user/.config/deluge/prefs.state`)
	currentdldir=${delconf[1]}


	###############################################################################
	# I had a strange problem where ktorrent listed most of my music torrents as
	# having /media/listen/Music as their destination folder.  Some of them, however,
	# had /media/listen/Music/Torrent Name/ as the destination.  I don't know why,
	# but all I did was to check if the first 19 chars of the string were my music
	# folder.  If they were, I redifined the variable to be sure.
	#
	#maybemusic=${dldir:0:19}
	#
	#if [ "$maybemusic" = "/media/listen/Music"  ]                                  
	#then 
	#	dldir=/media/listen/Music/ 
	#fi 
	###############################################################################


	echo Replacing $currentdldir with S\'$dldir\'...
	#Replace current with intended in deluge config.
	sed -e "s:$currentdldir:S'$dldir':" /home/$user/.config/deluge/prefs.state > /home/$user/.config/deluge/prefs.state.temp
	cat /home/$user/.config/deluge/prefs.state.temp > /home/$user/.config/deluge/prefs.state

	
	echo Creating /home/$user/.kde/share/apps/ktorrent/$dir/$dir.torrent...
	#Deluge wont accept torrents without a '.torrent' extension, and requires torrents to have different names
	#...so we make one and start deluge.
	cp /home/$user/.kde/share/apps/ktorrent/$dir/torrent /home/$user/.kde/share/apps/ktorrent/$dir/$dir.torrent
	deluge /home/$user/.kde/share/apps/ktorrent/$dir/$dir.torrent &

	echo Sleeping...
	#Allow my poor computer to catch up (hopefully)
	sleep 10
	#Have restart deluge each time, or it wont take new dldir.
	echo Killing deluge...
	killall -9 deluge
	echo Sleeping...
	sleep 10

	echo Removing /home/$user/\.kde/share/apps/ktorrent/$dir/$dir\.torrent...
	#Remove the extra .torrent file.
	rm /home/$user/.kde/share/apps/ktorrent/$dir/$dir.torrent

done
Note: I hope you wont need to use the commented bit in the middle. I think it was a problem caused when I moved music trackers recently :-(
I left it there as an example though, just in case it's due to a ktorrent update or something.

4) Find alternative entertainment...
johnnyg
Top Bloke
Top Bloke
Posts: 1522
Joined: Sun Oct 28, 2007 4:00 am
Location: Sydney, Australia

Re: A script to migrate your torrents from Ktorrent...

Post by johnnyg »

wow, that's an interesting approach...

however the latest svn has an autoload from folder feature which pretty much does the same thing as this (without having to run deluge n times :P)

thanks anyway for sharing...
timmyclub

Re: A script to migrate your torrents from Ktorrent...

Post by timmyclub »

Hah.. You're welcome. I guess that's the non-programmer's approach! :-) (biology teacher)

Anyway... I'm glad there is a better way for others!
deloptes
New User
New User
Posts: 2
Joined: Mon Sep 01, 2008 10:53 pm

Re: A script to migrate your torrents from Ktorrent...

Post by deloptes »

Does anybody know how to migrate from azureus to deluge?

thanks
Post Reply