find and show largest file
This commit is contained in:
parent
eb9e913788
commit
9b9e55d07d
2 changed files with 22 additions and 0 deletions
lbry/torrent
|
@ -64,6 +64,19 @@ class TorrentHandle:
|
||||||
self.total_wanted_done = 0
|
self.total_wanted_done = 0
|
||||||
self.name = ''
|
self.name = ''
|
||||||
self.tasks = []
|
self.tasks = []
|
||||||
|
self.torrent_file: Optional[libtorrent.torrent_info] = None
|
||||||
|
self._base_path = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def largest_file(self) -> Optional[str]:
|
||||||
|
if not self.torrent_file:
|
||||||
|
return None
|
||||||
|
largest_size, path = 0, None
|
||||||
|
for file_num in range(self.torrent_file.num_files()):
|
||||||
|
if self.torrent_file.file_size(file_num) > largest_size:
|
||||||
|
largest_size = self.torrent_file.file_size(file_num)
|
||||||
|
path = self.torrent_file.at(file_num).path
|
||||||
|
return os.path.join(self._base_path, path)
|
||||||
|
|
||||||
def stop_tasks(self):
|
def stop_tasks(self):
|
||||||
while self.tasks:
|
while self.tasks:
|
||||||
|
@ -79,6 +92,8 @@ class TorrentHandle:
|
||||||
if not self.metadata_completed.is_set():
|
if not self.metadata_completed.is_set():
|
||||||
self.metadata_completed.set()
|
self.metadata_completed.set()
|
||||||
log.info("Metadata completed for btih:%s - %s", status.info_hash, self.name)
|
log.info("Metadata completed for btih:%s - %s", status.info_hash, self.name)
|
||||||
|
self.torrent_file = self._handle.get_torrent_info().files()
|
||||||
|
self._base_path = status.save_path
|
||||||
if not status.is_seeding:
|
if not status.is_seeding:
|
||||||
log.debug('%.2f%% complete (down: %.1f kB/s up: %.1f kB/s peers: %d seeds: %d) %s - %s',
|
log.debug('%.2f%% complete (down: %.1f kB/s up: %.1f kB/s peers: %d seeds: %d) %s - %s',
|
||||||
status.progress * 100, status.download_rate / 1000, status.upload_rate / 1000,
|
status.progress * 100, status.download_rate / 1000, status.upload_rate / 1000,
|
||||||
|
@ -178,6 +193,9 @@ class TorrentSession:
|
||||||
handle = self._handles[btih] = TorrentHandle(self._loop, self._executor, self._session.add_torrent(params))
|
handle = self._handles[btih] = TorrentHandle(self._loop, self._executor, self._session.add_torrent(params))
|
||||||
handle._handle.force_dht_announce()
|
handle._handle.force_dht_announce()
|
||||||
|
|
||||||
|
def full_path(self, btih):
|
||||||
|
return self._handles[btih].largest_file
|
||||||
|
|
||||||
async def add_torrent(self, btih, download_path):
|
async def add_torrent(self, btih, download_path):
|
||||||
await self._loop.run_in_executor(
|
await self._loop.run_in_executor(
|
||||||
self._executor, self._add_torrent, btih, download_path
|
self._executor, self._add_torrent, btih, download_path
|
||||||
|
|
|
@ -42,6 +42,10 @@ class TorrentSource(ManagedDownloadSource):
|
||||||
rowid, content_fee, analytics_manager, added_on)
|
rowid, content_fee, analytics_manager, added_on)
|
||||||
self.torrent_session = torrent_session
|
self.torrent_session = torrent_session
|
||||||
|
|
||||||
|
@property
|
||||||
|
def full_path(self) -> Optional[str]:
|
||||||
|
return self.torrent_session.full_path(self.identifier)
|
||||||
|
|
||||||
async def start(self, timeout: Optional[float] = None, save_now: Optional[bool] = False):
|
async def start(self, timeout: Optional[float] = None, save_now: Optional[bool] = False):
|
||||||
await self.torrent_session.add_torrent(self.identifier, self.download_directory)
|
await self.torrent_session.add_torrent(self.identifier, self.download_directory)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue