forked from LBRYCommunity/lbry-sdk
break up GetStream.start() function further for testing
This commit is contained in:
parent
fc40f5525a
commit
be75c1bc5b
2 changed files with 18 additions and 13 deletions
|
@ -52,7 +52,8 @@ class SingleProgressManager(object):
|
||||||
def _check_if_finished(self):
|
def _check_if_finished(self):
|
||||||
if self.stream_position() == 1:
|
if self.stream_position() == 1:
|
||||||
blob_downloaded = self.download_manager.blobs[0]
|
blob_downloaded = self.download_manager.blobs[0]
|
||||||
log.debug("The blob %s has been downloaded. Calling the finished callback", str(blob_downloaded))
|
log.debug("The blob %s has been downloaded. Calling the finished callback",
|
||||||
|
str(blob_downloaded))
|
||||||
safe_stop_looping_call(self.checker)
|
safe_stop_looping_call(self.checker)
|
||||||
self.finished_callback(blob_downloaded)
|
self.finished_callback(blob_downloaded)
|
||||||
elif self.timeout is not None:
|
elif self.timeout is not None:
|
||||||
|
|
|
@ -162,9 +162,8 @@ class GetStream(object):
|
||||||
defer.returnValue(self.download_path)
|
defer.returnValue(self.download_path)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def initialize(self, stream_info, name):
|
def _initialize(self, stream_info):
|
||||||
# Set sd_hash and return key_fee from stream_info
|
# Set sd_hash and return key_fee from stream_info
|
||||||
self.set_status(INITIALIZING_CODE, name)
|
|
||||||
self.sd_hash = stream_info.source_hash
|
self.sd_hash = stream_info.source_hash
|
||||||
key_fee = None
|
key_fee = None
|
||||||
if stream_info.has_fee:
|
if stream_info.has_fee:
|
||||||
|
@ -179,14 +178,14 @@ class GetStream(object):
|
||||||
defer.returnValue(downloader)
|
defer.returnValue(downloader)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def download(self, name, key_fee):
|
def _download_sd_blob(self):
|
||||||
# download sd blob, and start downloader
|
sd_blob = yield download_sd_blob(self.session, self.sd_hash,
|
||||||
self.set_status(DOWNLOAD_METADATA_CODE, name)
|
self.payment_rate_manager, self.timeout)
|
||||||
sd_blob = yield download_sd_blob(self.session, self.sd_hash, self.payment_rate_manager, self.timeout)
|
defer.returnValue(sd_blob)
|
||||||
self.downloader = yield self._create_downloader(sd_blob)
|
|
||||||
|
|
||||||
self.set_status(DOWNLOAD_RUNNING_CODE, name)
|
@defer.inlineCallbacks
|
||||||
if key_fee:
|
def _download(self, sd_blob, name, key_fee):
|
||||||
|
self.downloader = yield self._create_downloader(sd_blob)
|
||||||
yield self.pay_key_fee(key_fee, name)
|
yield self.pay_key_fee(key_fee, name)
|
||||||
|
|
||||||
log.info("Downloading lbry://%s (%s) --> %s", name, self.sd_hash[:6], self.download_path)
|
log.info("Downloading lbry://%s (%s) --> %s", name, self.sd_hash[:6], self.download_path)
|
||||||
|
@ -204,11 +203,16 @@ class GetStream(object):
|
||||||
downloader - instance of ManagedEncryptedFileDownloader
|
downloader - instance of ManagedEncryptedFileDownloader
|
||||||
finished_deferred - deferred callbacked when download is finished
|
finished_deferred - deferred callbacked when download is finished
|
||||||
"""
|
"""
|
||||||
key_fee = yield self.initialize(stream_info, name)
|
self.set_status(INITIALIZING_CODE, name)
|
||||||
|
key_fee = yield self._initialize(stream_info)
|
||||||
|
|
||||||
yield self.download(name, key_fee)
|
self.set_status(DOWNLOAD_METADATA_CODE, name)
|
||||||
|
sd_blob = yield self._download_sd_blob()
|
||||||
|
|
||||||
|
yield self._download(sd_blob, name, key_fee)
|
||||||
|
self.set_status(DOWNLOAD_RUNNING_CODE, name)
|
||||||
safe_start(self.checker)
|
safe_start(self.checker)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield self.data_downloading_deferred
|
yield self.data_downloading_deferred
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
|
Loading…
Reference in a new issue