From be75c1bc5b86586e5ecaadcdd0668369fe3f63d4 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Wed, 21 Jun 2017 11:48:35 -0400 Subject: [PATCH] break up GetStream.start() function further for testing --- .../core/client/StandaloneBlobDownloader.py | 3 +- lbrynet/daemon/Downloader.py | 28 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lbrynet/core/client/StandaloneBlobDownloader.py b/lbrynet/core/client/StandaloneBlobDownloader.py index 5e194582d..97dc4727f 100644 --- a/lbrynet/core/client/StandaloneBlobDownloader.py +++ b/lbrynet/core/client/StandaloneBlobDownloader.py @@ -52,7 +52,8 @@ class SingleProgressManager(object): def _check_if_finished(self): if self.stream_position() == 1: 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) self.finished_callback(blob_downloaded) elif self.timeout is not None: diff --git a/lbrynet/daemon/Downloader.py b/lbrynet/daemon/Downloader.py index 988128851..a1f289894 100644 --- a/lbrynet/daemon/Downloader.py +++ b/lbrynet/daemon/Downloader.py @@ -162,9 +162,8 @@ class GetStream(object): defer.returnValue(self.download_path) @defer.inlineCallbacks - def initialize(self, stream_info, name): + def _initialize(self, 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 key_fee = None if stream_info.has_fee: @@ -179,15 +178,15 @@ class GetStream(object): defer.returnValue(downloader) @defer.inlineCallbacks - def download(self, name, key_fee): - # download sd blob, and start downloader - self.set_status(DOWNLOAD_METADATA_CODE, name) - sd_blob = yield download_sd_blob(self.session, self.sd_hash, self.payment_rate_manager, self.timeout) - self.downloader = yield self._create_downloader(sd_blob) + def _download_sd_blob(self): + sd_blob = yield download_sd_blob(self.session, self.sd_hash, + self.payment_rate_manager, self.timeout) + defer.returnValue(sd_blob) - self.set_status(DOWNLOAD_RUNNING_CODE, name) - if key_fee: - yield self.pay_key_fee(key_fee, name) + @defer.inlineCallbacks + def _download(self, sd_blob, name, key_fee): + self.downloader = yield self._create_downloader(sd_blob) + yield self.pay_key_fee(key_fee, name) log.info("Downloading lbry://%s (%s) --> %s", name, self.sd_hash[:6], self.download_path) self.finished_deferred = self.downloader.start() @@ -204,11 +203,16 @@ class GetStream(object): downloader - instance of ManagedEncryptedFileDownloader 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) + try: yield self.data_downloading_deferred except Exception as err: