feat:下载器支持多选
This commit is contained in:
@ -48,7 +48,8 @@ class TransmissionModule(_ModuleBase):
|
||||
self.transmission.reconnect()
|
||||
|
||||
def download(self, content: Union[Path, str], download_dir: Path, cookie: str,
|
||||
episodes: Set[int] = None, category: str = None) -> Optional[Tuple[Optional[str], str]]:
|
||||
episodes: Set[int] = None, category: str = None,
|
||||
downloader: str = settings.DEFAULT_DOWNLOADER) -> Optional[Tuple[Optional[str], str]]:
|
||||
"""
|
||||
根据种子文件,选择并添加下载任务
|
||||
:param content: 种子文件地址或者磁力链接
|
||||
@ -56,6 +57,7 @@ class TransmissionModule(_ModuleBase):
|
||||
:param cookie: cookie
|
||||
:param episodes: 需要下载的集数
|
||||
:param category: 分类,TR中未使用
|
||||
:param downloader: 下载器
|
||||
:return: 种子Hash
|
||||
"""
|
||||
|
||||
@ -74,7 +76,7 @@ class TransmissionModule(_ModuleBase):
|
||||
return "", 0
|
||||
|
||||
# 不是默认下载器不处理
|
||||
if settings.DEFAULT_DOWNLOADER != "transmission":
|
||||
if downloader != "transmission":
|
||||
return None
|
||||
|
||||
if not content:
|
||||
@ -158,13 +160,18 @@ class TransmissionModule(_ModuleBase):
|
||||
return torrent_hash, "添加下载任务成功"
|
||||
|
||||
def list_torrents(self, status: TorrentStatus = None,
|
||||
hashs: Union[list, str] = None) -> Optional[List[Union[TransferTorrent, DownloadingTorrent]]]:
|
||||
hashs: Union[list, str] = None,
|
||||
downloader: str = settings.DEFAULT_DOWNLOADER
|
||||
) -> Optional[List[Union[TransferTorrent, DownloadingTorrent]]]:
|
||||
"""
|
||||
获取下载器种子列表
|
||||
:param status: 种子状态
|
||||
:param hashs: 种子Hash
|
||||
:param downloader: 下载器
|
||||
:return: 下载器中符合状态的种子列表
|
||||
"""
|
||||
if downloader != "transmission":
|
||||
return None
|
||||
ret_torrents = []
|
||||
if hashs:
|
||||
# 按Hash获取
|
||||
@ -219,14 +226,17 @@ class TransmissionModule(_ModuleBase):
|
||||
return None
|
||||
return ret_torrents
|
||||
|
||||
def transfer_completed(self, hashs: Union[str, list],
|
||||
path: Path = None) -> None:
|
||||
def transfer_completed(self, hashs: Union[str, list], path: Path = None,
|
||||
downloader: str = settings.DEFAULT_DOWNLOADER) -> None:
|
||||
"""
|
||||
转移完成后的处理
|
||||
:param hashs: 种子Hash
|
||||
:param path: 源目录
|
||||
:param downloader: 下载器
|
||||
:return: None
|
||||
"""
|
||||
if downloader != "transmission":
|
||||
return None
|
||||
self.transmission.set_torrent_tag(ids=hashs, tags=['已整理'])
|
||||
# 移动模式删除种子
|
||||
if settings.TRANSFER_TYPE == "move":
|
||||
@ -239,47 +249,61 @@ class TransmissionModule(_ModuleBase):
|
||||
logger.warn(f"删除残留文件夹:{path}")
|
||||
shutil.rmtree(path, ignore_errors=True)
|
||||
|
||||
def remove_torrents(self, hashs: Union[str, list], delete_file: bool = True) -> bool:
|
||||
def remove_torrents(self, hashs: Union[str, list], delete_file: bool = True,
|
||||
downloader: str = settings.DEFAULT_DOWNLOADER) -> Optional[bool]:
|
||||
"""
|
||||
删除下载器种子
|
||||
:param hashs: 种子Hash
|
||||
:param delete_file: 是否删除文件
|
||||
:param downloader: 下载器
|
||||
:return: bool
|
||||
"""
|
||||
if downloader != "transmission":
|
||||
return None
|
||||
return self.transmission.delete_torrents(delete_file=delete_file, ids=hashs)
|
||||
|
||||
def start_torrents(self, hashs: Union[list, str]) -> bool:
|
||||
def start_torrents(self, hashs: Union[list, str],
|
||||
downloader: str = settings.DEFAULT_DOWNLOADER) -> Optional[bool]:
|
||||
"""
|
||||
开始下载
|
||||
:param hashs: 种子Hash
|
||||
:param downloader: 下载器
|
||||
:return: bool
|
||||
"""
|
||||
if downloader != "transmission":
|
||||
return None
|
||||
return self.transmission.start_torrents(ids=hashs)
|
||||
|
||||
def stop_torrents(self, hashs: Union[list, str]) -> bool:
|
||||
def stop_torrents(self, hashs: Union[list, str],
|
||||
downloader: str = settings.DEFAULT_DOWNLOADER) -> Optional[bool]:
|
||||
"""
|
||||
停止下载
|
||||
:param hashs: 种子Hash
|
||||
:param downloader: 下载器
|
||||
:return: bool
|
||||
"""
|
||||
if downloader != "transmission":
|
||||
return None
|
||||
return self.transmission.start_torrents(ids=hashs)
|
||||
|
||||
def torrent_files(self, tid: str) -> Optional[List[File]]:
|
||||
def torrent_files(self, tid: str, downloader: str = settings.DEFAULT_DOWNLOADER) -> Optional[List[File]]:
|
||||
"""
|
||||
获取种子文件列表
|
||||
"""
|
||||
if downloader != "transmission":
|
||||
return None
|
||||
return self.transmission.get_files(tid=tid)
|
||||
|
||||
def downloader_info(self) -> schemas.DownloaderInfo:
|
||||
def downloader_info(self) -> [schemas.DownloaderInfo]:
|
||||
"""
|
||||
下载器信息
|
||||
"""
|
||||
info = self.transmission.transfer_info()
|
||||
if not info:
|
||||
return schemas.DownloaderInfo()
|
||||
return schemas.DownloaderInfo(
|
||||
return [schemas.DownloaderInfo()]
|
||||
return [schemas.DownloaderInfo(
|
||||
download_speed=info.download_speed,
|
||||
upload_speed=info.upload_speed,
|
||||
download_size=info.current_stats.downloaded_bytes,
|
||||
upload_size=info.current_stats.uploaded_bytes
|
||||
)
|
||||
)]
|
||||
|
Reference in New Issue
Block a user