From 0e63ed4ebcb8a51408ec0b2fd8efb95f6106a62e Mon Sep 17 00:00:00 2001 From: Anders Jensen Date: Sat, 25 Aug 2018 09:16:07 +0200 Subject: [PATCH 1/3] fixed small bug with file priority overwriting manual priority management --- streaming/core.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/streaming/core.py b/streaming/core.py index afdeddf..445d109 100644 --- a/streaming/core.py +++ b/streaming/core.py @@ -166,7 +166,7 @@ def can_read(self, from_byte): f = self.get_file_from_offset(from_byte) logger.debug('Also setting file to max %r' % (f, )) file_priorities = self.torrent.get_file_priorities() - file_priorities[f['index']] = 7 + file_priorities[f['index']] = 2 self.torrent.set_file_priorities(file_priorities) for _ in range(300): @@ -239,7 +239,7 @@ def _cycle(self): if f['path'] in must_whitelist: if f['path'] in first_files: - file_priorities[i] = 7 + file_priorities[i] = 2 else: file_priorities[i] = 1 elif f['path'] not in cannot_blacklist: @@ -307,7 +307,7 @@ def _cycle(self): if i < first_file: file_priorities[index] = 0 elif i == first_file: - file_priorities[index] = 7 + file_priorities[index] = 2 else: file_priorities[index] = 1 From ec02a2e61d798057566eb62490e2743a274a4079 Mon Sep 17 00:00:00 2001 From: Anders Jensen Date: Sat, 25 Aug 2018 09:53:04 +0200 Subject: [PATCH 2/3] ensure priorities arent overwritten --- streaming/core.py | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/streaming/core.py b/streaming/core.py index 445d109..8ef7b59 100644 --- a/streaming/core.py +++ b/streaming/core.py @@ -70,6 +70,7 @@ AUDIO_STREAMABLE_EXTENSIONS = ['flac', 'mp3', 'oga'] STREAMABLE_EXTENSIONS = set(VIDEO_STREAMABLE_EXTENSIONS + AUDIO_STREAMABLE_EXTENSIONS) TORRENT_CLEANUP_INTERVAL = timedelta(minutes=30) +MAX_FILE_PRIORITY = 2 DEFAULT_PREFS = { 'ip': '127.0.0.1', @@ -164,10 +165,12 @@ def can_read(self, from_byte): self.torrent.handle.piece_priority(needed_piece, 7) f = self.get_file_from_offset(from_byte) - logger.debug('Also setting file to max %r' % (f, )) + file_priorities = self.torrent.get_file_priorities() - file_priorities[f['index']] = 2 - self.torrent.set_file_priorities(file_priorities) + if file_priorities[f['index']] != MAX_FILE_PRIORITY: + logger.debug('Also setting file to max %r' % (f, )) + file_priorities[f['index']] = MAX_FILE_PRIORITY + self.torrent.set_file_priorities(file_priorities) for _ in range(300): if self.torrent.status.pieces[needed_piece]: @@ -239,7 +242,7 @@ def _cycle(self): if f['path'] in must_whitelist: if f['path'] in first_files: - file_priorities[i] = 2 + file_priorities[i] = MAX_FILE_PRIORITY else: file_priorities[i] = 1 elif f['path'] not in cannot_blacklist: @@ -265,6 +268,23 @@ def _cycle(self): else: fileset_ranges[fileset_hash] = fileset['files'].index(path) + file_priorities = self.torrent.get_file_priorities() + logger.debug('Fileset heads: %r' % (fileset_ranges, )) + for fileset_hash, first_file in fileset_ranges.items(): + fileset = self.filesets[fileset_hash] + logger.debug('From index %s' % (first_file, )) + file_mapping = {f['path']: f['index'] for f in status['files']} + for i, f in enumerate(fileset['files']): + index = file_mapping[f] + if i < first_file: + file_priorities[index] = 0 + elif i == first_file: + file_priorities[index] = MAX_FILE_PRIORITY + else: + file_priorities[index] = 1 + + self.torrent.set_file_priorities(file_priorities) + currently_downloading = self.get_currently_downloading() logger.debug('File heads: %r' % (file_ranges, )) for f, progress in zip(status['files'], status['file_progress']): @@ -296,23 +316,6 @@ def _cycle(self): else: self.torrent.handle.piece_priority(piece, 1) - file_priorities = self.torrent.get_file_priorities() - logger.debug('Fileset heads: %r' % (fileset_ranges, )) - for fileset_hash, first_file in fileset_ranges.items(): - fileset = self.filesets[fileset_hash] - logger.debug('From index %s' % (first_file, )) - file_mapping = {f['path']: f['index'] for f in status['files']} - for i, f in enumerate(fileset['files']): - index = file_mapping[f] - if i < first_file: - file_priorities[index] = 0 - elif i == first_file: - file_priorities[index] = 2 - else: - file_priorities[index] = 1 - - self.torrent.set_file_priorities(file_priorities) - def get_currently_downloading(self): currently_downloading = set() for peer in self.torrent.handle.get_peer_info(): From 9e38de34f2373e84b94148d3da96715dca9d0345 Mon Sep 17 00:00:00 2001 From: Anders Jensen Date: Sat, 25 Aug 2018 09:55:11 +0200 Subject: [PATCH 3/3] updated readme and version --- README.md | 3 +++ setup.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ec730fa..910f18a 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,9 @@ The _allow remote_ option is to allow remote add and stream of torrents. # Version Info +## Version 0.10.1 +* Small bugfixes related to priorities, should actually make sequential download work. + ## Version 0.10.0 * Rewrote large parts of the code * Now using [thomas](https://github.com/JohnDoee/thomas) as file-reading core - this adds support for multi-rar streaming. diff --git a/setup.py b/setup.py index f74eabb..7be06e8 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ __plugin_name__ = "Streaming" __author__ = "Anders Jensen" __author_email__ = "johndoee@tidalstream.org" -__version__ = "0.10.0" +__version__ = "0.10.1" __url__ = "https://github.com/JohnDoee/deluge-streaming" __license__ = "GPLv3" __description__ = "Enables streaming of files while downloading them."