From f145d08c10d7c29f682edb78f9af6b4895629819 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 28 Feb 2020 15:22:57 -0300 Subject: [PATCH] tell progress, stop trying to read first piece --- lbry/extras/daemon/json_response_encoder.py | 6 +++--- lbry/torrent/session.py | 5 +---- lbry/torrent/torrent_manager.py | 4 ++++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lbry/extras/daemon/json_response_encoder.py b/lbry/extras/daemon/json_response_encoder.py index 6bb1ed0b2..fcffb0d29 100644 --- a/lbry/extras/daemon/json_response_encoder.py +++ b/lbry/extras/daemon/json_response_encoder.py @@ -291,9 +291,9 @@ class JSONResponseEncoder(JSONEncoder): 'sd_hash': managed_stream.descriptor.sd_hash if is_stream else None, 'mime_type': managed_stream.mime_type if is_stream else None, 'key': managed_stream.descriptor.key if is_stream else None, - 'total_bytes_lower_bound': managed_stream.descriptor.lower_bound_decrypted_length() if is_stream else None, - 'total_bytes': managed_stream.descriptor.upper_bound_decrypted_length() if is_stream else None, - 'written_bytes': managed_stream.written_bytes if is_stream else None, + 'total_bytes_lower_bound': managed_stream.descriptor.lower_bound_decrypted_length() if is_stream else managed_stream.torrent_length, + 'total_bytes': managed_stream.descriptor.upper_bound_decrypted_length() if is_stream else managed_stream.torrent_length, + 'written_bytes': managed_stream.written_bytes if is_stream else managed_stream.written_bytes, 'blobs_completed': managed_stream.blobs_completed if is_stream else None, 'blobs_in_stream': managed_stream.blobs_in_stream if is_stream else None, 'blobs_remaining': managed_stream.blobs_remaining if is_stream else None, diff --git a/lbry/torrent/session.py b/lbry/torrent/session.py index b4b47bcdb..feff53f75 100644 --- a/lbry/torrent/session.py +++ b/lbry/torrent/session.py @@ -40,8 +40,6 @@ log = logging.getLogger(__name__) DEFAULT_FLAGS = ( # fixme: somehow the logic here is inverted? libtorrent.add_torrent_params_flags_t.flag_auto_managed - | libtorrent.add_torrent_params_flags_t.flag_paused - | libtorrent.add_torrent_params_flags_t.flag_duplicate_is_error | libtorrent.add_torrent_params_flags_t.flag_update_subscribe ) @@ -104,7 +102,6 @@ class TorrentHandle: self.torrent_file = self._handle.get_torrent_info().files() self._base_path = status.save_path first_piece = self.torrent_file.at(self.largest_file_index).offset - self._handle.read_piece(first_piece) if not self.started.is_set(): if self._handle.have_piece(first_piece): self.started.set() @@ -205,7 +202,7 @@ class TorrentSession: ) def _add_torrent(self, btih: str, download_directory: Optional[str]): - params = {'info_hash': binascii.unhexlify(btih.encode())} + params = {'info_hash': binascii.unhexlify(btih.encode()), 'flags': DEFAULT_FLAGS} if download_directory: params['save_path'] = download_directory handle = self._session.add_torrent(params) diff --git a/lbry/torrent/torrent_manager.py b/lbry/torrent/torrent_manager.py index a2e1edbe4..cf9106731 100644 --- a/lbry/torrent/torrent_manager.py +++ b/lbry/torrent/torrent_manager.py @@ -62,6 +62,10 @@ class TorrentSource(ManagedDownloadSource): def torrent_length(self): return self.torrent_session.get_size(self.identifier) + @property + def written_bytes(self): + return self.torrent_session.get_downloaded(self.identifier) + @property def torrent_name(self): return self.torrent_session.get_name(self.identifier)