mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
fix transfer_completed
This commit is contained in:
@@ -402,14 +402,16 @@ class ChainBase(metaclass=ABCMeta):
|
|||||||
target_path=target_path, episodes_info=episodes_info, scrape=scrape)
|
target_path=target_path, episodes_info=episodes_info, scrape=scrape)
|
||||||
|
|
||||||
def transfer_completed(self, hashs: str, path: Path = None,
|
def transfer_completed(self, hashs: str, path: Path = None,
|
||||||
downloader: str = None) -> None:
|
downloader: str = None, transfer_type: str = None) -> None:
|
||||||
"""
|
"""
|
||||||
转移完成后的处理
|
转移完成后的处理
|
||||||
:param hashs: 种子Hash
|
:param hashs: 种子Hash
|
||||||
:param path: 源目录
|
:param path: 源目录
|
||||||
:param downloader: 下载器
|
:param downloader: 下载器
|
||||||
|
:param transfer_type: 整理方式
|
||||||
"""
|
"""
|
||||||
return self.run_module("transfer_completed", hashs=hashs, path=path, downloader=downloader)
|
return self.run_module("transfer_completed", hashs=hashs, path=path,
|
||||||
|
downloader=downloader, transfer_type=transfer_type)
|
||||||
|
|
||||||
def remove_torrents(self, hashs: Union[str, list], delete_file: bool = True,
|
def remove_torrents(self, hashs: Union[str, list], delete_file: bool = True,
|
||||||
downloader: str = None) -> bool:
|
downloader: str = None) -> bool:
|
||||||
|
|||||||
@@ -68,11 +68,13 @@ class TransferChain(ChainBase):
|
|||||||
# 如果没有下载器监控的目录则不处理
|
# 如果没有下载器监控的目录则不处理
|
||||||
downloader_monitor = False
|
downloader_monitor = False
|
||||||
for dir_info in download_dirs:
|
for dir_info in download_dirs:
|
||||||
if dir_info.monitor_type == "downloader":
|
# 只有下载器监控的本地目录才处理
|
||||||
|
if dir_info.monitor_type == "downloader" and dir_info.storage == "local":
|
||||||
downloader_monitor = True
|
downloader_monitor = True
|
||||||
break
|
break
|
||||||
if not downloader_monitor:
|
if not downloader_monitor:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
logger.info("开始整理下载器中已经完成下载的文件 ...")
|
logger.info("开始整理下载器中已经完成下载的文件 ...")
|
||||||
# 从下载器获取种子列表
|
# 从下载器获取种子列表
|
||||||
torrents: Optional[List[TransferTorrent]] = self.list_torrents(status=TorrentStatus.TRANSFER)
|
torrents: Optional[List[TransferTorrent]] = self.list_torrents(status=TorrentStatus.TRANSFER)
|
||||||
@@ -82,8 +84,6 @@ class TransferChain(ChainBase):
|
|||||||
|
|
||||||
logger.info(f"获取到 {len(torrents)} 个已完成的下载任务")
|
logger.info(f"获取到 {len(torrents)} 个已完成的下载任务")
|
||||||
|
|
||||||
# 检查是否为下载器监控目录中的文件
|
|
||||||
need_handle = False
|
|
||||||
for torrent in torrents:
|
for torrent in torrents:
|
||||||
# 文件路径
|
# 文件路径
|
||||||
file_path = Path(torrent.path)
|
file_path = Path(torrent.path)
|
||||||
@@ -91,15 +91,16 @@ class TransferChain(ChainBase):
|
|||||||
logger.warn(f"文件不存在:{file_path}")
|
logger.warn(f"文件不存在:{file_path}")
|
||||||
continue
|
continue
|
||||||
# 检查是否为下载器监控目录中的文件
|
# 检查是否为下载器监控目录中的文件
|
||||||
|
transfer_dirinfo = None
|
||||||
for dir_info in download_dirs:
|
for dir_info in download_dirs:
|
||||||
if dir_info.monitor_type != "downloader":
|
if dir_info.monitor_type != "downloader":
|
||||||
continue
|
continue
|
||||||
if not dir_info.download_path:
|
if not dir_info.download_path:
|
||||||
continue
|
continue
|
||||||
if file_path.is_relative_to(Path(dir_info.download_path)):
|
if file_path.is_relative_to(Path(dir_info.download_path)):
|
||||||
need_handle = True
|
transfer_dirinfo = dir_info
|
||||||
break
|
break
|
||||||
if not need_handle:
|
if not transfer_dirinfo:
|
||||||
logger.info(f"文件 {file_path} 不在下载器监控目录中,不通过下载器进行整理")
|
logger.info(f"文件 {file_path} 不在下载器监控目录中,不通过下载器进行整理")
|
||||||
# 设置下载任务状态
|
# 设置下载任务状态
|
||||||
self.transfer_completed(hashs=torrent.hash, path=torrent.path)
|
self.transfer_completed(hashs=torrent.hash, path=torrent.path)
|
||||||
@@ -137,7 +138,8 @@ class TransferChain(ChainBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# 设置下载任务状态
|
# 设置下载任务状态
|
||||||
self.transfer_completed(hashs=torrent.hash, path=torrent.path)
|
self.transfer_completed(hashs=torrent.hash, path=torrent.path,
|
||||||
|
transfer_type=transfer_dirinfo.transfer_type)
|
||||||
# 结束
|
# 结束
|
||||||
logger.info("所有下载器中下载完成的文件已整理完成")
|
logger.info("所有下载器中下载完成的文件已整理完成")
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -264,29 +264,28 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase):
|
|||||||
return ret_torrents
|
return ret_torrents
|
||||||
|
|
||||||
def transfer_completed(self, hashs: str, path: Path = None,
|
def transfer_completed(self, hashs: str, path: Path = None,
|
||||||
downloader: str = None) -> None:
|
downloader: str = None, transfer_type: str = None) -> None:
|
||||||
"""
|
"""
|
||||||
转移完成后的处理
|
转移完成后的处理
|
||||||
:param hashs: 种子Hash
|
:param hashs: 种子Hash
|
||||||
:param path: 源目录
|
:param path: 源目录
|
||||||
:param downloader: 下载器
|
:param downloader: 下载器
|
||||||
|
:param transfer_type: 整理方式
|
||||||
"""
|
"""
|
||||||
server: Qbittorrent = self.get_server(downloader)
|
server: Qbittorrent = self.get_server(downloader)
|
||||||
if not server:
|
if not server:
|
||||||
return None
|
return None
|
||||||
server.set_torrents_tag(ids=hashs, tags=['已整理'])
|
server.set_torrents_tag(ids=hashs, tags=['已整理'])
|
||||||
# FIXME 移动模式删除种子
|
# 移动模式删除种子
|
||||||
"""
|
if transfer_type and transfer_type in ["move"]:
|
||||||
if settings.TRANSFER_TYPE in ["move"]:
|
|
||||||
if self.remove_torrents(hashs):
|
if self.remove_torrents(hashs):
|
||||||
logger.info(f"移动模式删除种子成功:{hashs} ")
|
logger.info(f"移动模式删除种子成功:{hashs} ")
|
||||||
# 删除残留文件
|
# 删除本地残留文件
|
||||||
if path and path.exists():
|
if path and path.exists():
|
||||||
files = SystemUtils.list_files(path, settings.RMT_MEDIAEXT)
|
files = SystemUtils.list_files(path, settings.RMT_MEDIAEXT)
|
||||||
if not files:
|
if not files:
|
||||||
logger.warn(f"删除残留文件夹:{path}")
|
logger.warn(f"删除残留文件夹:{path}")
|
||||||
shutil.rmtree(path, ignore_errors=True)
|
shutil.rmtree(path, ignore_errors=True)
|
||||||
"""
|
|
||||||
|
|
||||||
def remove_torrents(self, hashs: Union[str, list], delete_file: bool = True,
|
def remove_torrents(self, hashs: Union[str, list], delete_file: bool = True,
|
||||||
downloader: str = None) -> Optional[bool]:
|
downloader: str = None) -> Optional[bool]:
|
||||||
|
|||||||
@@ -250,13 +250,13 @@ class TransmissionModule(_ModuleBase, _DownloaderBase):
|
|||||||
return ret_torrents
|
return ret_torrents
|
||||||
|
|
||||||
def transfer_completed(self, hashs: str, path: Path = None,
|
def transfer_completed(self, hashs: str, path: Path = None,
|
||||||
downloader: str = None) -> None:
|
downloader: str = None, transfer_type: str = None) -> None:
|
||||||
"""
|
"""
|
||||||
转移完成后的处理
|
转移完成后的处理
|
||||||
:param hashs: 种子Hash
|
:param hashs: 种子Hash
|
||||||
:param path: 源目录
|
:param path: 源目录
|
||||||
:param downloader: 下载器
|
:param downloader: 下载器
|
||||||
:return: None
|
:param transfer_type: 整理方式
|
||||||
"""
|
"""
|
||||||
# 获取下载器
|
# 获取下载器
|
||||||
server: Transmission = self.get_server(downloader)
|
server: Transmission = self.get_server(downloader)
|
||||||
@@ -270,18 +270,16 @@ class TransmissionModule(_ModuleBase, _DownloaderBase):
|
|||||||
else:
|
else:
|
||||||
tags = ['已整理']
|
tags = ['已整理']
|
||||||
server.set_torrent_tag(ids=hashs, tags=tags)
|
server.set_torrent_tag(ids=hashs, tags=tags)
|
||||||
# FIXME 移动模式删除种子
|
# 移动模式删除种子
|
||||||
"""
|
if transfer_type and transfer_type in ["move"]:
|
||||||
if settings.TRANSFER_TYPE in ["move"]:
|
|
||||||
if self.remove_torrents(hashs):
|
if self.remove_torrents(hashs):
|
||||||
logger.info(f"移动模式删除种子成功:{hashs} ")
|
logger.info(f"移动模式删除种子成功:{hashs} ")
|
||||||
# 删除残留文件
|
# 删除本地残留文件
|
||||||
if path and path.exists():
|
if path and path.exists():
|
||||||
files = SystemUtils.list_files(path, settings.RMT_MEDIAEXT)
|
files = SystemUtils.list_files(path, settings.RMT_MEDIAEXT)
|
||||||
if not files:
|
if not files:
|
||||||
logger.warn(f"删除残留文件夹:{path}")
|
logger.warn(f"删除残留文件夹:{path}")
|
||||||
shutil.rmtree(path, ignore_errors=True)
|
shutil.rmtree(path, ignore_errors=True)
|
||||||
"""
|
|
||||||
|
|
||||||
def remove_torrents(self, hashs: Union[str, list], delete_file: bool = True,
|
def remove_torrents(self, hashs: Union[str, list], delete_file: bool = True,
|
||||||
downloader: str = None) -> Optional[bool]:
|
downloader: str = None) -> Optional[bool]:
|
||||||
|
|||||||
Reference in New Issue
Block a user