diff --git a/pyproject.toml b/pyproject.toml index 9d414ae..f59c4d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "torrent-telegram-bot" -version = "0.1.2" +version = "0.1.3" description = "" authors = ["Vadim Aleksandrov "] readme = "README.md" diff --git a/torrent_telegram_bot/_version.py b/torrent_telegram_bot/_version.py index b3f4756..ae73625 100644 --- a/torrent_telegram_bot/_version.py +++ b/torrent_telegram_bot/_version.py @@ -1 +1 @@ -__version__ = "0.1.2" +__version__ = "0.1.3" diff --git a/torrent_telegram_bot/bot.py b/torrent_telegram_bot/bot.py index adea77e..ddb9b3c 100755 --- a/torrent_telegram_bot/bot.py +++ b/torrent_telegram_bot/bot.py @@ -297,7 +297,7 @@ async def list_torrent_action(update, context, **kwargs): if len(torrents) > 0: try: for torrent in torrents: - if torrent.done_date == datetime.fromtimestamp(0): + if torrent.done_date is None or torrent.done_date == datetime.fromtimestamp(0): try: eta = str(torrent.eta) except ValueError: @@ -309,7 +309,7 @@ async def list_torrent_action(update, context, **kwargs): Procent: {round(torrent.progress, 2)}% Speed: {tools.humanize_bytes(torrent.download_speed)}/s ETA: {eta} - Peers: {torrent.num_seeds} + Peers: {torrent.num_seeds_download} """ ) else: @@ -317,8 +317,8 @@ async def list_torrent_action(update, context, **kwargs): f""" *{torrent.name}* Status: {torrent.status} - Speed: {tools.humanize_bytes(torrent.download_speed)}/s - Peers: {torrent.num_seeds} + Speed: {tools.humanize_bytes(torrent.upload_speed)}/s + Peers: {torrent.num_seeds_upload} Ratio: {torrent.ratio} """ ) @@ -426,12 +426,20 @@ async def check_torrent_download_status(context): # noqa: C901 await db.remove_torrent_by_id(torrent[1]) else: try: - if task is not None and task.done_date != datetime.fromtimestamp(0): + if ( + task is not None + and task.done_date is not None + and task.done_date != datetime.fromtimestamp(0) + ): await db.complete_torrent(torrent[1]) except Exception as exc: logger.error(f"{type(exc).__name__}({exc})") else: - if task is not None and task.done_date != datetime.fromtimestamp(0): + if ( + task is not None + and task.done_date is not None + and task.done_date != datetime.fromtimestamp(0) + ): response = f'Torrent "*{task.name}*" was successfully downloaded' try: notify_flag = False diff --git a/torrent_telegram_bot/custom_types.py b/torrent_telegram_bot/custom_types.py index ca3e298..b8f828a 100644 --- a/torrent_telegram_bot/custom_types.py +++ b/torrent_telegram_bot/custom_types.py @@ -11,7 +11,9 @@ def __init__( eta: datetime.timedelta | None, progress: float, download_speed: int, - num_seeds: int, + upload_speed: int, + num_seeds_download: int, + num_seeds_upload: int, ratio: float, ): self.torrent_id = torrent_id @@ -21,5 +23,7 @@ def __init__( self.eta = eta self.progress = progress self.download_speed = download_speed - self.num_seeds = num_seeds + self.upload_speed = upload_speed + self.num_seeds_download = num_seeds_download + self.num_seeds_upload = num_seeds_upload self.ratio = ratio diff --git a/torrent_telegram_bot/qbittorrent.py b/torrent_telegram_bot/qbittorrent.py index efdad80..3dc69fd 100644 --- a/torrent_telegram_bot/qbittorrent.py +++ b/torrent_telegram_bot/qbittorrent.py @@ -45,7 +45,9 @@ def get_torrents(self) -> list[Torrent]: status=torrent.state, progress=torrent.progress * 100, download_speed=torrent.dlspeed, - num_seeds=torrent.num_seeds + torrent.num_leechs, + upload_speed=torrent.upspeed, + num_seeds_download=torrent.num_seeds + torrent.num_leechs, + num_seeds_upload=torrent.num_seeds + torrent.num_leechs, ratio=torrent.ratio, ) for torrent in torrents @@ -64,7 +66,9 @@ def get_torrent(self, torrent_id: str) -> Torrent | None: status=torrent.state, progress=torrent.progress * 100, download_speed=torrent.dlspeed, - num_seeds=torrent.num_seeds + torrent.num_leechs, + upload_speed=torrent.upspeed, + num_seeds_download=torrent.num_seeds + torrent.num_leechs, + num_seeds_upload=torrent.num_seeds + torrent.num_leechs, ratio=torrent.ratio, ) @@ -105,6 +109,8 @@ def add_torrent(self, torrent_data: bytes, **kwargs) -> Torrent: status=torrent.state, progress=torrent.progress * 100, download_speed=torrent.dlspeed, - num_seeds=torrent.num_seeds + torrent.num_leechs, + upload_speed=torrent.upspeed, + num_seeds_download=torrent.num_seeds + torrent.num_leechs, + num_seeds_upload=torrent.num_seeds + torrent.num_leechs, ratio=torrent.ratio, ) diff --git a/torrent_telegram_bot/transmission.py b/torrent_telegram_bot/transmission.py index c7b3060..452135d 100644 --- a/torrent_telegram_bot/transmission.py +++ b/torrent_telegram_bot/transmission.py @@ -35,8 +35,10 @@ def get_torrents(self) -> list[Torrent]: status=torrent.status, progress=torrent.progress, download_speed=torrent.rate_download, - num_seeds=torrent.peers_sending_to_us, - ratio=torrent.rate_download, + upload_speed=torrent.rate_upload, + num_seeds_download=torrent.peers_sending_to_us, + num_seeds_upload=torrent.peers_getting_from_us, + ratio=torrent.ratio, ) for torrent in torrents ] @@ -52,8 +54,10 @@ def get_torrent(self, torrent_id: str) -> Torrent | None: status=torrent.status, progress=torrent.progress, download_speed=torrent.rate_download, - num_seeds=torrent.peers_sending_to_us, - ratio=torrent.rate_download, + upload_speed=torrent.rate_upload, + num_seeds_download=torrent.peers_sending_to_us, + num_seeds_upload=torrent.peers_getting_from_us, + ratio=torrent.ratio, ) def remove_torrent(self, torrent_id: str, delete_data: bool = True): @@ -64,27 +68,18 @@ def add_torrent(self, torrent_data: bytes, **kwargs) -> Torrent: """Add torrent to client""" if "download_dir" in kwargs: torrent = self.client.add_torrent(torrent=torrent_data, download_dir=kwargs.get("download_dir")) - return Torrent( - torrent_id=str(torrent.id), - name=torrent.name, - done_date=torrent.done_date, - eta=torrent.eta, - status=torrent.status, - progress=torrent.progress, - download_speed=torrent.rate_download, - num_seeds=torrent.peers_sending_to_us, - ratio=torrent.rate_download, - ) else: torrent = self.client.add_torrent(torrent=torrent_data) - return Torrent( - torrent_id=str(torrent.id), - name=torrent.name, - done_date=torrent.done_date, - eta=torrent.eta, - status=torrent.status, - progress=torrent.progress, - download_speed=torrent.rate_download, - num_seeds=torrent.peers_sending_to_us, - ratio=torrent.rate_download, - ) + return Torrent( + torrent_id=str(torrent.id), + name=torrent.name, + done_date=None, + eta=None, + status="", + progress=0, + download_speed=0, + upload_speed=0, + num_seeds_download=0, + num_seeds_upload=0, + ratio=0, + )