From e8178a1f554a5ab32a4aab1cc51353d2273bbe4c Mon Sep 17 00:00:00 2001 From: jxxghp Date: Tue, 6 Jun 2023 10:58:57 +0800 Subject: [PATCH] fix list_torrents --- app/modules/__init__.py | 6 +++--- app/modules/qbittorrent/__init__.py | 25 ++++++++++++++++++++++++- app/modules/transmission/__init__.py | 25 ++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/app/modules/__init__.py b/app/modules/__init__.py index a3caddd4..a02af147 100644 --- a/app/modules/__init__.py +++ b/app/modules/__init__.py @@ -131,7 +131,7 @@ class _ModuleBase(metaclass=ABCMeta): """ pass - def list_torrents(self, status: TorrentStatus) -> List[dict]: + def list_torrents(self, status: TorrentStatus) -> Optional[List[dict]]: """ 获取下载器种子列表 :param status: 种子状态 @@ -139,10 +139,10 @@ class _ModuleBase(metaclass=ABCMeta): """ pass - def remove_torrents(self, status: Union[str, list]) -> bool: + def remove_torrents(self, hashs: Union[str, list]) -> bool: """ 删除下载器种子 - :param status: 种子状态 + :param hashs: 种子Hash :return: bool """ pass diff --git a/app/modules/qbittorrent/__init__.py b/app/modules/qbittorrent/__init__.py index e66121cc..e66042db 100644 --- a/app/modules/qbittorrent/__init__.py +++ b/app/modules/qbittorrent/__init__.py @@ -1,10 +1,11 @@ from pathlib import Path -from typing import Set, Tuple, Optional, Union +from typing import Set, Tuple, Optional, Union, List from app.core import settings, MetaInfo from app.modules import _ModuleBase from app.modules.qbittorrent.qbittorrent import Qbittorrent from app.utils.string import StringUtils +from app.utils.types import TorrentStatus class QbittorrentModule(_ModuleBase): @@ -73,3 +74,25 @@ class QbittorrentModule(_ModuleBase): return torrent_hash, f"添加下载成功,已选择集数:{sucess_epidised}" else: return torrent_hash, "添加下载成功" + + def list_torrents(self, status: TorrentStatus) -> Optional[List[dict]]: + """ + 获取下载器种子列表 + :param status: 种子状态 + :return: 下载器中符合状态的种子列表 + """ + if status == TorrentStatus.COMPLETE: + torrents = self.qbittorrent.get_completed_torrents() + elif status == TorrentStatus.DOWNLOADING: + torrents = self.qbittorrent.get_downloading_torrents() + else: + return None + return torrents + + def remove_torrents(self, hashs: Union[str, list]) -> bool: + """ + 删除下载器种子 + :param hashs: 种子Hash + :return: bool + """ + return self.qbittorrent.delete_torrents(delete_file=True, ids=hashs) diff --git a/app/modules/transmission/__init__.py b/app/modules/transmission/__init__.py index d329cd56..c8a68ad7 100644 --- a/app/modules/transmission/__init__.py +++ b/app/modules/transmission/__init__.py @@ -1,9 +1,10 @@ from pathlib import Path -from typing import Set, Tuple, Optional, Union +from typing import Set, Tuple, Optional, Union, List from app.core import settings, MetaInfo from app.modules import _ModuleBase from app.modules.transmission.transmission import Transmission +from app.utils.types import TorrentStatus class TransmissionModule(_ModuleBase): @@ -68,3 +69,25 @@ class TransmissionModule(_ModuleBase): self.transmission.start_torrents(torrent_hash) else: return torrent_hash, "添加下载任务成功" + + def list_torrents(self, status: TorrentStatus) -> Optional[List[dict]]: + """ + 获取下载器种子列表 + :param status: 种子状态 + :return: 下载器中符合状态的种子列表 + """ + if status == TorrentStatus.COMPLETE: + torrents = self.transmission.get_completed_torrents() + elif status == TorrentStatus.DOWNLOADING: + torrents = self.transmission.get_completed_torrents() + else: + return None + return torrents + + def remove_torrents(self, hashs: Union[str, list]) -> bool: + """ + 删除下载器种子 + :param hashs: 种子Hash + :return: bool + """ + return self.transmission.delete_torrents(delete_file=True, ids=hashs)