From bf919c8e39a452c533913ad41ea5403f5eecc752 Mon Sep 17 00:00:00 2001 From: thsrite Date: Thu, 18 Apr 2024 11:07:41 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=BC=82=E6=AD=A5=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- package.json | 5 +-- plugins/cloudstrm/__init__.py | 7 ++-- plugins/filesoftlink/__init__.py | 70 +++++++++++++++++++------------- 4 files changed, 48 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index db4e917..457ab62 100644 --- a/README.md +++ b/README.md @@ -32,5 +32,5 @@ MoviePilot三方插件市场:https://github.com/thsrite/MoviePilot-Plugins/ - [自定义命令 1.5](docs%2FCustomCommand.md) - docker自定义任务 1.2 - 插件彻底卸载 1.0 -- 实时软连接 1.1 +- 实时软连接 1.2 diff --git a/package.json b/package.json index 969b479..4880997 100644 --- a/package.json +++ b/package.json @@ -306,13 +306,12 @@ "FileSoftLink": { "name": "实时软连接", "description": "监控目录文件变化,媒体文件软连接,其他文件可选复制。", - "version": "1.1", + "version": "1.2", "icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/softlink.png", "author": "thsrite", "level": 1, "history": { - "v1.1": "fix bug", - "v1.0": "init" + "v1.2": "异步启动" } } } diff --git a/plugins/cloudstrm/__init__.py b/plugins/cloudstrm/__init__.py index 48d0db5..8326a57 100644 --- a/plugins/cloudstrm/__init__.py +++ b/plugins/cloudstrm/__init__.py @@ -48,7 +48,6 @@ class CloudStrm(_PluginBase): _rebuild = False _https = False _observer = [] - _video_formats = ('.mp4', '.avi', '.rmvb', '.wmv', '.mov', '.mkv', '.flv', '.ts', '.webm', '.iso', '.mpg', '.m2ts') __cloud_files_json = "cloud_files.json" _dirconf = {} @@ -231,7 +230,7 @@ class CloudStrm(_PluginBase): continue # 不复制非媒体文件时直接过滤掉非媒体文件 - if not self._copy_files and not file.lower().endswith(self._video_formats): + if not self._copy_files and Path(file).suffix not in settings.RMT_MEDIAEXT: continue if source_file not in self.__cloud_files: @@ -278,7 +277,7 @@ class CloudStrm(_PluginBase): continue # 不复制非媒体文件时直接过滤掉非媒体文件 - if not self._copy_files and not file.lower().endswith(self._video_formats): + if not self._copy_files and Path(file).suffix not in settings.RMT_MEDIAEXT: continue logger.info(f"扫描到新文件 {source_file},正在开始处理") @@ -341,7 +340,7 @@ class CloudStrm(_PluginBase): os.makedirs(Path(dest_file).parent) # 视频文件创建.strm文件 - if dest_file.lower().endswith(self._video_formats): + if Path(dest_file).suffix in settings.RMT_MEDIAEXT: # 创建.strm文件 self.__create_strm_file(scheme="https" if self._https else "http", dest_file=dest_file, diff --git a/plugins/filesoftlink/__init__.py b/plugins/filesoftlink/__init__.py index c0ed91f..cf6722b 100644 --- a/plugins/filesoftlink/__init__.py +++ b/plugins/filesoftlink/__init__.py @@ -53,7 +53,7 @@ class FileSoftLink(_PluginBase): # 插件图标 plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/softlink.png" # 插件版本 - plugin_version = "1.1" + plugin_version = "1.2" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -145,31 +145,15 @@ class FileSoftLink(_PluginBase): logger.debug(str(e)) pass - try: - if self._mode == "compatibility": - # 兼容模式,目录同步性能降低且NAS不能休眠,但可以兼容挂载的远程共享目录如SMB - observer = PollingObserver(timeout=10) - else: - # 内部处理系统操作类型选择最优解 - observer = Observer(timeout=10) - self._observer.append(observer) - observer.schedule(FileMonitorHandler(mon_path, self), path=mon_path, recursive=True) - observer.daemon = True - observer.start() - logger.info(f"{mon_path} 的目录监控服务启动") - except Exception as e: - err_msg = str(e) - if "inotify" in err_msg and "reached" in err_msg: - logger.warn( - f"目录监控服务启动出现异常:{err_msg},请在宿主机上(不是docker容器内)执行以下命令并重启:" - + """ - echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf - echo fs.inotify.max_user_instances=524288 | sudo tee -a /etc/sysctl.conf - sudo sysctl -p - """) - else: - logger.error(f"{mon_path} 启动目录监控失败:{err_msg}") - self.systemmessage.put(f"{mon_path} 启动目录监控失败:{err_msg}") + # 异步开启云盘监控 + logger.info(f"异步开启实时硬链接 {mon_path} {self._mode},延迟5s启动") + self._scheduler.add_job(func=self.start_monitor, trigger='date', + run_date=datetime.datetime.now( + tz=pytz.timezone(settings.TZ)) + datetime.timedelta(seconds=5), + name=f"实时硬链接 {mon_path}", + kwargs={ + "source_dir": mon_path + }) # 运行一次定时服务 if self._onlyonce: @@ -188,6 +172,36 @@ class FileSoftLink(_PluginBase): self._scheduler.print_jobs() self._scheduler.start() + def start_monitor(self, source_dir: str): + """ + 异步开启实时软链接 + """ + try: + if str(self._mode) == "compatibility": + # 兼容模式,目录同步性能降低且NAS不能休眠,但可以兼容挂载的远程共享目录如SMB + observer = PollingObserver(timeout=10) + else: + # 内部处理系统操作类型选择最优解 + observer = Observer(timeout=10) + self._observer.append(observer) + observer.schedule(FileMonitorHandler(source_dir, self), path=source_dir, recursive=True) + observer.daemon = True + observer.start() + logger.info(f"{source_dir} 的实时软链接服务启动") + except Exception as e: + err_msg = str(e) + if "inotify" in err_msg and "reached" in err_msg: + logger.warn( + f"云盘监控服务启动出现异常:{err_msg},请在宿主机上(不是docker容器内)执行以下命令并重启:" + + """ + echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf + echo fs.inotify.max_user_instances=524288 | sudo tee -a /etc/sysctl.conf + sudo sysctl -p + """) + else: + logger.error(f"{source_dir} 启动云盘监控失败:{err_msg}") + self.systemmessage.put(f"{source_dir} 启动云盘监控失败:{err_msg}") + def __update_config(self): """ 更新配置 @@ -228,7 +242,7 @@ class FileSoftLink(_PluginBase): # 遍历所有监控目录 for mon_path in self._dirconf.keys(): # 遍历目录下所有文件 - for file_path in SystemUtils.list_files(Path(mon_path), settings.RMT_MEDIAEXT): + for file_path in SystemUtils.list_files(Path(mon_path), ['.*']): self.__handle_file(event_path=str(file_path), mon_path=mon_path) logger.info("全量同步监控目录完成!") @@ -321,7 +335,7 @@ class FileSoftLink(_PluginBase): os.makedirs(Path(target_file).parent) # 媒体文件软连接 - if target_file.lower().endswith(self._video_formats): + if Path(target_file).suffix in settings.RMT_MEDIAEXT: SystemUtils.softlink(str(file_path), target_file) else: if self._copy_files: