Re: [In progress] Sequential download plugin
Posted: Thu Apr 23, 2009 8:00 am
I just added mine as a cron job. Once every hour or so should be fine.
Support Forum for the Deluge BitTorrent Client
https://forum.deluge-torrent.org/
Code: Select all
#!/usr/bin/python
#-*- coding:utf-8 -*-
# "Alphabetic Downloader" v0.1
# Copyright (C) 2009 Vincent Beers (DaVince) <VincentBeers@gmail.com>
# Some logic and code Copyright (C) mvoncken.
# http://forum.deluge-torrent.org/memberlist.php?mode=viewprofile&u=407
'''
This Deluge script sets the file priorities in a torrent file
so that the first encountered incomplete file 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 optparse import OptionParser
from deluge.ui.client import sclient
sclient.set_core_uri()
PRIO_NORMAL = 1
PRIO_HIGH = 2
PRIO_MAX = 5
PRIO_DND = 0
#Definitions for the amount of files that will
#have their priority set to highest/high.
AMOUNT_HIGHEST = 1
AMOUNT_HIGH = 1
LABEL = "inorder"
####################
def main():
global AMOUNT_HIGH, AMOUNT_HIGHEST
parser = OptionParser()
parser.add_option("--high", dest="high", type="int", default=2,
help="Set the amount of files that will get a high priority.",
metavar="AMOUNT")
parser.add_option("--highest", dest="highest", type="int", default=1,
help="Set the amount of files that will get the highest priority.",
metavar="AMOUNT")
parser.add_option("--label", dest="label", type="string", default="inorder",
help="Only set the priorities for torrents with this label.",
metavar="LABEL")
(options, args) = parser.parse_args()
AMOUNT_HIGHEST = options.highest
AMOUNT_HIGH = options.high
LABEL = options.label
torrents = sclient.get_torrents_status({"state":"Downloading", "label":LABEL}, ["name", "file_progress", "files", "file_priorities"]).items()
for torrent_id, torrent in torrents:
set_priorities(torrent_id, torrent)
####################
def set_priorities(torrent_id, torrent):
"""Set the priorities for not completely downloaded files in the passed torrent."""
global AMOUNT_HIGH, AMOUNT_HIGHEST
incomplete_files = get_incomplete_files(torrent)
files = [f["path"] for f in torrent["files"]]
#priorities = [PRIO_NORMAL for f in torrent["files"]] #Reset priorites first.
priorities = []
counter = 0
prio = iter(torrent["file_priorities"])
for f in torrent["files"]:
if prio.next() == PRIO_DND:
priorities.append(PRIO_DND)
else:
priorities.append(PRIO_NORMAL)
counter = 0
print "File:", torrent["name"]
#Do the magic of priority setting.
for file in incomplete_files:
if counter < AMOUNT_HIGHEST:
priorities[file] = PRIO_MAX
print (" " + files[file] + " gets highest priority.")
elif counter < (AMOUNT_HIGH + AMOUNT_HIGHEST):
priorities[file] = PRIO_HIGH
print (" " + files[file] + " gets high priority.")
else: break
counter+=1
sclient.set_torrent_file_priorities(torrent_id, priorities)
####################
def get_incomplete_files(torrent):
"""Find incomplete files in a torrent and return them in an array."""
files = []
filenames = [f["path"].lower() for f in torrent["files"]]
for filename in sorted(filenames):
index = filenames.index(filename)
progress = torrent["file_progress"][index]
dnd = torrent["file_priorities"][index]
if progress < 1 and not dnd == PRIO_DND:
files.append(index)
return files
####################
if __name__ == "__main__":
main()
Code: Select all
"priorities_mapping": {"highest": 5,
"high": 2,
"norm": 1,
"dnd": 0},
Code: Select all
"priorities_mapping": {"highest": 7,
"high": 5,
"norm": 1,
"dnd": 0},