From 342b9f77a44dea776037f6c4017c41a689701dcd Mon Sep 17 00:00:00 2001 From: JohnDoee Date: Wed, 18 Nov 2015 11:40:11 +0100 Subject: [PATCH] fixed bug related to path streaming --- README.md | 6 +++++- setup.py | 2 +- streaming/core.py | 9 ++++++++- streaming/filelike.py | 17 +++++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 053bf17..651efbf 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,10 @@ The _allow remote_ option is to allow remote add and stream of torrents. # Version Info +## Version 0.5.0 +* Restructured the whole plugin +* Added support for StreamProtocol + ## Version 0.4.1 * Fixed bug with old Deluge versions @@ -58,4 +62,4 @@ The _allow remote_ option is to allow remote add and stream of torrents. * Improved buffering algorithm, not using only deadline anymore. ## Version 0.1 -* Initial working release \ No newline at end of file +* Initial working release diff --git a/setup.py b/setup.py index 9d26610..7a9c72a 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ from setuptools import setup __plugin_name__ = "Streaming" __author__ = "John Doee" __author_email__ = "johndoee@tidalstream.org" -__version__ = "0.4.1" +__version__ = "0.5.0" __url__ = "https://github.com/JohnDoee/deluge-streaming" __license__ = "GPLv3" __description__ = "Enables streaming of files while downloading them." diff --git a/streaming/core.py b/streaming/core.py index 6e41904..e8e3432 100644 --- a/streaming/core.py +++ b/streaming/core.py @@ -225,6 +225,7 @@ class TorrentFile(object): # can be read from, knows about itself logger.debug('Got data for piece %i, but no data needed for this piece?' % alert.piece) return # TODO: check piece size is not zero + self.waiting_pieces[alert.piece].callback(alert.buffer) @defer.inlineCallbacks @@ -293,8 +294,13 @@ class Torrent(object): first_piece = f['offset'] / piece_length last_piece = (f['offset'] + f['size']) / piece_length full_path = os.path.join(save_path, f['path']) + + path = f['path'] + if '/' in path: + path = '/'.join(path.split('/')[1:]) + self.torrent_files.append(TorrentFile(self, first_piece, last_piece, piece_length, f['offset'], - f['path'], full_path, f['size'], f['index'])) + path, full_path, f['size'], f['index'])) return files @@ -303,6 +309,7 @@ class Torrent(object): biggest_file_size = 0 for i, f in enumerate(self.torrent_files): + logger.debug('Testing file %r against %s / %r' % (file_or_index, i, f.path)) if file_or_index is not None: if i == file_or_index or f.path == file_or_index: best_file = f diff --git a/streaming/filelike.py b/streaming/filelike.py index ea4ff65..651c92d 100644 --- a/streaming/filelike.py +++ b/streaming/filelike.py @@ -12,7 +12,12 @@ class NoRangeStaticProducer(static.NoRangeStaticProducer): def resumeProducing(self): if not self.request: return + data = yield defer.maybeDeferred(self.fileObject.read, self.bufferSize) + + if not self.request: + return + if data: # this .write will spin the reactor, calling .doWrite and then # .resumeProducing again, so be prepared for a re-entrant call @@ -27,13 +32,19 @@ class SingleRangeStaticProducer(static.SingleRangeStaticProducer): def resumeProducing(self): if not self.request: return + data = yield defer.maybeDeferred(self.fileObject.read, min(self.bufferSize, self.size - self.bytesWritten)) + + if not self.request: + return + if data: self.bytesWritten += len(data) # this .write will spin the reactor, calling .doWrite and then # .resumeProducing again, so be prepared for a re-entrant call self.request.write(data) + if self.request and self.bytesWritten == self.size: self.request.unregisterProducer() self.request.finish() @@ -44,6 +55,7 @@ class MultipleRangeStaticProducer(static.MultipleRangeStaticProducer): def resumeProducing(self): if not self.request: return + data = [] dataLength = 0 done = False @@ -64,7 +76,12 @@ class MultipleRangeStaticProducer(static.MultipleRangeStaticProducer): except StopIteration: done = True break + + if not self.request: + return + self.request.write(''.join(data)) + if done: self.request.unregisterProducer() self.request.finish()