Improve auto add from folder with a warning! (SOLVED)

Suggestions and discussion of future versions
Post Reply
anonymous_user
Member
Member
Posts: 40
Joined: Sat Jan 31, 2009 7:28 am

Improve auto add from folder with a warning! (SOLVED)

Post by anonymous_user »

Hello,

I've been testing out several torrent clients and their features on a linux distro..

I was attempting to set up my .torrents from my Windows partition to seed whilst I'm dual-booted on my alternate OS, so whichever one I'm on, I'll still be seeding. Since I have a load of .torrents I decided to auto add the directory to Deluge as any new .torrents I add whilst on Windows will be added when I next log onto linux.

The problem is, no where did it state whilst using Deluge that you must use the "Copy of .torrent files to:" ticked at the same time as the "Auto add .torrents from:" function if I wanted to keep my .torrent data files. After auto adding them, my ~500 torrents are now deleted from the original directory moved to the .config/deluge/state folder with filenames that don't mean anything to me. I've read that this is a feature, but in my case it's acted like a major bug. If the filenames had remained the same it wouldn't be so bad, I could just copy them back to my original windows folder so that they still work in uTorrent.

My question is: Where is the safety net? No dialogue box / no mouse over message to tell me my .torrents will be deleted automatically after auto-adding them? So logically a method of retrieving them if the user needed would be in place?

At least I have the files still, but making them work in uTorrent (on Windows) again whilst retaining ratios, labels and force seeding information I don't think is even possible without them named how they were originally..

Is there any way to get these files to revert back to their original state filename wise? Any help/knowledge in making this task of putting everything back in place would be highly appreciated as didn't expect this software to delete my .torrent files without my given permission. Having to remove all my torrents from uTorrent, then adding them again and locating the data of each on my HDD is not something I'm looking forward too! :(

~ Anon

P.S I really should of had my .torrent folder backed up beforehand and I likely would have stopped to do so if mention of torrents being deleted was expressed as some type of warning. I have seen a few posts describing the same issue of their torrents being deleted after downloading them. They suffered the same issue as me, please add a warning so no one unwillingly else gets their torrents deleted like me again.
Last edited by anonymous_user on Sat Apr 16, 2011 10:34 pm, edited 1 time in total.
http://www.bugmenot.com
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Improve auto add from folder with a warning!

Post by Cas »

moved to the .config/deluge/state folder with filenames that don't mean anything to me.
The filenames of the torrents moved to the state folder are clearly the hash ids of the torrents.

I had a think about the problem and one solution is to scrape the title from a site like Torrentz using the hash in the url like this:

Code: Select all

curl -sL http://torrentz.eu/40cf347e39fe45e3c5bfde8d844015cde10ad1e8 | awk -F'[<|>]' '/title/{printf "%s", $3}' | cut -d " " -f 1
This could be put into a bash script that would run through all the files and rename them accordingly.
CSB
Leecher
Leecher
Posts: 66
Joined: Fri Dec 03, 2010 1:55 am

Re: Improve auto add from folder with a warning!

Post by CSB »

Run this script from your .config/deluge/state directory and it will copy all of the torrent files into ~/renamedtorrents with the name they have in deluge.

Make sure to

Code: Select all

mkdir ~/renamedtorrents
first

Code: Select all

#!/usr/bin/python

import shutil
import os
from deluge.ui.client import client
from twisted.internet import reactor
from deluge.log import setupLogger
setupLogger()

d = client.connect()

def on_connect_success(result):
    print "Connection was successful!"
    def on_get_torrent_value(value):

        for torrent in value:
                print "%s: %s" % (torrent, value[torrent]["name"])
                shutil.copy("./"+torrent+".torrent",os.environ['HOME']+"/renamedtorrents/"+value[torrent]["name"]+".torrent")
        
        client.disconnect()
        reactor.stop()
        
    client.core.get_torrents_status({}, ["name"]).addCallback(on_get_torrent_value)

d.addCallback(on_connect_success)

def on_connect_fail(result):
    print "Connection failed!"
    print "result:", result

d.addErrback(on_connect_fail)

reactor.run()
Have a nice day.
anonymous_user
Member
Member
Posts: 40
Joined: Sat Jan 31, 2009 7:28 am

Re: Improve auto add from folder with a warning!

Post by anonymous_user »

Thank you for your help, I am a novice at Linux but I'm sure I'll figure it out!

..if I don't, I'll get back to you two.

Once again thanks,

~ Anon

Edit: @Cas: I'd try that method though firstly, my torrents are from a private tracker, second, the torrents already got renamed slightly by uTorrent originally when moving them from one directory to another. That script may come in handy one day though :)
Last edited by anonymous_user on Sat Apr 16, 2011 6:57 pm, edited 1 time in total.
http://www.bugmenot.com
anonymous_user
Member
Member
Posts: 40
Joined: Sat Jan 31, 2009 7:28 am

Re: Improve auto add from folder with a warning!

Post by anonymous_user »

Hi there CBS,

Thanks for the script. The only problem is I can't get it to work!

I've made a directory named "renamedtorrents" in "/.config/deluge/state". I then made an empty file, pasted your script in there, saved it, then renamed it to "renamescript.sh".

When I run it in Terminal I get:

Code: Select all

Connection failed!
result: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionRefusedError'>: Connection was refused by other side: 111: Connection refused.
]
..something isn't wanting to communicate.

Do you know what the fix is?

Thanks! :)
http://www.bugmenot.com
CSB
Leecher
Leecher
Posts: 66
Joined: Fri Dec 03, 2010 1:55 am

Re: Improve auto add from folder with a warning!

Post by CSB »

Make sure the deluge daemon is running locally.

I'm not home right now, so I'm not able to be too much of a help at the moment.
anonymous_user
Member
Member
Posts: 40
Joined: Sat Jan 31, 2009 7:28 am

SOLVED!

Post by anonymous_user »

I'm not entirely sure what you mean by check if the daemon is running locally.. Sometimes I see Deluge-gtk (IIRC) as a process and sometimes /usr/bin/deluge but never a separate daemon process.

What I've done so far is turn off classic mode then shutdown Deluge and Daemon (program hangs so I have to kill it). Now I launched Deluge again, the process is /usr/bin/deluge, and the Connection Manager pops up, I hit start Daemon and I receive an error:

Code: Select all

Unable to start daemon!

Deluge cannot find the 'deluged' executable, it is likely that you forgot to install the deluged package or it's not in your PATH.
(No wonder "deluged" in Terminal wasn't working.)

So, now I've downloaded deluged (the daemon) through Ubuntu Software Centre, opened Deluge again and now on the Connections Manager, start Daemon works!

Both processes are running now so I ran your script again but received:

Code: Select all

Connection was successful!
(removed-hash-ID-here): (removed-torrent-name-here)
Unhandled error in Deferred:
Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/twisted/internet/tcp.py", line 460, in doRead
    return self.protocol.dataReceived(data)
  File "/usr/lib/pymodules/python2.6/deluge/ui/client.py", line 183, in dataReceived
    d.callback(request[2])
  File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 318, in callback
    self._startRunCallbacks(result)
  File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 424, in _startRunCallbacks
    self._runCallbacks()
--- <exception caught here> ---
  File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 441, in _runCallbacks
    self.result = callback(self.result, *args, **kw)
  File "/home/USERNAME-HERE/.config/deluge/state/renamescript.sh", line 18, in on_get_torrent_value
    shutil.copy("./"+torrent+".torrent",os.environ['HOME']+"/renamedtorrents/"+value[torrent]["name"]+".torrent")
  File "/usr/lib/python2.6/shutil.py", line 84, in copy
    copyfile(src, dst)
  File "/usr/lib/python2.6/shutil.py", line 51, in copyfile
    with open(dst, 'wb') as fdst:
exceptions.IOError: [Errno 2] No such file or directory: '/home/USERNAME-HERE/renamedtorrents/(removed-torrent-name-here).torrent'
So, your initial instructions as I understood it was to create "renamedtorrents" in the "/.config/deluge/state" directory but in fact it was needed to be put in the /home/USERNAME-HERE directory. (Edit: On second read I assume when you said "mkdir ~/renamedtorrents" the ~ refers to the user directory root. You were correct.)

After creating a "renamedtorrents" in the user directory I ran the script and it seems as if all is well!

Thank you so much for your script and help, couldn't of done it without you! :D

P.S A lengthy reply for those Googler's who land on this post after going through the same problem. I hate forum users who leave a post such as "nvm figured it out", really doesn't help anyone!
http://www.bugmenot.com
CSB
Leecher
Leecher
Posts: 66
Joined: Fri Dec 03, 2010 1:55 am

Re: Improve auto add from folder with a warning! (SOLVED)

Post by CSB »

Glad to see the script was able to help you. When saw your first post, I came up with the idea of the script and had to whip it out, since I thought it was a neat idea, but was bummed after I didn't see any replies =/
anonymous_user
Member
Member
Posts: 40
Joined: Sat Jan 31, 2009 7:28 am

Re: Improve auto add from folder with a warning! (SOLVED)

Post by anonymous_user »

Haha, I gave up after a while as there was no hope left how I saw it! Luckily I came back to this thread :)

If this had happened on Windows using Deluge, could a similar script have been written and recovered the same information? Or was this solution only a Linux one?

I'm not a great Python scripter but I love to undertake making one every now and then. Your script was inspiring to me though maybe simple to you. I was thinking of having to manually copy paste the title names from each to the torrent files, or make a script that could read uTorrent's resume.dat and match the hash-ID.torrents created by Deluge with the hash IDs written in the .dat file, then replacing the hash-ID.torrent filename uTorrent's names for each. Effectively doing what your script did though I was having trouble finding a place to start!
http://www.bugmenot.com
CSB
Leecher
Leecher
Posts: 66
Joined: Fri Dec 03, 2010 1:55 am

Re: Improve auto add from folder with a warning! (SOLVED)

Post by CSB »

It'd probably have to be modified for Windows, due to the changes of paths and whatnot.

Come to think of it, parsing uTorrent's .dat file would probably be simpler, but I've never seen one, though I have experience with Deluge's API, so that route is what came to me first.
Post Reply