From 7b5c1a597c44f4bdb2cc8b979665a5ee335841a2 Mon Sep 17 00:00:00 2001 From: thsrite Date: Wed, 17 Jul 2024 09:37:15 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E8=87=AA=E5=AE=9A=E4=B9=89=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BF=9D=E7=95=99=E6=97=B6=E9=95=BF=EF=BC=8C=E5=A4=A7?= =?UTF-8?q?=E4=BA=8E=E8=AF=A5=E5=80=BC=E4=BC=9A=E8=A2=AB=E8=BD=AC=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/CloudAssistant.md | 2 ++ package.json | 3 ++- plugins/cloudassistant/__init__.py | 40 ++++++++++++++++++++++++------ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/docs/CloudAssistant.md b/docs/CloudAssistant.md index 18121d0..4f9845f 100644 --- a/docs/CloudAssistant.md +++ b/docs/CloudAssistant.md @@ -11,6 +11,7 @@ "return_mode": "softlink", "monitor_dirs": [ { + "retention_time": 0, "monitor_mode": "fast", /* 监控模式 compatibility/ */ "dest_path": "/series/link", @@ -132,6 +133,7 @@ cd2方式上传--strm回本地(暂时移除) - return_mode: 云盘文件回本地模式:softlink/strm - return_path:MoviePilot中软链接/strm生成路径 +- retention_time: 本地文件保留时长(小时) 当前日期与文件创建日期的时间差(小时),大于此值的文件将被转移 - monitor_mode:监控模式 compatibility/fast - tranfer_type:转移类型,可选值:copy/move - dest_path: MoviePilot本地刮削好的文件路径(MoviePilot媒体库目录) diff --git a/package.json b/package.json index 2efc437..13b6a47 100644 --- a/package.json +++ b/package.json @@ -542,12 +542,13 @@ "name": "云盘助手", "description": "本地文件定时转移到云盘,软连接/strm回本地,定时清理无效软连接。", "labels": "云盘", - "version": "2.1.3", + "version": "2.1.4", "icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/cloudassistant.png", "author": "thsrite", "level": 99, "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlgN7RtXlPNXoFE9B67ye\ny2mog/hDDrhBAIJogdvfAgBMZ1qVzIPcBfdjENPJ9kV/F+zOoh0CzEaDufM54ERT\nykK1pQw7yj7quRZDbv5byxVNqI8bJg8zQo8Q66SQ8SP+aftmpFrADKClQ8VcVYzZ\nJ+YDu9H9q+TcvBqVtLyKfAH5T9WAxn0bXEh4OgkJn7oO5eI5+Fsi6Aq9suVN/HyK\nz2bDr237GmXJT4YPn9s7kj4Rypzg2ldiuBwtVnaTw+xjZRlCRr4Gs0eFUIMUqnoQ\nip4Px8Mrq5cqHl0HrJ/av/pJLCN1icCgegYW63b2gjjJwmps9NGGOydRzgoFkqj0\nDwIDAQAB", "history": { + "v2.1.4": "自定义文件保留时长,大于该值会被转移", "v2.1.3": "修复消息通知", "v2.1.2": "修复清理无效软连接", "v2.1.1": "修复清理无效软连接", diff --git a/plugins/cloudassistant/__init__.py b/plugins/cloudassistant/__init__.py index 6ebf473..f3d09ad 100644 --- a/plugins/cloudassistant/__init__.py +++ b/plugins/cloudassistant/__init__.py @@ -64,7 +64,7 @@ class CloudAssistant(_PluginBase): # 插件图标 plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/cloudassistant.png" # 插件版本 - plugin_version = "2.1.3" + plugin_version = "2.1.4" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -110,6 +110,7 @@ class CloudAssistant(_PluginBase): "return_mode": "softlink", "monitor_dirs": [ { + "retention_time": 0, "monitor_mode": "模式 compatibility/fast", "dest_path": "/mnt/media/movies", "mount_path": "/mnt/cloud/115/media/movies", @@ -401,13 +402,6 @@ class CloudAssistant(_PluginBase): logger.info(f"{event_path} 命中整理屏蔽词 {keyword},不处理") return - # 判断是不是蓝光目录 - if re.search(r"BDMV[/\\]STREAM", event_path, re.IGNORECASE): - # 截取BDMV前面的路径 - blurray_dir = event_path[:event_path.find("BDMV")] - file_path = Path(blurray_dir) - logger.info(f"{event_path} 是蓝光目录,更正文件路径为:{str(file_path)}") - # 查询转移配置 monitor_dir = self._dirconf.get(mon_path) mount_path = monitor_dir.get("mount_path") @@ -422,6 +416,24 @@ class CloudAssistant(_PluginBase): dest_preserve_hierarchy = monitor_dir.get("dest_preserve_hierarchy") or 0 src_paths = monitor_dir.get("src_paths") or "" src_preserve_hierarchy = monitor_dir.get("src_preserve_hierarchy") or 0 + # 本地文件保留时间 (小时) + retention_time = monitor_dir.get("retention_time") or 0 + if retention_time > 0: + creation_time = self.__get_file_creation_time(file_path) + creation_datetime = datetime.datetime.fromtimestamp(creation_time) + current_datetime = datetime.datetime.now() + time_difference = (current_datetime - creation_datetime).total_seconds() + if time_difference < (int(retention_time) * 3600): + logger.warning( + f"{file_path} 创建 {time_difference / 3600} 小时,小于保留时间 {retention_time} 小时,暂不处理") + return + + # 判断是不是蓝光目录 + if re.search(r"BDMV[/\\]STREAM", event_path, re.IGNORECASE): + # 截取BDMV前面的路径 + blurray_dir = event_path[:event_path.find("BDMV")] + file_path = Path(blurray_dir) + logger.info(f"{event_path} 是蓝光目录,更正文件路径为:{str(file_path)}") # 1、转移到云盘挂载路径 上传到cd2 # 挂载的路径 @@ -628,6 +640,18 @@ class CloudAssistant(_PluginBase): logger.warn(f"删除源文件空目录:{file_dir}") shutil.rmtree(file_dir, ignore_errors=True) + @staticmethod + def __get_file_creation_time(file_path): + """获取文件的创建时间""" + if os.name == 'nt': # Windows系统 + return os.path.getctime(file_path) + else: # Unix系统 + stat = os.stat(file_path) + try: + return stat.st_birthtime + except AttributeError: + return stat.st_mtime + def __msg_handler(self, transferhis): """ 组织消息发送数据