mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-04-05 11:47:50 +08:00
fix monitor
This commit is contained in:
@@ -20,7 +20,7 @@ from app.helper.directory import DirectoryHelper
|
||||
from app.helper.format import FormatParser
|
||||
from app.helper.progress import ProgressHelper
|
||||
from app.log import logger
|
||||
from app.schemas import TransferInfo, TransferTorrent, Notification, EpisodeFormat, FileItem
|
||||
from app.schemas import TransferInfo, TransferTorrent, Notification, EpisodeFormat, FileItem, TransferDirectoryConf
|
||||
from app.schemas.types import TorrentStatus, EventType, MediaType, ProgressKey, NotificationType, MessageChannel, \
|
||||
SystemConfigKey
|
||||
from app.utils.string import StringUtils
|
||||
@@ -65,15 +65,9 @@ class TransferChain(ChainBase):
|
||||
# 获取下载器监控目录
|
||||
download_dirs = self.directoryhelper.get_download_dirs()
|
||||
# 如果没有下载器监控的目录则不处理
|
||||
downloader_monitor = False
|
||||
for dir_info in download_dirs:
|
||||
# 只有下载器监控的本地目录才处理
|
||||
if dir_info.monitor_type == "downloader" and dir_info.storage == "local":
|
||||
downloader_monitor = True
|
||||
break
|
||||
if not downloader_monitor:
|
||||
if not any(dir_info.monitor_type == "downloader" and dir_info.storage == "local"
|
||||
for dir_info in download_dirs):
|
||||
return True
|
||||
|
||||
logger.info("开始整理下载器中已经完成下载的文件 ...")
|
||||
# 从下载器获取种子列表
|
||||
torrents: Optional[List[TransferTorrent]] = self.list_torrents(status=TorrentStatus.TRANSFER)
|
||||
@@ -150,24 +144,25 @@ class TransferChain(ChainBase):
|
||||
|
||||
def __do_transfer(self, fileitem: FileItem,
|
||||
meta: MetaBase = None, mediainfo: MediaInfo = None,
|
||||
download_hash: str = None, target_storage: str = None,
|
||||
target_path: Path = None, transfer_type: str = None,
|
||||
target_directory: TransferDirectoryConf = None,
|
||||
target_storage: str = None, target_path: Path = None,
|
||||
transfer_type: str = None, scrape: bool = None,
|
||||
season: int = None, epformat: EpisodeFormat = None,
|
||||
min_filesize: int = 0, scrape: bool = None,
|
||||
force: bool = False) -> Tuple[bool, str]:
|
||||
min_filesize: int = 0, download_hash: str = None, force: bool = False) -> Tuple[bool, str]:
|
||||
"""
|
||||
执行一个复杂目录的整理操作
|
||||
:param fileitem: 文件项
|
||||
:param meta: 元数据
|
||||
:param mediainfo: 媒体信息
|
||||
:param download_hash: 下载记录hash
|
||||
:param target_directory: 目标目录配置
|
||||
:param target_storage: 目标存储器
|
||||
:param target_path: 目标路径
|
||||
:param transfer_type: 整理类型
|
||||
:param scrape: 是否刮削元数据
|
||||
:param season: 季
|
||||
:param epformat: 剧集格式
|
||||
:param min_filesize: 最小文件大小(MB)
|
||||
:param scrape: 是否刮削元数据
|
||||
:param download_hash: 下载记录hash
|
||||
:param force: 是否强制整理
|
||||
返回:成功标识,错误信息
|
||||
"""
|
||||
@@ -228,7 +223,8 @@ class TransferChain(ChainBase):
|
||||
# 如果是目录且不是⼀蓝光原盘,获取所有文件并整理
|
||||
if trans_item.type == "dir" and not bluray_dir:
|
||||
# 遍历获取下载目录所有文件(递归)
|
||||
if (files := self.storagechain.list_files(trans_item, recursion=True)): file_items.extend(files)
|
||||
if files := self.storagechain.list_files(trans_item, recursion=True):
|
||||
file_items.extend(files)
|
||||
# 如果是蓝光目录,计算⼤⼩
|
||||
elif bluray_dir:
|
||||
bluray.append(trans_item)
|
||||
@@ -387,9 +383,10 @@ class TransferChain(ChainBase):
|
||||
transferinfo: TransferInfo = self.transfer(fileitem=file_item,
|
||||
meta=file_meta,
|
||||
mediainfo=file_mediainfo,
|
||||
transfer_type=transfer_type,
|
||||
target_directory=target_directory,
|
||||
target_storage=target_storage,
|
||||
target_path=target_path,
|
||||
transfer_type=transfer_type,
|
||||
episodes_info=episodes_info,
|
||||
scrape=scrape)
|
||||
if not transferinfo:
|
||||
|
||||
@@ -321,30 +321,33 @@ class FileManagerModule(_ModuleBase):
|
||||
message=f"{target_path} 不是有效目录")
|
||||
# 获取目标路径
|
||||
directoryhelper = DirectoryHelper()
|
||||
if target_path:
|
||||
dir_info = directoryhelper.get_dir(mediainfo, dest_path=target_path)
|
||||
else:
|
||||
dir_info = directoryhelper.get_dir(mediainfo)
|
||||
if dir_info:
|
||||
if not target_directory:
|
||||
# 根据目的路径查找目录配置
|
||||
if target_path:
|
||||
target_directory = directoryhelper.get_dir(mediainfo, dest_path=target_path)
|
||||
else:
|
||||
target_directory = directoryhelper.get_dir(mediainfo)
|
||||
|
||||
if target_directory:
|
||||
# 拼装媒体库一、二级子目录
|
||||
target_path = self.__get_dest_dir(mediainfo=mediainfo, target_dir=target_directory)
|
||||
# 目标存储类型
|
||||
if not target_storage:
|
||||
target_storage = dir_info.library_storage
|
||||
target_storage = target_directory.library_storage
|
||||
# 整理方式
|
||||
if not transfer_type:
|
||||
transfer_type = dir_info.transfer_type
|
||||
transfer_type = target_directory.transfer_type
|
||||
# 是否需要刮削
|
||||
if scrape is None:
|
||||
need_scrape = dir_info.scraping
|
||||
need_scrape = target_directory.scraping
|
||||
else:
|
||||
need_scrape = scrape
|
||||
# 是否需要重命名
|
||||
need_rename = dir_info.renaming
|
||||
# 覆盖模式
|
||||
overwrite_mode = dir_info.overwrite_mode
|
||||
need_rename = target_directory.renaming
|
||||
# 是否需要通知
|
||||
need_notify = dir_info.notify
|
||||
# 拼装媒体库一、二级子目录
|
||||
target_path = self.__get_dest_dir(mediainfo=mediainfo, target_dir=dir_info)
|
||||
need_notify = target_directory.notify
|
||||
# 覆盖模式
|
||||
overwrite_mode = target_directory.overwrite_mode
|
||||
elif target_path:
|
||||
# 自定义目标路径,仅适用于手动整理的场景
|
||||
need_scrape = scrape or False
|
||||
@@ -365,14 +368,14 @@ class FileManagerModule(_ModuleBase):
|
||||
return self.transfer_media(fileitem=fileitem,
|
||||
in_meta=meta,
|
||||
mediainfo=mediainfo,
|
||||
transfer_type=transfer_type,
|
||||
overwrite_mode=overwrite_mode,
|
||||
target_storage=target_storage,
|
||||
target_path=target_path,
|
||||
episodes_info=episodes_info,
|
||||
transfer_type=transfer_type,
|
||||
need_scrape=need_scrape,
|
||||
need_rename=need_rename,
|
||||
need_notify=need_notify)
|
||||
need_notify=need_notify,
|
||||
overwrite_mode=overwrite_mode,
|
||||
episodes_info=episodes_info)
|
||||
|
||||
def __get_storage_oper(self, _storage: str, _func: str = None) -> Optional[StorageBase]:
|
||||
"""
|
||||
@@ -832,14 +835,14 @@ class FileManagerModule(_ModuleBase):
|
||||
fileitem: FileItem,
|
||||
in_meta: MetaBase,
|
||||
mediainfo: MediaInfo,
|
||||
transfer_type: str,
|
||||
overwrite_mode: str,
|
||||
target_storage: str,
|
||||
target_path: Path,
|
||||
episodes_info: List[TmdbEpisode] = None,
|
||||
transfer_type: str,
|
||||
need_scrape: bool = False,
|
||||
need_rename: bool = True,
|
||||
need_notify: bool = True,
|
||||
overwrite_mode: str = None,
|
||||
episodes_info: List[TmdbEpisode] = None,
|
||||
) -> TransferInfo:
|
||||
"""
|
||||
识别并整理一个文件或者一个目录下的所有文件
|
||||
@@ -849,11 +852,11 @@ class FileManagerModule(_ModuleBase):
|
||||
:param target_storage: 目标存储
|
||||
:param target_path: 目标路径
|
||||
:param transfer_type: 文件整理方式
|
||||
:param overwrite_mode: 覆盖模式
|
||||
:param episodes_info: 当前季的全部集信息
|
||||
:param need_scrape: 是否需要刮削
|
||||
:param need_rename: 是否需要重命名
|
||||
:param need_notify: 是否需要通知
|
||||
:param overwrite_mode: 覆盖模式
|
||||
:param episodes_info: 当前季的全部集信息
|
||||
:return: TransferInfo、错误信息
|
||||
"""
|
||||
|
||||
|
||||
@@ -386,12 +386,10 @@ class Monitor(metaclass=Singleton):
|
||||
return
|
||||
|
||||
# 查询转移目的目录
|
||||
dir_info = self.directoryhelper.get_dir(mediainfo, src_path=Path(mon_path))
|
||||
dir_info = self.directoryhelper.get_dir(mediainfo, src_path=mon_path)
|
||||
if not dir_info:
|
||||
logger.warn(f"{event_path.name} 未找到对应的目标目录")
|
||||
return
|
||||
# 获取目标路径
|
||||
dest_path = Path(dir_info.library_path)
|
||||
|
||||
# 查找这个文件项
|
||||
file_item = self.storagechain.get_file_item(storage=storage, path=event_path)
|
||||
@@ -421,7 +419,7 @@ class Monitor(metaclass=Singleton):
|
||||
transferinfo: TransferInfo = self.chain.transfer(fileitem=file_item,
|
||||
meta=file_meta,
|
||||
mediainfo=mediainfo,
|
||||
target_path=dest_path,
|
||||
target_directory=dir_info,
|
||||
episodes_info=episodes_info)
|
||||
|
||||
if not transferinfo:
|
||||
|
||||
Reference in New Issue
Block a user