mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-08 01:18:39 +00:00
Multiple files prioritize first last.
Now `set_prioritize_first_last()` sets the first 2% and the last 2% of the pieces of each file on a torrent at a high priority, ie, it no longer works on just single file torrents.
This commit is contained in:
parent
837c39fdda
commit
89b79c76a3
1 changed files with 20 additions and 8 deletions
|
@ -252,14 +252,26 @@ class Torrent(object):
|
||||||
|
|
||||||
def set_prioritize_first_last(self, prioritize):
|
def set_prioritize_first_last(self, prioritize):
|
||||||
self.options["prioritize_first_last_pieces"] = prioritize
|
self.options["prioritize_first_last_pieces"] = prioritize
|
||||||
if prioritize:
|
if self.handle.has_metadata():
|
||||||
if self.handle.has_metadata():
|
if self.options["compact_allocation"]:
|
||||||
if self.handle.get_torrent_info().num_files() == 1:
|
log.debug("Setting first/last priority with compact "
|
||||||
# We only do this if one file is in the torrent
|
"allocation does not work!")
|
||||||
priorities = [1] * self.handle.get_torrent_info().num_pieces()
|
return
|
||||||
priorities[0] = 7
|
|
||||||
priorities[-1] = 7
|
paths = {}
|
||||||
self.handle.prioritize_pieces(priorities)
|
ti = self.handle.get_torrent_info()
|
||||||
|
for n in range(ti.num_pieces()):
|
||||||
|
slices = ti.map_block(n, 0, ti.piece_size(n))
|
||||||
|
for slice in slices:
|
||||||
|
fe = ti.file_at(slice.file_index)
|
||||||
|
paths.setdefault(fe.path, []).append(n)
|
||||||
|
|
||||||
|
priorities = self.handle.piece_priorities()
|
||||||
|
for pieces in paths.itervalues():
|
||||||
|
two_percent = 2*100/len(pieces)
|
||||||
|
for piece in pieces[:two_percent]+pieces[-two_percent:]:
|
||||||
|
priorities[piece] = prioritize and 7 or 1
|
||||||
|
self.handle.prioritize_pieces(priorities)
|
||||||
|
|
||||||
def set_auto_managed(self, auto_managed):
|
def set_auto_managed(self, auto_managed):
|
||||||
self.options["auto_managed"] = auto_managed
|
self.options["auto_managed"] = auto_managed
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue