diff --git a/lbrynet/stream/stream_manager.py b/lbrynet/stream/stream_manager.py index ced6a303c..436620fa4 100644 --- a/lbrynet/stream/stream_manager.py +++ b/lbrynet/stream/stream_manager.py @@ -302,18 +302,8 @@ class StreamManager: downloader.stop() log.info("stopped stream") raise DownloadSDTimeout(downloader.sd_hash) - file_name = os.path.basename(downloader.output_path) - download_directory = os.path.dirname(downloader.output_path) - if not await self.blob_manager.storage.stream_exists(downloader.sd_hash): - await self.blob_manager.storage.store_stream(downloader.sd_blob, downloader.descriptor) - if not await self.blob_manager.storage.file_exists(downloader.sd_hash): - rowid = await self.blob_manager.storage.save_downloaded_file( - downloader.descriptor.stream_hash, file_name, download_directory, - 0.0 - ) - else: - rowid = self.blob_manager.storage.rowid_for_stream(downloader.descriptor.stream_hash) - await self.blob_manager.storage.save_content_claim( + rowid = await self._store_stream(downloader) + await self.storage.save_content_claim( downloader.descriptor.stream_hash, f"{claim_info['txid']}:{claim_info['nout']}" ) stream = ManagedStream(self.loop, self.blob_manager, rowid, downloader.descriptor, download_directory, @@ -330,6 +320,19 @@ class StreamManager: await self.stop_stream(stream) raise DownloadDataTimeout(downloader.sd_hash) + async def _store_stream(self, downloader: StreamDownloader) -> int: + file_name = os.path.basename(downloader.output_path) + download_directory = os.path.dirname(downloader.output_path) + if not await self.storage.stream_exists(downloader.sd_hash): + await self.storage.store_stream(downloader.sd_blob, downloader.descriptor) + if not await self.storage.file_exists(downloader.sd_hash): + return await self.storage.save_downloaded_file( + downloader.descriptor.stream_hash, file_name, download_directory, + 0.0 + ) + else: + return await self.storage.rowid_for_stream(downloader.descriptor.stream_hash) + async def download_stream_from_claim(self, node: 'Node', claim_info: typing.Dict, file_name: typing.Optional[str] = None, timeout: typing.Optional[float] = 60,