From 6b76b5ce79101db6fead9895d276235e2850e15d Mon Sep 17 00:00:00 2001 From: thsrite Date: Mon, 21 Apr 2025 11:48:13 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BA=91=E7=9B=98Strm=E5=8A=A9=E6=89=8Bv?= =?UTF-8?q?1.3.2=20=E6=8F=92=E4=BB=B6=E8=81=94=E5=8A=A8=E7=94=9F=E6=88=90S?= =?UTF-8?q?trm=E6=96=87=E4=BB=B6=E5=90=8C=E6=97=B6=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=9D=9E=E5=AA=92=E4=BD=93=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 3 +- plugins.v2/cloudstrmcompanion/__init__.py | 54 ++++++++++++++++------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/package.v2.json b/package.v2.json index 8c21cd6..84c42c2 100644 --- a/package.v2.json +++ b/package.v2.json @@ -447,11 +447,12 @@ "name": "云盘Strm助手", "description": "实时监控、定时全量增量生成strm文件。", "labels": "云盘", - "version": "1.3.1", + "version": "1.3.2", "icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/cloudcompanion.png", "author": "thsrite", "level": 1, "history": { + "v1.3.2": "插件联动生成Strm文件同时处理非媒体文件", "v1.3.1": "增加全量同步", "v1.3": "移除全量同步、定时同步(谨慎升级)", "v1.2.7": "增加路径替换规则", diff --git a/plugins.v2/cloudstrmcompanion/__init__.py b/plugins.v2/cloudstrmcompanion/__init__.py index f81b4c2..093be71 100644 --- a/plugins.v2/cloudstrmcompanion/__init__.py +++ b/plugins.v2/cloudstrmcompanion/__init__.py @@ -57,7 +57,7 @@ class CloudStrmCompanion(_PluginBase): # 插件图标 plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/cloudcompanion.png" # 插件版本 - plugin_version = "1.3.1" + plugin_version = "1.3.2" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -106,7 +106,6 @@ class CloudStrmCompanion(_PluginBase): # 退出事件 _event = threading.Event() - def init_plugin(self, config: dict = None): # 清空配置 self._strm_dir_conf = {} @@ -337,24 +336,45 @@ class CloudStrmCompanion(_PluginBase): # 生成strm文件 self.__create_strm_file(strm_file=target_file, strm_content=strm_content) - else: - # 复制非媒体文件 - if self._copy_files and self._other_mediaext and Path(event_path).suffix.lower() in [ext.strip() for - ext in - self._other_mediaext.split( - ",")]: - os.makedirs(os.path.dirname(target_file), exist_ok=True) - shutil.copy2(str(event_path), target_file) - logger.info(f"复制非媒体文件 {str(event_path)} 到 {target_file}") - # 复制字幕文件(独立于copy_files检查) - if self._copy_subtitles and Path(event_path).suffix.lower() in ['.srt', '.ass', '.ssa', '.sub']: - os.makedirs(os.path.dirname(target_file), exist_ok=True) - shutil.copy2(str(event_path), target_file) - logger.info(f"复制字幕文件 {str(event_path)} 到 {target_file}") + # nfo、jpg等同名文件 + pattern = Path(event_path).stem.replace('[', '?').replace(']', '?') + files = list(Path(event_path).parent.glob(f"{pattern}.*")) + logger.debug(f"筛选到 {Path(event_path).parent} 下同名文件 {pattern} {files}") + for file in files: + target_file = str(file).replace(mon_path, strm_dir) + self.__handle_other_files(event_path=str(file), target_file=target_file) + + # thumb图片 + thumb_file = Path(event_path).parent / (Path(event_path).stem + "-thumb.jpg") + if thumb_file.exists(): + target_file = str(thumb_file).replace(mon_path, strm_dir) + self.__handle_other_files(event_path=str(thumb_file), target_file=target_file) + else: + self.__handle_other_files(event_path=event_path, target_file=target_file) except Exception as e: logger.error("目录监控发生错误:%s - %s" % (str(e), traceback.format_exc())) + def __handle_other_files(self, event_path: str, target_file: str): + """ + 处理非媒体文件 + :param event_path: 事件文件路径 + """ + # 复制非媒体文件 + if self._copy_files and self._other_mediaext and Path(event_path).suffix.lower() in [ext.strip() for + ext in + self._other_mediaext.split( + ",")]: + os.makedirs(os.path.dirname(target_file), exist_ok=True) + shutil.copy2(str(event_path), target_file) + logger.info(f"复制非媒体文件 {str(event_path)} 到 {target_file}") + + # 复制字幕文件(独立于copy_files检查) + if self._copy_subtitles and Path(event_path).suffix.lower() in ['.srt', '.ass', '.ssa', '.sub']: + os.makedirs(os.path.dirname(target_file), exist_ok=True) + shutil.copy2(str(event_path), target_file) + logger.info(f"复制字幕文件 {str(event_path)} 到 {target_file}") + def __sava_json(self): """ 保存json文件 @@ -1316,4 +1336,4 @@ class CloudStrmCompanion(_PluginBase): self._event.set() self._scheduler.shutdown() self._event.clear() - self._scheduler = None \ No newline at end of file + self._scheduler = None