This commit is contained in:
jxxghp
2024-11-23 11:48:23 +08:00
parent 0afbc58263
commit 0feecc3eca
4 changed files with 129 additions and 105 deletions

View File

@@ -131,6 +131,7 @@ class TransferChain(ChainBase):
extension=file_path.suffix.lstrip('.'), extension=file_path.suffix.lstrip('.'),
), ),
mediainfo=mediainfo, mediainfo=mediainfo,
downloader=torrent.downloader,
download_hash=torrent.hash, download_hash=torrent.hash,
src_match=True src_match=True
) )
@@ -149,8 +150,8 @@ class TransferChain(ChainBase):
target_storage: str = None, target_path: Path = None, target_storage: str = None, target_path: Path = None,
transfer_type: str = None, scrape: bool = None, transfer_type: str = None, scrape: bool = None,
library_type_folder: bool = False, library_category_folder: bool = False, library_type_folder: bool = False, library_category_folder: bool = False,
season: int = None, epformat: EpisodeFormat = None, season: int = None, epformat: EpisodeFormat = None, min_filesize: int = 0,
min_filesize: int = 0, download_hash: str = None, downloader: str = None, download_hash: str = None,
force: bool = False, src_match: bool = False) -> Tuple[bool, str]: force: bool = False, src_match: bool = False) -> Tuple[bool, str]:
""" """
执行一个复杂目录的整理操作 执行一个复杂目录的整理操作
@@ -167,6 +168,7 @@ class TransferChain(ChainBase):
:param season: 季 :param season: 季
:param epformat: 剧集格式 :param epformat: 剧集格式
:param min_filesize: 最小文件大小(MB) :param min_filesize: 最小文件大小(MB)
:param downloader: 下载器
:param download_hash: 下载记录hash :param download_hash: 下载记录hash
:param force: 是否强制整理 :param force: 是否强制整理
:param src_match: 是否源目录匹配 :param src_match: 是否源目录匹配
@@ -478,6 +480,7 @@ class TransferChain(ChainBase):
'meta': file_meta, 'meta': file_meta,
'mediainfo': file_mediainfo, 'mediainfo': file_mediainfo,
'transferinfo': transferinfo, 'transferinfo': transferinfo,
'downloader': downloader,
'download_hash': download_hash, 'download_hash': download_hash,
}) })
@@ -517,7 +520,7 @@ class TransferChain(ChainBase):
if all_success and current_transfer_type in ["move"]: if all_success and current_transfer_type in ["move"]:
# 下载器hash # 下载器hash
if download_hash: if download_hash:
if self.remove_torrents(download_hash): if self.remove_torrents(download_hash, downloader=downloader):
logger.info(f"移动模式删除种子成功:{download_hash} ") logger.info(f"移动模式删除种子成功:{download_hash} ")
# 删除残留目录 # 删除残留目录
if fileitem: if fileitem:

View File

@@ -1,5 +1,5 @@
from pathlib import Path from pathlib import Path
from typing import Set, Tuple, Optional, Union, List from typing import Set, Tuple, Optional, Union, List, Dict
from qbittorrentapi import TorrentFilesList from qbittorrentapi import TorrentFilesList
from torrentool.torrent import Torrent from torrentool.torrent import Torrent
@@ -204,66 +204,75 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
:return: 下载器中符合状态的种子列表 :return: 下载器中符合状态的种子列表
""" """
# 获取下载器 # 获取下载器
server: Qbittorrent = self.get_instance(downloader) if downloader:
if not server: server: Qbittorrent = self.get_instance(downloader)
return None if not server:
return None
servers = {downloader: server}
else:
servers: Dict[str, Qbittorrent] = self.get_instances()
ret_torrents = [] ret_torrents = []
if hashs: if hashs:
# 按Hash获取 # 按Hash获取
torrents, _ = server.get_torrents(ids=hashs, tags=settings.TORRENT_TAG) for name, server in servers.items():
for torrent in torrents or []: torrents, _ = server.get_torrents(ids=hashs, tags=settings.TORRENT_TAG)
content_path = torrent.get("content_path") for torrent in torrents or []:
if content_path: content_path = torrent.get("content_path")
torrent_path = Path(content_path) if content_path:
else: torrent_path = Path(content_path)
torrent_path = Path(torrent.get('save_path')) / torrent.get('name') else:
ret_torrents.append(TransferTorrent( torrent_path = Path(torrent.get('save_path')) / torrent.get('name')
title=torrent.get('name'), ret_torrents.append(TransferTorrent(
path=torrent_path, downloader=name,
hash=torrent.get('hash'), title=torrent.get('name'),
size=torrent.get('total_size'), path=torrent_path,
tags=torrent.get('tags') hash=torrent.get('hash'),
)) size=torrent.get('total_size'),
tags=torrent.get('tags')
))
elif status == TorrentStatus.TRANSFER: elif status == TorrentStatus.TRANSFER:
# 获取已完成且未整理的 # 获取已完成且未整理的
torrents = server.get_completed_torrents(tags=settings.TORRENT_TAG) for name, server in servers.items():
for torrent in torrents or []: torrents = server.get_completed_torrents(tags=settings.TORRENT_TAG)
tags = torrent.get("tags") or [] for torrent in torrents or []:
if "已整理" in tags: tags = torrent.get("tags") or []
continue if "已整理" in tags:
# 内容路径 continue
content_path = torrent.get("content_path") # 内容路径
if content_path: content_path = torrent.get("content_path")
torrent_path = Path(content_path) if content_path:
else: torrent_path = Path(content_path)
torrent_path = torrent.get('save_path') / torrent.get('name') else:
ret_torrents.append(TransferTorrent( torrent_path = torrent.get('save_path') / torrent.get('name')
title=torrent.get('name'), ret_torrents.append(TransferTorrent(
path=torrent_path, downloader=name,
hash=torrent.get('hash'), title=torrent.get('name'),
tags=torrent.get('tags') path=torrent_path,
)) hash=torrent.get('hash'),
tags=torrent.get('tags')
))
elif status == TorrentStatus.DOWNLOADING: elif status == TorrentStatus.DOWNLOADING:
# 获取正在下载的任务 # 获取正在下载的任务
torrents = server.get_downloading_torrents(tags=settings.TORRENT_TAG) for name, server in servers.items():
for torrent in torrents or []: torrents = server.get_downloading_torrents(tags=settings.TORRENT_TAG)
meta = MetaInfo(torrent.get('name')) for torrent in torrents or []:
ret_torrents.append(DownloadingTorrent( meta = MetaInfo(torrent.get('name'))
hash=torrent.get('hash'), ret_torrents.append(DownloadingTorrent(
title=torrent.get('name'), downloader=name,
name=meta.name, hash=torrent.get('hash'),
year=meta.year, title=torrent.get('name'),
season_episode=meta.season_episode, name=meta.name,
progress=torrent.get('progress') * 100, year=meta.year,
size=torrent.get('total_size'), season_episode=meta.season_episode,
state="paused" if torrent.get('state') in ("paused", "pausedDL") else "downloading", progress=torrent.get('progress') * 100,
dlspeed=StringUtils.str_filesize(torrent.get('dlspeed')), size=torrent.get('total_size'),
upspeed=StringUtils.str_filesize(torrent.get('upspeed')), state="paused" if torrent.get('state') in ("paused", "pausedDL") else "downloading",
left_time=StringUtils.str_secends( dlspeed=StringUtils.str_filesize(torrent.get('dlspeed')),
(torrent.get('total_size') - torrent.get('completed')) / torrent.get('dlspeed')) if torrent.get( upspeed=StringUtils.str_filesize(torrent.get('upspeed')),
'dlspeed') > 0 else '' left_time=StringUtils.str_secends(
)) (torrent.get('total_size') - torrent.get('completed')) / torrent.get('dlspeed')) if torrent.get(
'dlspeed') > 0 else ''
))
else: else:
return None return None
return ret_torrents return ret_torrents

View File

@@ -1,5 +1,5 @@
from pathlib import Path from pathlib import Path
from typing import Set, Tuple, Optional, Union, List from typing import Set, Tuple, Optional, Union, List, Dict
from torrentool.torrent import Torrent from torrentool.torrent import Torrent
from transmission_rpc import File from transmission_rpc import File
@@ -196,60 +196,70 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
:return: 下载器中符合状态的种子列表 :return: 下载器中符合状态的种子列表
""" """
# 获取下载器 # 获取下载器
server: Transmission = self.get_instance(downloader) if downloader:
if not server: server: Transmission = self.get_instance(downloader)
return None if not server:
return None
servers = {downloader: server}
else:
servers: Dict[str, Transmission] = self.get_instances()
ret_torrents = [] ret_torrents = []
if hashs: if hashs:
# 按Hash获取 # 按Hash获取
torrents, _ = server.get_torrents(ids=hashs, tags=settings.TORRENT_TAG) for name, server in servers.items():
for torrent in torrents or []: torrents, _ = server.get_torrents(ids=hashs, tags=settings.TORRENT_TAG)
ret_torrents.append(TransferTorrent( for torrent in torrents or []:
title=torrent.name, ret_torrents.append(TransferTorrent(
path=Path(torrent.download_dir) / torrent.name, downloader=name,
hash=torrent.hashString, title=torrent.name,
size=torrent.total_size, path=Path(torrent.download_dir) / torrent.name,
tags=",".join(torrent.labels or []) hash=torrent.hashString,
)) size=torrent.total_size,
tags=",".join(torrent.labels or [])
))
elif status == TorrentStatus.TRANSFER: elif status == TorrentStatus.TRANSFER:
# 获取已完成且未整理的 # 获取已完成且未整理的
torrents = server.get_completed_torrents(tags=settings.TORRENT_TAG) for name, server in servers.items():
for torrent in torrents or []: torrents = server.get_completed_torrents(tags=settings.TORRENT_TAG)
# 含"已整理"tag的不处理 for torrent in torrents or []:
if "已整理" in torrent.labels or []: # 含"已整理"tag的不处理
continue if "已整理" in torrent.labels or []:
# 下载路径 continue
path = torrent.download_dir # 下载路径
# 无法获取下载路径的不处理 path = torrent.download_dir
if not path: # 无法获取下载路径的不处理
logger.debug(f"未获取到 {torrent.name} 下载保存路径") if not path:
continue logger.debug(f"未获取到 {torrent.name} 下载保存路径")
ret_torrents.append(TransferTorrent( continue
title=torrent.name, ret_torrents.append(TransferTorrent(
path=Path(torrent.download_dir) / torrent.name, downloader=name,
hash=torrent.hashString, title=torrent.name,
tags=",".join(torrent.labels or []) path=Path(torrent.download_dir) / torrent.name,
)) hash=torrent.hashString,
tags=",".join(torrent.labels or [])
))
elif status == TorrentStatus.DOWNLOADING: elif status == TorrentStatus.DOWNLOADING:
# 获取正在下载的任务 # 获取正在下载的任务
torrents = server.get_downloading_torrents(tags=settings.TORRENT_TAG) for name, server in servers.items():
for torrent in torrents or []: torrents = server.get_downloading_torrents(tags=settings.TORRENT_TAG)
meta = MetaInfo(torrent.name) for torrent in torrents or []:
dlspeed = torrent.rate_download if hasattr(torrent, "rate_download") else torrent.rateDownload meta = MetaInfo(torrent.name)
upspeed = torrent.rate_upload if hasattr(torrent, "rate_upload") else torrent.rateUpload dlspeed = torrent.rate_download if hasattr(torrent, "rate_download") else torrent.rateDownload
ret_torrents.append(DownloadingTorrent( upspeed = torrent.rate_upload if hasattr(torrent, "rate_upload") else torrent.rateUpload
hash=torrent.hashString, ret_torrents.append(DownloadingTorrent(
title=torrent.name, downloader=name,
name=meta.name, hash=torrent.hashString,
year=meta.year, title=torrent.name,
season_episode=meta.season_episode, name=meta.name,
progress=torrent.progress, year=meta.year,
size=torrent.total_size, season_episode=meta.season_episode,
state="paused" if torrent.status == "stopped" else "downloading", progress=torrent.progress,
dlspeed=StringUtils.str_filesize(dlspeed), size=torrent.total_size,
upspeed=StringUtils.str_filesize(upspeed), state="paused" if torrent.status == "stopped" else "downloading",
left_time=StringUtils.str_secends(torrent.left_until_done / dlspeed) if dlspeed > 0 else '' dlspeed=StringUtils.str_filesize(dlspeed),
)) upspeed=StringUtils.str_filesize(upspeed),
left_time=StringUtils.str_secends(torrent.left_until_done / dlspeed) if dlspeed > 0 else ''
))
else: else:
return None return None
return ret_torrents return ret_torrents

View File

@@ -10,6 +10,7 @@ class TransferTorrent(BaseModel):
""" """
待转移任务信息 待转移任务信息
""" """
downloader: Optional[str] = None
title: Optional[str] = None title: Optional[str] = None
path: Optional[Path] = None path: Optional[Path] = None
hash: Optional[str] = None hash: Optional[str] = None
@@ -22,6 +23,7 @@ class DownloadingTorrent(BaseModel):
""" """
下载中任务信息 下载中任务信息
""" """
downloader: Optional[str] = None
hash: Optional[str] = None hash: Optional[str] = None
title: Optional[str] = None title: Optional[str] = None
name: Optional[str] = None name: Optional[str] = None