mirror of
https://github.com/JohnDoee/deluge-streaming/
synced 2026-07-01 07:31:17 -07:00
fixed bug related to path streaming
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user