From 9c9c0e6c09bfb316da521b1d4e2798490f7d4285 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Fri, 8 Nov 2024 18:24:06 -0300 Subject: [PATCH] feat: seed after doenload --- torrent-client/torrent_downloader.py | 30 ++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/torrent-client/torrent_downloader.py b/torrent-client/torrent_downloader.py index b5280260..a098f7db 100644 --- a/torrent-client/torrent_downloader.py +++ b/torrent-client/torrent_downloader.py @@ -158,8 +158,34 @@ class TorrentDownloader: } if status.progress == 1: - torrent_handle.pause() - self.session.remove_torrent(torrent_handle) self.downloading_game_id = -1 return response + + def get_seed_status(self): + response = [] + + for game_id, torrent_handle in self.torrent_handles.items(): + if game_id == self.downloading_game_id: + continue + + status = torrent_handle.status() + info = torrent_handle.torrent_file() + + torrent_info = { + 'folderName': info.name() if info else "", + 'fileSize': info.total_size() if info else 0, + 'gameId': game_id, + 'progress': status.progress, + 'downloadSpeed': status.download_rate, + 'uploadSpeed': status.upload_rate, + 'numPeers': status.num_peers, + 'numSeeds': status.num_seeds, + 'status': status.state, + 'bytesDownloaded': status.progress * info.total_size() if info else status.all_time_download, + } + + if status.state == 5: + response.append(torrent_info) + + return response