Page 2 of 4

Re: [In progress] One-by-one download plugin

Posted: Sat Jan 17, 2009 10:00 am
by DaVince
You make some very good points. I also appreciate it you're reminding me of the "Don't download" thing - I actually completely forgot the option!
As for your code style: I don't really see the point of making AMOUNT_HIGHEST and AMOUNT_HIGH global variables, you could just as easily pass them into set_priorities (in fact if you did this you wouldn't need the temporary variable "counter").
You mean like arguments? Good idea, but I kind of need a clue on how I'm going to avoid the use of "counter" here... I'm quite sure I could do without, I'm just not seeing how really. :?
EDIT: using enumerate for that loop now.


I'm putting down some ideas of my own for the actual plugin:

You can have it auto-manage all still-downloading torrents, but you can also turn this off and individually manage the torrents. When auto-managed the plugin could check (or just set) priorities every one or two minutes.

When not priority-managed, right-click on a torrent and you can "prioritize its files", which sets the files to highest/high/normal priority, based on the two setting boxes in the plugin's settings pane.

The config panel could have a number input box for the minimum treshhold to enable the usage of auto-managing a torrent - for example, it's useless to set the priority to highest on a torrent that contains only one (or maybe two) files.

Maybe some compatibility with the label plugin, where only torrents with a specific label will be checked and priority-managed?

Re: [In progress] Sequential download plugin

Posted: Sat Jan 17, 2009 3:03 pm
by Case
I downloaded the script and ran it, but it says

Code: Select all

[DEBUG   ] 15:57:28 client:46 CoreProxy init..
[INFO    ] 15:57:28 client:105 Setting core uri as http://localhost:58846
[DEBUG   ] 15:57:28 client:137 Creating ServerProxy..
Traceback (most recent call last):
  File "./deluge-priority-setter.py", line 99, in <module>
    main()
  File "./deluge-priority-setter.py", line 49, in main
    torrents = sclient.get_torrents_status({"state":"Downloading"}, ["name", "file_progress", "files"]).items()
AttributeError: 'NoneType' object has no attribute 'items'
HTH. As I read it, it's designed to prioritize every running torrent? Would it be possible to pass the torrent file to be prioritized as an argument?

Re: [In progress] Sequential download plugin

Posted: Sun Jan 18, 2009 2:41 am
by DaVince
The script does indeed go through all torrents. I'm planning to have it work on individual torrents in the plugin, but this is difficult to do for the standalone script because torrents have weird IDs and there's nothing "clickable". I guess I could make a commandline option menu for that, but that effort could be better spent to making the actual plugin, right?

Thanks for posting the error, that one line of code is supposed to return an array of all active torrents but it would obviously fail if there are none (is this the case? If not, lemme know. I definitely need to put some error catching in there).

Re: [In progress] One-by-one download plugin

Posted: Sun Jan 18, 2009 6:23 am
by johnnyg
DaVince wrote:You mean like arguments? Good idea, but I kind of need a clue on how I'm going to avoid the use of "counter" here... I'm quite sure I could do without, I'm just not seeing how really. :?
EDIT: using enumerate for that loop now.
you would just decrement amount highest and amount high, and only apply the priority if it was greater than 0.
code wise it would be something like this:

Code: Select all

priorities = []
for file in incomplete_files:
   if amount_highest != 0:             # != would mean that setting negative values (eg. -1) would mean an infinite number
      priority[file] = PRIO_MAX
      amount_highest -= 1
   elif amount_high != 0:
      priority[file] = PRIO_HIGH
      amount_high -= 1
   else
      priority[file] = PRIO_NORMAL
DaVince wrote: When auto-managed the plugin could check (or just set) priorities every one or two minutes.
what would be better was if there was an event for when a file inside a torrent finished, so that you could just catch that, but that doesn't currently exist :(

Keep us posted with your progress.

Re: [In progress] Sequential download plugin

Posted: Sun Jan 18, 2009 8:42 am
by Case
DaVince wrote:Thanks for posting the error, that one line of code is supposed to return an array of all active torrents but it would obviously fail if there are none (is this the case? If not, lemme know. I definitely need to put some error catching in there).
There was one active torrent with 22 files inside a directory, downloading and all files on Normal prio.

Re: [In progress] Sequential download plugin

Posted: Tue Apr 21, 2009 7:20 am
by aXis
Case wrote:I downloaded the script and ran it, but it says
...
AttributeError: 'NoneType' object has no attribute 'items'[/code]
...
I had a similar problem - it turns out that my client didnt like the default core_uri or something and was never connecting to the deluge RPC propper. I had to modify the core_uri to something that would stick like:

sclient.set_core_uri('http://localclient:password@localhost:58846')

where localclient:password is what is contained in your deluge/auth file.

Re: [In progress] Sequential download plugin

Posted: Tue Apr 21, 2009 7:32 am
by aXis
I've also modified DaVince's script so that it will handle "do not download" items. I'd like to limit the overall active files to about 20, but cant think of a way to do that and obey users "do not download" settings. Personally i find that 2 highest and 3 high priority file works well.

The code has been refactored quite a bit but it's my first foray into python so it's not very clever. Still works fine though:

Code: Select all

#!/usr/bin/env python
#-*- coding:utf-8 -*-

# "Sequential Files" v0.2, 21/04/2009
# By aXis - http://forum.deluge-torrent.org/memberlist.php?mode=viewprofile&u=46045

# Inspired and based on "Alphabetic Downloader" v0.1 by Vincent Beers (DaVince)
# http://davince.tengudev.com/code/python/deluge-priority-setter.py
# see http://forum.deluge-torrent.org/viewtopic.php?f=9&t=13515

'''
This Deluge script sets the file priorities in a torrent file
so that the first encountered incomplete files will get the highest
priority. Benefits for this are that the first next episode in a
series will be downloaded first, instead of all episodes at the same
time.
'''

from deluge.ui.client import sclient
sclient.set_core_uri('http://localclient:[PASSWORD]@localhost:58846')

# constants used by deluge priorities
PRIO_SKIP = 0
PRIO_NORMAL = 1
PRIO_HIGH = 2
PRIO_HIGHEST = 5

# Options for the amount of files that will have their priority set
AMOUNT_HIGHEST = 2
AMOUNT_HIGH = 3

####################
def main():
  torrents = sclient.get_torrents_status({"state":"Downloading"}, ["name", "file_priorities", "file_progress"]).items()

  for torrent_id, torrent in torrents:
    set_priorities(torrent_id, torrent)

####################
def set_priorities(torrent_id, torrent):

  #prepare our priority counters
  highest_remain = AMOUNT_HIGHEST
  high_remain = AMOUNT_HIGH

  # get the file details from the torrent
  print "Torrent:",torrent["name"]  
  priorities = torrent["file_priorities"]
  progress = torrent["file_progress"]

  # go through each file and work out the appropriate amounts of each priority
  for i in range(len(priorities)):
    if (progress[i] < 1) and (priorities[i] > PRIO_SKIP):
      if highest_remain > 0:
         priorities[i] = PRIO_HIGHEST
         highest_remain-=1
      elif high_remain > 0:
         priorities[i] = PRIO_HIGH
         high_remain-=1
      else:
         priorities[i] = PRIO_NORMAL

  # set the priorities
  print priorities
  sclient.set_torrent_file_priorities(torrent_id, priorities)

  return

####################
if __name__ == "__main__":
  main()
Take note to fix the password or make the core_uri blank if that works for you.

Re: [In progress] Sequential download plugin

Posted: Tue Apr 21, 2009 5:50 pm
by Case
I added "localclient:password" to ~/.config/deluge/auth (it didn't even exist btw), but I still get the same error. In netstat I can see the daeluged at localhost:58846
When I look at the deluged.log I see [DEBUG ] 19:48:05 core:493 'state' whenever I run the script. Any ideas?

Re: [In progress] Sequential download plugin

Posted: Wed Apr 22, 2009 1:11 am
by aXis
Were you running the old script or the new one?

For some reason when I call sclient.set_core_uri() or even sclient.set_core_uri('http://localhost:58846') on my server, it does nothing and the core_uri stays as blank. Calling "is_localhost" or "connected" both return false.

It's not until I move my uri away from the default that it seems to stick. Eg, turning on "allow remote connections" and then modifying the line in the script to sclient.set_core_uri('http://[server ip address]:58846') made a difference, albeit I then got an "unauthorised error". Adding the login to localhost also made enough of a change for it to work too.

Try this script and see where it fails:

Code: Select all

#!/usr/bin/env python
#-*- coding:utf-8 -*-

from deluge.ui.client import sclient

print "\n### inital"
print "core_uri: ",sclient.get_core_uri()
print "is localhost: ", sclient.is_localhost()
print "is connected: ", sclient.connected()

print "\n### blank"
sclient.set_core_uri()
print "core_uri: ",sclient.get_core_uri()
print "is localhost: ", sclient.is_localhost()
print "is connected: ", sclient.connected()
print "stats:"
try:
  stats = sclient.get_stats()
  for key in sorted(stats.keys()):
    print key, ":", stats[key]
except Exception, e:
  print e


print "\n### localhost"
sclient.set_core_uri('http://localhost:58846')
print "core_uri: ",sclient.get_core_uri()
print "is localhost: ", sclient.is_localhost()
print "is connected: ", sclient.connected()
print "stats:"
try:
  stats = sclient.get_stats()
  for key in sorted(stats.keys()):
    print key, ":", stats[key]
except Exception, e:
  print e


print "\n### localclient"
sclient.set_core_uri('http://localclient:password@localhost:58846')
print "core_uri: ",sclient.get_core_uri()
print "is localhost: ", sclient.is_localhost()
print "is connected: ", sclient.connected()
print "stats:"
try:
  stats = sclient.get_stats()
  for key in sorted(stats.keys()):
    print key, ":", stats[key]
except Exception, e:
  print e


Re: [In progress] Sequential download plugin

Posted: Wed Apr 22, 2009 5:21 am
by Case
I was running the new script, but with an older release of Deluge (1.0.7 - I'm running Mandriva and apparently they didn't keep up). I updated Deluge and now the script works.

I suppose one has to run this script at regular intervals? it looks like a one-shot. for now I just did
while pgrep deluge &>/dev/null; do ./deluge_prio.py; sleep 60; done