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
+6 -3
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:
+11 -2
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,13 +204,17 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
:return: 下载器中符合状态的种子列表 :return: 下载器中符合状态的种子列表
""" """
# 获取下载器 # 获取下载器
if downloader:
server: Qbittorrent = self.get_instance(downloader) server: Qbittorrent = self.get_instance(downloader)
if not server: if not server:
return None return None
servers = {downloader: server}
else:
servers: Dict[str, Qbittorrent] = self.get_instances()
ret_torrents = [] ret_torrents = []
if hashs: if hashs:
# 按Hash获取 # 按Hash获取
for name, server in servers.items():
torrents, _ = server.get_torrents(ids=hashs, tags=settings.TORRENT_TAG) torrents, _ = server.get_torrents(ids=hashs, tags=settings.TORRENT_TAG)
for torrent in torrents or []: for torrent in torrents or []:
content_path = torrent.get("content_path") content_path = torrent.get("content_path")
@@ -219,6 +223,7 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
else: else:
torrent_path = Path(torrent.get('save_path')) / torrent.get('name') torrent_path = Path(torrent.get('save_path')) / torrent.get('name')
ret_torrents.append(TransferTorrent( ret_torrents.append(TransferTorrent(
downloader=name,
title=torrent.get('name'), title=torrent.get('name'),
path=torrent_path, path=torrent_path,
hash=torrent.get('hash'), hash=torrent.get('hash'),
@@ -227,6 +232,7 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
)) ))
elif status == TorrentStatus.TRANSFER: elif status == TorrentStatus.TRANSFER:
# 获取已完成且未整理的 # 获取已完成且未整理的
for name, server in servers.items():
torrents = server.get_completed_torrents(tags=settings.TORRENT_TAG) torrents = server.get_completed_torrents(tags=settings.TORRENT_TAG)
for torrent in torrents or []: for torrent in torrents or []:
tags = torrent.get("tags") or [] tags = torrent.get("tags") or []
@@ -239,6 +245,7 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
else: else:
torrent_path = torrent.get('save_path') / torrent.get('name') torrent_path = torrent.get('save_path') / torrent.get('name')
ret_torrents.append(TransferTorrent( ret_torrents.append(TransferTorrent(
downloader=name,
title=torrent.get('name'), title=torrent.get('name'),
path=torrent_path, path=torrent_path,
hash=torrent.get('hash'), hash=torrent.get('hash'),
@@ -246,10 +253,12 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
)) ))
elif status == TorrentStatus.DOWNLOADING: elif status == TorrentStatus.DOWNLOADING:
# 获取正在下载的任务 # 获取正在下载的任务
for name, server in servers.items():
torrents = server.get_downloading_torrents(tags=settings.TORRENT_TAG) torrents = server.get_downloading_torrents(tags=settings.TORRENT_TAG)
for torrent in torrents or []: for torrent in torrents or []:
meta = MetaInfo(torrent.get('name')) meta = MetaInfo(torrent.get('name'))
ret_torrents.append(DownloadingTorrent( ret_torrents.append(DownloadingTorrent(
downloader=name,
hash=torrent.get('hash'), hash=torrent.get('hash'),
title=torrent.get('name'), title=torrent.get('name'),
name=meta.name, name=meta.name,
+11 -1
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,15 +196,21 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
:return: 下载器中符合状态的种子列表 :return: 下载器中符合状态的种子列表
""" """
# 获取下载器 # 获取下载器
if downloader:
server: Transmission = self.get_instance(downloader) server: Transmission = self.get_instance(downloader)
if not server: if not server:
return None return None
servers = {downloader: server}
else:
servers: Dict[str, Transmission] = self.get_instances()
ret_torrents = [] ret_torrents = []
if hashs: if hashs:
# 按Hash获取 # 按Hash获取
for name, server in servers.items():
torrents, _ = server.get_torrents(ids=hashs, tags=settings.TORRENT_TAG) torrents, _ = server.get_torrents(ids=hashs, tags=settings.TORRENT_TAG)
for torrent in torrents or []: for torrent in torrents or []:
ret_torrents.append(TransferTorrent( ret_torrents.append(TransferTorrent(
downloader=name,
title=torrent.name, title=torrent.name,
path=Path(torrent.download_dir) / torrent.name, path=Path(torrent.download_dir) / torrent.name,
hash=torrent.hashString, hash=torrent.hashString,
@@ -213,6 +219,7 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
)) ))
elif status == TorrentStatus.TRANSFER: elif status == TorrentStatus.TRANSFER:
# 获取已完成且未整理的 # 获取已完成且未整理的
for name, server in servers.items():
torrents = server.get_completed_torrents(tags=settings.TORRENT_TAG) torrents = server.get_completed_torrents(tags=settings.TORRENT_TAG)
for torrent in torrents or []: for torrent in torrents or []:
# 含"已整理"tag的不处理 # 含"已整理"tag的不处理
@@ -225,6 +232,7 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
logger.debug(f"未获取到 {torrent.name} 下载保存路径") logger.debug(f"未获取到 {torrent.name} 下载保存路径")
continue continue
ret_torrents.append(TransferTorrent( ret_torrents.append(TransferTorrent(
downloader=name,
title=torrent.name, title=torrent.name,
path=Path(torrent.download_dir) / torrent.name, path=Path(torrent.download_dir) / torrent.name,
hash=torrent.hashString, hash=torrent.hashString,
@@ -232,12 +240,14 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
)) ))
elif status == TorrentStatus.DOWNLOADING: elif status == TorrentStatus.DOWNLOADING:
# 获取正在下载的任务 # 获取正在下载的任务
for name, server in servers.items():
torrents = server.get_downloading_torrents(tags=settings.TORRENT_TAG) torrents = server.get_downloading_torrents(tags=settings.TORRENT_TAG)
for torrent in torrents or []: for torrent in torrents or []:
meta = MetaInfo(torrent.name) meta = MetaInfo(torrent.name)
dlspeed = torrent.rate_download if hasattr(torrent, "rate_download") else torrent.rateDownload dlspeed = torrent.rate_download if hasattr(torrent, "rate_download") else torrent.rateDownload
upspeed = torrent.rate_upload if hasattr(torrent, "rate_upload") else torrent.rateUpload upspeed = torrent.rate_upload if hasattr(torrent, "rate_upload") else torrent.rateUpload
ret_torrents.append(DownloadingTorrent( ret_torrents.append(DownloadingTorrent(
downloader=name,
hash=torrent.hashString, hash=torrent.hashString,
title=torrent.name, title=torrent.name,
name=meta.name, name=meta.name,
+2
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