Skip to content

Commit

Permalink
Merge branch 'release/0.10.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders Jensen committed Aug 25, 2018
2 parents ce7f6ef + 9e38de3 commit bfe0f9f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
45 changes: 24 additions & 21 deletions streaming/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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']] = 7
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]:
Expand Down Expand Up @@ -239,7 +242,7 @@ def _cycle(self):

if f['path'] in must_whitelist:
if f['path'] in first_files:
file_priorities[i] = 7
file_priorities[i] = MAX_FILE_PRIORITY
else:
file_priorities[i] = 1
elif f['path'] not in cannot_blacklist:
Expand All @@ -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']):
Expand Down Expand Up @@ -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] = 7
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():
Expand Down

0 comments on commit bfe0f9f

Please sign in to comment.