From c7b28f0d110dbc85567aeedf917ce949bb7badf6 Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Tue, 19 Nov 2024 17:39:11 +0800 Subject: [PATCH 01/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 14 ++ plugins.v2/playletcategory/__init__.py | 323 +++++++++++++++++++++++++ 2 files changed, 337 insertions(+) create mode 100644 plugins.v2/playletcategory/__init__.py diff --git a/package.v2.json b/package.v2.json index ed288c0..c7b0490 100644 --- a/package.v2.json +++ b/package.v2.json @@ -251,5 +251,19 @@ "history": { "v2.0": "兼容MoviePilot V2" } + }, + "PlayletCategory": { + "name": "短剧自动分类", + "description": "网络短剧自动整理到独立的分类目录。", + "labels": "文件整理", + "version": "2.1", + "icon": "Amule_A.png", + "author": "jxxghp", + "level": 1, + "v2": true, + "history": { + "v2.1": "兼容MoviePilot V2", + "v2.0": "适配新的目录结构变化,短剧分类名称调整为配置目录路径,升级后需要重新调整设置后才能使用。" + } } } \ No newline at end of file diff --git a/plugins.v2/playletcategory/__init__.py b/plugins.v2/playletcategory/__init__.py new file mode 100644 index 0000000..9545e36 --- /dev/null +++ b/plugins.v2/playletcategory/__init__.py @@ -0,0 +1,323 @@ +import random +import shutil +import subprocess +import threading +from pathlib import Path +from typing import Any, List, Dict, Tuple + +from app.core.config import settings +from app.core.context import MediaInfo +from app.core.event import eventmanager, Event +from app.log import logger +from app.plugins import _PluginBase +from app.schemas import TransferInfo +from app.schemas.types import EventType, MediaType, NotificationType +from app.utils.system import SystemUtils + +lock = threading.Lock() + + +class PlayletCategory(_PluginBase): + # 插件名称 + plugin_name = "短剧自动分类" + # 插件描述 + plugin_desc = "网络短剧自动分类到独立目录。" + # 插件图标 + plugin_icon = "Amule_A.png" + # 插件版本 + plugin_version = "2.0" + # 插件作者 + plugin_author = "jxxghp" + # 作者主页 + author_url = "https://github.com/jxxghp" + # 插件配置项ID前缀 + plugin_config_prefix = "playletcategory_" + # 加载顺序 + plugin_order = 29 + # 可使用的用户级别 + auth_level = 1 + + _enabled = False + _notify = True + _delay = 0 + _category_dir = "" + _episode_duration = 8 + + def init_plugin(self, config: dict = None): + + if config: + self._enabled = config.get("enabled") + self._delay = config.get("delay") or 0 + self._notify = config.get("notify") + self._category_dir = config.get("category_dir") + self._episode_duration = config.get("episode_duration") + + def get_state(self) -> bool: + return True if self._enabled and self._category_dir and self._episode_duration else False + + @staticmethod + def get_command() -> List[Dict[str, Any]]: + pass + + def get_api(self) -> List[Dict[str, Any]]: + pass + + def get_form(self) -> Tuple[List[dict], Dict[str, Any]]: + """ + 拼装插件配置页面,需要返回两块数据:1、页面配置;2、数据结构 + """ + return [ + { + 'component': 'VForm', + 'content': [ + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 6 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'enabled', + 'label': '启用插件', + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 6 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'notify', + 'label': '发送消息', + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4, + }, + 'content': [ + { + 'component': 'VTextField', + 'props': { + 'model': 'category_dir', + 'label': '分类目录路径', + 'placeholder': '/media/短剧' + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4, + }, + 'content': [ + { + 'component': 'VTextField', + 'props': { + 'model': 'episode_duration', + 'label': '单集时长(分钟)', + 'placeholder': '8' + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4, + }, + 'content': [ + { + 'component': 'VTextField', + 'props': { + 'model': 'delay', + 'label': '入库延迟时间(秒)', + 'placeholder': '' + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VAlert', + 'props': { + 'type': 'info', + 'variant': 'tonal', + 'text': '小于单集时长的剧集视频文件将会移动到分类目录,入库延迟适用于网盘等需要延后处理的场景,需要安装FFmpeg。' + } + } + ] + } + ] + } + ] + } + ], { + "enabled": False, + "notify": True, + "delay": '', + "category_dir": '短剧', + "episode_duration": '8' + } + + def get_page(self) -> List[dict]: + pass + + @eventmanager.register(EventType.TransferComplete) + def category_handler(self, event: Event): + """ + 根据事件实时刮削剧集组信息 + """ + if not event: + return + if not self.get_state(): + return + event_data = event.event_data + mediainfo: MediaInfo = event_data.get("mediainfo") + transferinfo: TransferInfo = event_data.get("transferinfo") + if not mediainfo or not transferinfo: + return + if not transferinfo.target_path: + return + if not transferinfo.target_path.exists(): + return + if mediainfo.type != MediaType.TV: + logger.info(f"{transferinfo.target_path} 不是电视剧,跳过分类处理") + return + # 加锁 + with lock: + file_list = transferinfo.file_list_new or [] + # 过滤掉不存在的文件 + file_list = [file for file in file_list if Path(file).exists()] + if not file_list: + logger.warn(f"{transferinfo.target_path} 无文件,跳过分类处理") + return + logger.info(f"开始处理 {transferinfo.target_path} 短剧分类,共有 {len(file_list)} 个文件") + # 从文件列表中随机抽取3个文件 + if len(file_list) > 3: + check_files = random.choices(file_list, k=3) + else: + check_files = file_list + # 计算文件时长,有任意文件时长大于单集时长则不处理 + need_category = True + for file in check_files: + duration = self.__get_duration(file) + if duration > float(self._episode_duration): + logger.info( + f"{file} 时长 {duration} 分钟,大于单集时长 {self._episode_duration} 分钟,不需要分类处理") + need_category = False + break + else: + logger.info(f"{file} 时长:{duration} 分钟") + if need_category: + logger.info(f"{transferinfo.target_path} 需要分类处理,开始移动文件...") + self.__move_files(target_path=transferinfo.target_path) + logger.info(f"{transferinfo.target_path} 短剧分类处理完成") + else: + logger.info(f"{transferinfo.target_path} 不是短剧,无需分类处理") + + @staticmethod + def __get_duration(video_path: str) -> float: + """ + 获取视频文件时长(分钟) + """ + + # 使用FFmpeg命令行工具获取视频时长 + cmd = ['ffprobe', '-v', 'error', '-show_entries', 'format=duration', '-of', + 'default=noprint_wrappers=1:nokey=1', str(video_path)] + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + output, error = process.communicate() + + # 如果有错误,输出错误信息 + if error: + logger.error(f"FFmpeg处理出错: {error.decode('utf-8')}") + return 0 + + # 获取视频时长(秒),转换为分钟 + return round(float(output) / 60, 1) + + def __move_files(self, target_path: Path): + """ + 移动文件到分类目录 + :param target_path: 电视剧时为季的目录 + """ + if not target_path.exists(): + return + if target_path.is_file(): + target_path = target_path.parent + # 剧集的根目录 + tv_path = target_path.parent + # 新的文件目录 + new_path = Path(self._category_dir) / tv_path.name + if not new_path.exists(): + # 移动目录 + try: + shutil.move(tv_path, new_path) + except Exception as e: + logger.error(f"移动文件失败:{e}") + return + else: + # 遍历目录下的所有文件,并移动到目的目录 + for file in tv_path.iterdir(): + if file.is_file(): + try: + # 相对路径 + relative_path = file.relative_to(tv_path) + shutil.move(file, new_path / relative_path) + except Exception as e: + logger.error(f"移动文件失败:{e}") + return + # 删除空目录 + if not SystemUtils.list_files(tv_path, extensions=settings.RMT_MEDIAEXT + settings.DOWNLOAD_TMPEXT): + try: + shutil.rmtree(tv_path, ignore_errors=True) + except Exception as e: + logger.error(f"删除空目录失败:{e}") + + # 发送消息 + if self._notify: + self.post_message( + mtype=NotificationType.Organize, + title="【短剧自动分类】", + text=f"已将 {tv_path.name} 分类到 {self._category_dir} 目录", + ) + + def stop_service(self): + """ + 停止服务 + """ + pass From fdbfe1c3c2fe3c15da4261a15714c3c6b7ebe186 Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Tue, 19 Nov 2024 17:41:26 +0800 Subject: [PATCH 02/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 4 ++-- plugins.v2/chinesesubfinder/__init__.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.v2.json b/package.v2.json index c7b0490..6312f8b 100644 --- a/package.v2.json +++ b/package.v2.json @@ -252,13 +252,13 @@ "v2.0": "兼容MoviePilot V2" } }, - "PlayletCategory": { + "PlayletCategory_v2": { "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", "version": "2.1", "icon": "Amule_A.png", - "author": "jxxghp", + "author": "longqiuyu", "level": 1, "v2": true, "history": { diff --git a/plugins.v2/chinesesubfinder/__init__.py b/plugins.v2/chinesesubfinder/__init__.py index eb80ff7..71a3b6e 100644 --- a/plugins.v2/chinesesubfinder/__init__.py +++ b/plugins.v2/chinesesubfinder/__init__.py @@ -23,7 +23,8 @@ class ChineseSubFinder(_PluginBase): # 插件版本 plugin_version = "2.0" # 插件作者 - plugin_author = "jxxghp" + # plugin_author = "jxxghp" + plugin_author = "longqiuyu" # 作者主页 author_url = "https://github.com/jxxghp" # 插件配置项ID前缀 From d3a3add51b8b112c4d98c383d448032e402a8f82 Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Tue, 19 Nov 2024 18:24:10 +0800 Subject: [PATCH 03/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins.v2/playletcategory/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins.v2/playletcategory/__init__.py b/plugins.v2/playletcategory/__init__.py index 9545e36..06e069a 100644 --- a/plugins.v2/playletcategory/__init__.py +++ b/plugins.v2/playletcategory/__init__.py @@ -17,7 +17,7 @@ from app.utils.system import SystemUtils lock = threading.Lock() -class PlayletCategory(_PluginBase): +class PlayletCategory_v2(_PluginBase): # 插件名称 plugin_name = "短剧自动分类" # 插件描述 @@ -25,13 +25,13 @@ class PlayletCategory(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.0" + plugin_version = "2.1" # 插件作者 plugin_author = "jxxghp" # 作者主页 author_url = "https://github.com/jxxghp" # 插件配置项ID前缀 - plugin_config_prefix = "playletcategory_" + plugin_config_prefix = "playletcategory_v2_" # 加载顺序 plugin_order = 29 # 可使用的用户级别 From b2d5e84058bec5c3cdd6280f0a3a94caf838e6bb Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Tue, 19 Nov 2024 18:29:33 +0800 Subject: [PATCH 04/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 2 +- .../{playletcategory => playletcategory_v2}/__init__.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename plugins.v2/{playletcategory => playletcategory_v2}/__init__.py (99%) diff --git a/package.v2.json b/package.v2.json index 6312f8b..bede2c4 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,7 +256,7 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.1", + "version": "2.2", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, diff --git a/plugins.v2/playletcategory/__init__.py b/plugins.v2/playletcategory_v2/__init__.py similarity index 99% rename from plugins.v2/playletcategory/__init__.py rename to plugins.v2/playletcategory_v2/__init__.py index 06e069a..3155415 100644 --- a/plugins.v2/playletcategory/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -25,11 +25,11 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.1" + plugin_version = "2.2" # 插件作者 - plugin_author = "jxxghp" + plugin_author = "longqiuyu" # 作者主页 - author_url = "https://github.com/jxxghp" + author_url = "https://github.com/LongShengWen" # 插件配置项ID前缀 plugin_config_prefix = "playletcategory_v2_" # 加载顺序 From c05d727655bb8c71366575b696210a92900361d2 Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Tue, 19 Nov 2024 18:38:59 +0800 Subject: [PATCH 05/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 2 +- plugins.v2/playletcategory_v2/__init__.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package.v2.json b/package.v2.json index bede2c4..9cbf8d9 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,7 +256,7 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.2", + "version": "2.3", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory_v2/__init__.py index 3155415..d5107d7 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -25,7 +25,7 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.2" + plugin_version = "2.3" # 插件作者 plugin_author = "longqiuyu" # 作者主页 @@ -202,18 +202,26 @@ class PlayletCategory_v2(_PluginBase): """ 根据事件实时刮削剧集组信息 """ + logger.info(f"触发短剧分类!") if not event: + logger.info(f"短剧分类异常:{event}") return if not self.get_state(): + logger.info(f"短剧分类异常:{event}") return event_data = event.event_data mediainfo: MediaInfo = event_data.get("mediainfo") transferinfo: TransferInfo = event_data.get("transferinfo") + logger.info(f"mediainfo:{mediainfo}") + logger.info(f"transferinfo:{transferinfo}") if not mediainfo or not transferinfo: + logger.info(f"1") return if not transferinfo.target_path: + logger.info(f"2") return if not transferinfo.target_path.exists(): + logger.info(f"3") return if mediainfo.type != MediaType.TV: logger.info(f"{transferinfo.target_path} 不是电视剧,跳过分类处理") @@ -275,7 +283,9 @@ class PlayletCategory_v2(_PluginBase): 移动文件到分类目录 :param target_path: 电视剧时为季的目录 """ + logger.info(f"target_path: {target_path}") if not target_path.exists(): + logger.info(f"4") return if target_path.is_file(): target_path = target_path.parent From 77b79d3f425d2e0ed59f54e395fcd3733a7c1dfe Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Tue, 19 Nov 2024 20:01:56 +0800 Subject: [PATCH 06/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 2 +- plugins.v2/playletcategory_v2/__init__.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.v2.json b/package.v2.json index 9cbf8d9..574a454 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,7 +256,7 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.3", + "version": "2.4", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory_v2/__init__.py index d5107d7..57d877d 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -25,7 +25,7 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.3" + plugin_version = "2.4" # 插件作者 plugin_author = "longqiuyu" # 作者主页 @@ -232,6 +232,7 @@ class PlayletCategory_v2(_PluginBase): # 过滤掉不存在的文件 file_list = [file for file in file_list if Path(file).exists()] if not file_list: + logger.info(f"{transferinfo.target_path} 无文件,跳过分类处理") logger.warn(f"{transferinfo.target_path} 无文件,跳过分类处理") return logger.info(f"开始处理 {transferinfo.target_path} 短剧分类,共有 {len(file_list)} 个文件") From 5e23741d07c8cbc0c83ead3efacc817665e5266f Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Tue, 19 Nov 2024 21:04:01 +0800 Subject: [PATCH 07/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 2 +- plugins.v2/playletcategory_v2/__init__.py | 25 ++++++++++------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/package.v2.json b/package.v2.json index 574a454..432648d 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,7 +256,7 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.4", + "version": "2.5", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory_v2/__init__.py index 57d877d..b32bf96 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -25,7 +25,7 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.4" + plugin_version = "2.5" # 插件作者 plugin_author = "longqiuyu" # 作者主页 @@ -212,19 +212,17 @@ class PlayletCategory_v2(_PluginBase): event_data = event.event_data mediainfo: MediaInfo = event_data.get("mediainfo") transferinfo: TransferInfo = event_data.get("transferinfo") - logger.info(f"mediainfo:{mediainfo}") - logger.info(f"transferinfo:{transferinfo}") if not mediainfo or not transferinfo: - logger.info(f"1") + logger.info(f"关键信息不存在!") return - if not transferinfo.target_path: + if not transferinfo.target_item.path: logger.info(f"2") return - if not transferinfo.target_path.exists(): + if not transferinfo.target_item.path.exists(): logger.info(f"3") return if mediainfo.type != MediaType.TV: - logger.info(f"{transferinfo.target_path} 不是电视剧,跳过分类处理") + logger.info(f"{transferinfo.target_item.path} 不是电视剧,跳过分类处理") return # 加锁 with lock: @@ -232,10 +230,9 @@ class PlayletCategory_v2(_PluginBase): # 过滤掉不存在的文件 file_list = [file for file in file_list if Path(file).exists()] if not file_list: - logger.info(f"{transferinfo.target_path} 无文件,跳过分类处理") - logger.warn(f"{transferinfo.target_path} 无文件,跳过分类处理") + logger.warn(f"{transferinfo.target_item.path} 无文件,跳过分类处理") return - logger.info(f"开始处理 {transferinfo.target_path} 短剧分类,共有 {len(file_list)} 个文件") + logger.info(f"开始处理 {transferinfo.target_item.path} 短剧分类,共有 {len(file_list)} 个文件") # 从文件列表中随机抽取3个文件 if len(file_list) > 3: check_files = random.choices(file_list, k=3) @@ -253,11 +250,11 @@ class PlayletCategory_v2(_PluginBase): else: logger.info(f"{file} 时长:{duration} 分钟") if need_category: - logger.info(f"{transferinfo.target_path} 需要分类处理,开始移动文件...") - self.__move_files(target_path=transferinfo.target_path) - logger.info(f"{transferinfo.target_path} 短剧分类处理完成") + logger.info(f"{transferinfo.target_item.path} 需要分类处理,开始移动文件...") + self.__move_files(target_path=transferinfo.target_item.path) + logger.info(f"{transferinfo.target_item.path} 短剧分类处理完成") else: - logger.info(f"{transferinfo.target_path} 不是短剧,无需分类处理") + logger.info(f"{transferinfo.target_item.path} 不是短剧,无需分类处理") @staticmethod def __get_duration(video_path: str) -> float: From b81d800d0064f71496fd94ad55e090c5816aa7c9 Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Tue, 19 Nov 2024 21:21:04 +0800 Subject: [PATCH 08/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 2 +- plugins.v2/playletcategory_v2/__init__.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.v2.json b/package.v2.json index 432648d..d3deac4 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,7 +256,7 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.5", + "version": "2.6", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory_v2/__init__.py index b32bf96..1fd8c83 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -25,7 +25,7 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.5" + plugin_version = "2.6" # 插件作者 plugin_author = "longqiuyu" # 作者主页 @@ -224,9 +224,10 @@ class PlayletCategory_v2(_PluginBase): if mediainfo.type != MediaType.TV: logger.info(f"{transferinfo.target_item.path} 不是电视剧,跳过分类处理") return + logger.info("开始整理!") # 加锁 with lock: - file_list = transferinfo.file_list_new or [] + file_list = transferinfo.target_item.file_list_new or [] # 过滤掉不存在的文件 file_list = [file for file in file_list if Path(file).exists()] if not file_list: From b8700f22f29807b27d4c646769715be4a63071ff Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Wed, 20 Nov 2024 08:59:50 +0800 Subject: [PATCH 09/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 3 +- plugins.v2/playletcategory_v2/__init__.py | 35 ++++++++++++----------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/package.v2.json b/package.v2.json index d3deac4..250f6bd 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,11 +256,10 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.6", + "version": "2.7", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, - "v2": true, "history": { "v2.1": "兼容MoviePilot V2", "v2.0": "适配新的目录结构变化,短剧分类名称调整为配置目录路径,升级后需要重新调整设置后才能使用。" diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory_v2/__init__.py index 1fd8c83..eb1a761 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -25,7 +25,7 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.6" + plugin_version = "2.7" # 插件作者 plugin_author = "longqiuyu" # 作者主页 @@ -209,21 +209,24 @@ class PlayletCategory_v2(_PluginBase): if not self.get_state(): logger.info(f"短剧分类异常:{event}") return - event_data = event.event_data - mediainfo: MediaInfo = event_data.get("mediainfo") - transferinfo: TransferInfo = event_data.get("transferinfo") - if not mediainfo or not transferinfo: - logger.info(f"关键信息不存在!") - return - if not transferinfo.target_item.path: - logger.info(f"2") - return - if not transferinfo.target_item.path.exists(): - logger.info(f"3") - return - if mediainfo.type != MediaType.TV: - logger.info(f"{transferinfo.target_item.path} 不是电视剧,跳过分类处理") - return + try: + event_data = event.event_data + mediainfo: MediaInfo = event_data.get("mediainfo") + transferinfo: TransferInfo = event_data.get("transferinfo") + if not mediainfo or not transferinfo: + logger.info(f"关键信息不存在!") + return + if not transferinfo.target_item.path: + logger.info(f"2") + return + if not transferinfo.target_item.path.exists(): + logger.info(f"3") + return + if mediainfo.type != MediaType.TV: + logger.info(f"{transferinfo.target_item.path} 不是电视剧,跳过分类处理") + return + except Exception as e: + logger.info(f"目录异常:{str(e)}") logger.info("开始整理!") # 加锁 with lock: From 2283f88bbd00215bad5c75460744d7f4eb93eeb6 Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Wed, 20 Nov 2024 09:32:03 +0800 Subject: [PATCH 10/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 2 +- plugins.v2/playletcategory_v2/__init__.py | 82 ++++++++++++----------- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/package.v2.json b/package.v2.json index 250f6bd..7e209b8 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,7 +256,7 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.7", + "version": "2.8", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory_v2/__init__.py index eb1a761..afdfa11 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -25,7 +25,7 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.7" + plugin_version = "2.8" # 插件作者 plugin_author = "longqiuyu" # 作者主页 @@ -213,52 +213,53 @@ class PlayletCategory_v2(_PluginBase): event_data = event.event_data mediainfo: MediaInfo = event_data.get("mediainfo") transferinfo: TransferInfo = event_data.get("transferinfo") + logger.info(transferinfo.target_item) + logger.info(transferinfo.target_item.path) if not mediainfo or not transferinfo: - logger.info(f"关键信息不存在!") return if not transferinfo.target_item.path: - logger.info(f"2") + logger.debug(f"文件路径不存在:{transferinfo.target_item.path}") return - if not transferinfo.target_item.path.exists(): - logger.info(f"3") + target_path = Path(transferinfo.target_item.path) + if not target_path.exists(): + logger.debug(f"文件路径不存在:{target_path}") return if mediainfo.type != MediaType.TV: - logger.info(f"{transferinfo.target_item.path} 不是电视剧,跳过分类处理") + logger.info(f"{target_path} 不是电视剧,跳过分类处理") return - except Exception as e: - logger.info(f"目录异常:{str(e)}") - logger.info("开始整理!") - # 加锁 - with lock: - file_list = transferinfo.target_item.file_list_new or [] - # 过滤掉不存在的文件 - file_list = [file for file in file_list if Path(file).exists()] - if not file_list: - logger.warn(f"{transferinfo.target_item.path} 无文件,跳过分类处理") - return - logger.info(f"开始处理 {transferinfo.target_item.path} 短剧分类,共有 {len(file_list)} 个文件") - # 从文件列表中随机抽取3个文件 - if len(file_list) > 3: - check_files = random.choices(file_list, k=3) - else: - check_files = file_list - # 计算文件时长,有任意文件时长大于单集时长则不处理 - need_category = True - for file in check_files: - duration = self.__get_duration(file) - if duration > float(self._episode_duration): - logger.info( - f"{file} 时长 {duration} 分钟,大于单集时长 {self._episode_duration} 分钟,不需要分类处理") - need_category = False - break + logger.info("开始整理!") + # 加锁 + with lock: + file_list = transferinfo.target_item.file_list_new or [] + # 过滤掉不存在的文件 + file_list = [file for file in file_list if Path(file).exists()] + if not file_list: + logger.warn(f"{target_path} 无文件,跳过分类处理") + return + logger.info(f"开始处理 {target_path} 短剧分类,共有 {len(file_list)} 个文件") + # 从文件列表中随机抽取3个文件 + if len(file_list) > 3: + check_files = random.choices(file_list, k=3) else: - logger.info(f"{file} 时长:{duration} 分钟") - if need_category: - logger.info(f"{transferinfo.target_item.path} 需要分类处理,开始移动文件...") - self.__move_files(target_path=transferinfo.target_item.path) - logger.info(f"{transferinfo.target_item.path} 短剧分类处理完成") - else: - logger.info(f"{transferinfo.target_item.path} 不是短剧,无需分类处理") + check_files = file_list + # 计算文件时长,有任意文件时长大于单集时长则不处理 + need_category = True + for file in check_files: + duration = self.__get_duration(file) + if duration > float(self._episode_duration): + logger.info(f"{file} 时长 {duration} 分钟,大于单集时长 {self._episode_duration} 分钟,不需要分类处理") + need_category = False + break + else: + logger.info(f"{file} 时长:{duration} 分钟") + if need_category: + logger.info(f"{target_path} 需要分类处理,开始移动文件...") + self.__move_files(target_path=target_path) + logger.info(f"{target_path} 短剧分类处理完成") + else: + logger.info(f"{target_path} 不是短剧,无需分类处理") + except Exception as e: + logger.info(f"短剧分类异常:{str(e)}") @staticmethod def __get_duration(video_path: str) -> float: @@ -287,14 +288,15 @@ class PlayletCategory_v2(_PluginBase): """ logger.info(f"target_path: {target_path}") if not target_path.exists(): - logger.info(f"4") return if target_path.is_file(): target_path = target_path.parent # 剧集的根目录 tv_path = target_path.parent + logger.info(f"{tv_path}") # 新的文件目录 new_path = Path(self._category_dir) / tv_path.name + logger.info(f"{new_path}") if not new_path.exists(): # 移动目录 try: From 4dedbdd743122d886d2ea5f92154a078a3b1754e Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Wed, 20 Nov 2024 09:41:35 +0800 Subject: [PATCH 11/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 2 +- plugins.v2/playletcategory_v2/__init__.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/package.v2.json b/package.v2.json index 7e209b8..0d30663 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,7 +256,7 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.8", + "version": "2.9", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory_v2/__init__.py index afdfa11..751b02d 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -11,6 +11,7 @@ from app.core.event import eventmanager, Event from app.log import logger from app.plugins import _PluginBase from app.schemas import TransferInfo +from app.schemas.file import FileItem from app.schemas.types import EventType, MediaType, NotificationType from app.utils.system import SystemUtils @@ -25,7 +26,7 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.8" + plugin_version = "2.9" # 插件作者 plugin_author = "longqiuyu" # 作者主页 @@ -230,7 +231,9 @@ class PlayletCategory_v2(_PluginBase): logger.info("开始整理!") # 加锁 with lock: - file_list = transferinfo.target_item.file_list_new or [] + target_item: FileItem = transferinfo.target_item + logger.debug(f"target_item: {target_item}") + file_list = target_item.file_list_new or [] # 过滤掉不存在的文件 file_list = [file for file in file_list if Path(file).exists()] if not file_list: From 911891d4569fa192ef1d6704e69563eb848c47fb Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Wed, 20 Nov 2024 11:01:09 +0800 Subject: [PATCH 12/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 2 +- plugins.v2/playletcategory_v2/__init__.py | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/package.v2.json b/package.v2.json index 0d30663..a463ad4 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,7 +256,7 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.9", + "version": "2.10", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory_v2/__init__.py index 751b02d..4476f2e 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -26,7 +26,7 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.9" + plugin_version = "2.10" # 插件作者 plugin_author = "longqiuyu" # 作者主页 @@ -214,14 +214,14 @@ class PlayletCategory_v2(_PluginBase): event_data = event.event_data mediainfo: MediaInfo = event_data.get("mediainfo") transferinfo: TransferInfo = event_data.get("transferinfo") - logger.info(transferinfo.target_item) - logger.info(transferinfo.target_item.path) + logger.info(transferinfo.target_diritem) + logger.info(transferinfo.target_diritem.path) if not mediainfo or not transferinfo: return - if not transferinfo.target_item.path: - logger.debug(f"文件路径不存在:{transferinfo.target_item.path}") + if not transferinfo.target_diritem.path: + logger.debug(f"文件路径不存在:{transferinfo.target_diritem.path}") return - target_path = Path(transferinfo.target_item.path) + target_path = Path(transferinfo.target_diritem.path) if not target_path.exists(): logger.debug(f"文件路径不存在:{target_path}") return @@ -231,9 +231,8 @@ class PlayletCategory_v2(_PluginBase): logger.info("开始整理!") # 加锁 with lock: - target_item: FileItem = transferinfo.target_item - logger.debug(f"target_item: {target_item}") - file_list = target_item.file_list_new or [] + file_list = transferinfo.file_list_new or [] + logger.debug(f"target_item: {file_list}") # 过滤掉不存在的文件 file_list = [file for file in file_list if Path(file).exists()] if not file_list: From 455d58b3b532bb9100680f42337d5b47d9ff48fd Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Wed, 20 Nov 2024 11:25:25 +0800 Subject: [PATCH 13/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 2 +- plugins.v2/playletcategory_v2/__init__.py | 25 +++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/package.v2.json b/package.v2.json index a463ad4..aa705d4 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,7 +256,7 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.10", + "version": "2.11", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory_v2/__init__.py index 4476f2e..e1f18e2 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -26,7 +26,7 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.10" + plugin_version = "2.11" # 插件作者 plugin_author = "longqiuyu" # 作者主页 @@ -203,12 +203,12 @@ class PlayletCategory_v2(_PluginBase): """ 根据事件实时刮削剧集组信息 """ - logger.info(f"触发短剧分类!") + logger.debug(f"触发短剧分类!") if not event: - logger.info(f"短剧分类异常:{event}") + logger.debug(f"短剧分类异常:{event}") return if not self.get_state(): - logger.info(f"短剧分类异常:{event}") + logger.debug(f"短剧分类插件配置不完整!") return try: event_data = event.event_data @@ -228,11 +228,9 @@ class PlayletCategory_v2(_PluginBase): if mediainfo.type != MediaType.TV: logger.info(f"{target_path} 不是电视剧,跳过分类处理") return - logger.info("开始整理!") # 加锁 with lock: file_list = transferinfo.file_list_new or [] - logger.debug(f"target_item: {file_list}") # 过滤掉不存在的文件 file_list = [file for file in file_list if Path(file).exists()] if not file_list: @@ -290,37 +288,38 @@ class PlayletCategory_v2(_PluginBase): """ logger.info(f"target_path: {target_path}") if not target_path.exists(): + logger.warning(f"目标路径 {target_path} 不存在,跳过处理。") return if target_path.is_file(): target_path = target_path.parent # 剧集的根目录 - tv_path = target_path.parent + tv_path = target_path logger.info(f"{tv_path}") # 新的文件目录 - new_path = Path(self._category_dir) / tv_path.name + new_path = Path(self._category_dir) / target_path.name logger.info(f"{new_path}") if not new_path.exists(): # 移动目录 try: - shutil.move(tv_path, new_path) + shutil.move(target_path, new_path) except Exception as e: logger.error(f"移动文件失败:{e}") return else: # 遍历目录下的所有文件,并移动到目的目录 - for file in tv_path.iterdir(): + for file in target_path.iterdir(): if file.is_file(): try: # 相对路径 - relative_path = file.relative_to(tv_path) + relative_path = file.relative_to(target_path) shutil.move(file, new_path / relative_path) except Exception as e: logger.error(f"移动文件失败:{e}") return # 删除空目录 - if not SystemUtils.list_files(tv_path, extensions=settings.RMT_MEDIAEXT + settings.DOWNLOAD_TMPEXT): + if not SystemUtils.list_files(target_path, extensions=settings.RMT_MEDIAEXT + settings.DOWNLOAD_TMPEXT): try: - shutil.rmtree(tv_path, ignore_errors=True) + shutil.rmtree(target_path, ignore_errors=True) except Exception as e: logger.error(f"删除空目录失败:{e}") From 12952785d867e25b4d973dd8bf012f4b06580c7f Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Wed, 20 Nov 2024 12:38:13 +0800 Subject: [PATCH 14/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 2 +- plugins.v2/playletcategory_v2/__init__.py | 50 +++++++++++++++-------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/package.v2.json b/package.v2.json index aa705d4..4491144 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,7 +256,7 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.11", + "version": "2.12", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory_v2/__init__.py index e1f18e2..b3f16d2 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -26,7 +26,7 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.11" + plugin_version = "2.12" # 插件作者 plugin_author = "longqiuyu" # 作者主页 @@ -212,25 +212,28 @@ class PlayletCategory_v2(_PluginBase): return try: event_data = event.event_data - mediainfo: MediaInfo = event_data.get("mediainfo") - transferinfo: TransferInfo = event_data.get("transferinfo") + media_info: MediaInfo = event_data.get("mediainfo") + transfer_info: TransferInfo = event_data.get("transferinfo") logger.info(transferinfo.target_diritem) logger.info(transferinfo.target_diritem.path) - if not mediainfo or not transferinfo: + if not media_info or not transfer_info: return - if not transferinfo.target_diritem.path: - logger.debug(f"文件路径不存在:{transferinfo.target_diritem.path}") + if not transfer_info.success: + logger.debug(f"整理失败不做处理!") return - target_path = Path(transferinfo.target_diritem.path) + if not transfer_info.target_diritem.path: + logger.debug(f"文件路径不存在:{transfer_info.target_diritem.path}") + return + target_path = Path(transfer_info.target_diritem.path) if not target_path.exists(): logger.debug(f"文件路径不存在:{target_path}") return - if mediainfo.type != MediaType.TV: + if media_info.type != MediaType.TV: logger.info(f"{target_path} 不是电视剧,跳过分类处理") return # 加锁 with lock: - file_list = transferinfo.file_list_new or [] + file_list = transfer_info.file_list_new or [] # 过滤掉不存在的文件 file_list = [file for file in file_list if Path(file).exists()] if not file_list: @@ -254,8 +257,11 @@ class PlayletCategory_v2(_PluginBase): logger.info(f"{file} 时长:{duration} 分钟") if need_category: logger.info(f"{target_path} 需要分类处理,开始移动文件...") - self.__move_files(target_path=target_path) - logger.info(f"{target_path} 短剧分类处理完成") + result = self.__move_files(target_path=target_path) + if result: + logger.info(f"{target_path} 短剧分类处理完成") + else: + logger.info(f"{target_path} 短剧分类移动失败!") else: logger.info(f"{target_path} 不是短剧,无需分类处理") except Exception as e: @@ -281,7 +287,7 @@ class PlayletCategory_v2(_PluginBase): # 获取视频时长(秒),转换为分钟 return round(float(output) / 60, 1) - def __move_files(self, target_path: Path): + def __move_files(self, target_path: Path) -> bool: """ 移动文件到分类目录 :param target_path: 电视剧时为季的目录 @@ -289,7 +295,7 @@ class PlayletCategory_v2(_PluginBase): logger.info(f"target_path: {target_path}") if not target_path.exists(): logger.warning(f"目标路径 {target_path} 不存在,跳过处理。") - return + return False if target_path.is_file(): target_path = target_path.parent # 剧集的根目录 @@ -304,18 +310,29 @@ class PlayletCategory_v2(_PluginBase): shutil.move(target_path, new_path) except Exception as e: logger.error(f"移动文件失败:{e}") - return + return False else: # 遍历目录下的所有文件,并移动到目的目录 for file in target_path.iterdir(): + logger.info("f{file}") if file.is_file(): try: # 相对路径 relative_path = file.relative_to(target_path) - shutil.move(file, new_path / relative_path) + logger.info(f"relative_path:{to_path}") + to_path = new_path / relative_path + logger.info(f"to_path:{to_path}") + shutil.move(file, to_path) except Exception as e: logger.error(f"移动文件失败:{e}") - return + return False + else: + # 整季移动 + try: + shutil.move(file, new_path) + except Exception as e: + logger.error(f"移动文件失败:{e}") + return False # 删除空目录 if not SystemUtils.list_files(target_path, extensions=settings.RMT_MEDIAEXT + settings.DOWNLOAD_TMPEXT): try: @@ -330,6 +347,7 @@ class PlayletCategory_v2(_PluginBase): title="【短剧自动分类】", text=f"已将 {tv_path.name} 分类到 {self._category_dir} 目录", ) + return True def stop_service(self): """ From c66c9be10de3f7cb6c3ede3589b6f212e66fb57a Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Wed, 20 Nov 2024 12:45:53 +0800 Subject: [PATCH 15/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 2 +- plugins.v2/playletcategory_v2/__init__.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/package.v2.json b/package.v2.json index 4491144..edca0c6 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,7 +256,7 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.12", + "version": "2.13", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory_v2/__init__.py index b3f16d2..95f694c 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -26,7 +26,7 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.12" + plugin_version = "2.13" # 插件作者 plugin_author = "longqiuyu" # 作者主页 @@ -214,8 +214,7 @@ class PlayletCategory_v2(_PluginBase): event_data = event.event_data media_info: MediaInfo = event_data.get("mediainfo") transfer_info: TransferInfo = event_data.get("transferinfo") - logger.info(transferinfo.target_diritem) - logger.info(transferinfo.target_diritem.path) + logger.debug(transfer_info) if not media_info or not transfer_info: return if not transfer_info.success: From b26e2bdd46bd394436652b394daaa0cb207eaa9f Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Wed, 20 Nov 2024 13:02:21 +0800 Subject: [PATCH 16/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 2 +- plugins.v2/playletcategory_v2/__init__.py | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/package.v2.json b/package.v2.json index edca0c6..12f844a 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,7 +256,7 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.13", + "version": "2.14", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory_v2/__init__.py index 95f694c..711d4bf 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -26,7 +26,7 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.13" + plugin_version = "2.14" # 插件作者 plugin_author = "longqiuyu" # 作者主页 @@ -157,7 +157,7 @@ class PlayletCategory_v2(_PluginBase): 'props': { 'model': 'delay', 'label': '入库延迟时间(秒)', - 'placeholder': '' + 'placeholder': '使用刮削尽量设置大一些' } } ] @@ -214,7 +214,7 @@ class PlayletCategory_v2(_PluginBase): event_data = event.event_data media_info: MediaInfo = event_data.get("mediainfo") transfer_info: TransferInfo = event_data.get("transferinfo") - logger.debug(transfer_info) + # logger.debug(transfer_info) if not media_info or not transfer_info: return if not transfer_info.success: @@ -291,7 +291,7 @@ class PlayletCategory_v2(_PluginBase): 移动文件到分类目录 :param target_path: 电视剧时为季的目录 """ - logger.info(f"target_path: {target_path}") + logger.debug(f"target_path: {target_path}") if not target_path.exists(): logger.warning(f"目标路径 {target_path} 不存在,跳过处理。") return False @@ -299,10 +299,9 @@ class PlayletCategory_v2(_PluginBase): target_path = target_path.parent # 剧集的根目录 tv_path = target_path - logger.info(f"{tv_path}") # 新的文件目录 new_path = Path(self._category_dir) / target_path.name - logger.info(f"{new_path}") + logger.debug(f"{new_path}") if not new_path.exists(): # 移动目录 try: @@ -313,14 +312,14 @@ class PlayletCategory_v2(_PluginBase): else: # 遍历目录下的所有文件,并移动到目的目录 for file in target_path.iterdir(): - logger.info("f{file}") + logger.debug(f"{file}") if file.is_file(): try: # 相对路径 relative_path = file.relative_to(target_path) - logger.info(f"relative_path:{to_path}") + logger.debug(f"relative_path:{to_path}") to_path = new_path / relative_path - logger.info(f"to_path:{to_path}") + logger.debug(f"to_path:{to_path}") shutil.move(file, to_path) except Exception as e: logger.error(f"移动文件失败:{e}") From c1c2a6c8106cdd27704f55eee9a930f14468308f Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Wed, 20 Nov 2024 13:09:48 +0800 Subject: [PATCH 17/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 2 +- plugins.v2/playletcategory_v2/__init__.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/package.v2.json b/package.v2.json index 12f844a..d502a49 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,7 +256,7 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.14", + "version": "2.15", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory_v2/__init__.py index 711d4bf..b1244e1 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -1,4 +1,5 @@ import random +import time import shutil import subprocess import threading @@ -26,7 +27,7 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.14" + plugin_version = "2.15" # 插件作者 plugin_author = "longqiuyu" # 作者主页 @@ -230,6 +231,9 @@ class PlayletCategory_v2(_PluginBase): if media_info.type != MediaType.TV: logger.info(f"{target_path} 不是电视剧,跳过分类处理") return + if self._delay > 0: + # 进行延迟 + time.sleep(self._delay) # 加锁 with lock: file_list = transfer_info.file_list_new or [] From 103dba71f85d29bb704498c85486c6adb269c485 Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Wed, 20 Nov 2024 15:10:55 +0800 Subject: [PATCH 18/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 2 +- plugins.v2/playletcategory_v2/__init__.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.v2.json b/package.v2.json index d502a49..2747cc7 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,7 +256,7 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.15", + "version": "2.16", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory_v2/__init__.py index b1244e1..a62d7bd 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -27,7 +27,7 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.15" + plugin_version = "2.16" # 插件作者 plugin_author = "longqiuyu" # 作者主页 @@ -41,7 +41,7 @@ class PlayletCategory_v2(_PluginBase): _enabled = False _notify = True - _delay = 0 + _delay: int = 0 _category_dir = "" _episode_duration = 8 From ddf0504b28463bcb0aed5a78fe365e1d6f42028b Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Wed, 20 Nov 2024 15:23:16 +0800 Subject: [PATCH 19/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 2 +- plugins.v2/playletcategory_v2/__init__.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.v2.json b/package.v2.json index 2747cc7..63c51a3 100644 --- a/package.v2.json +++ b/package.v2.json @@ -256,7 +256,7 @@ "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.16", + "version": "2.17", "icon": "Amule_A.png", "author": "longqiuyu", "level": 1, diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory_v2/__init__.py index a62d7bd..d2e6751 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory_v2/__init__.py @@ -27,7 +27,7 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.16" + plugin_version = "2.17" # 插件作者 plugin_author = "longqiuyu" # 作者主页 @@ -231,9 +231,9 @@ class PlayletCategory_v2(_PluginBase): if media_info.type != MediaType.TV: logger.info(f"{target_path} 不是电视剧,跳过分类处理") return - if self._delay > 0: + if int(self._delay) > 0: # 进行延迟 - time.sleep(self._delay) + time.sleep(int(self._delay)) # 加锁 with lock: file_list = transfer_info.file_list_new or [] From 8b36f75126bca0265cb574bf30806eb1fca4268f Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Wed, 20 Nov 2024 15:37:37 +0800 Subject: [PATCH 20/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=A7=86=E9=A2=91V2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- package.v2.json | 6 +++--- .../__init__.py | 11 +++++------ 3 files changed, 9 insertions(+), 10 deletions(-) rename plugins.v2/{playletcategory_v2 => playletcategory}/__init__.py (98%) diff --git a/package.json b/package.json index c81332d..c9eb20a 100644 --- a/package.json +++ b/package.json @@ -653,7 +653,7 @@ "icon": "Amule_A.png", "author": "jxxghp", "level": 1, - "v2": true, + // "v2": true, "history": { "v2.0": "适配新的目录结构变化,短剧分类名称调整为配置目录路径,升级后需要重新调整设置后才能使用。" } diff --git a/package.v2.json b/package.v2.json index 63c51a3..855a0e4 100644 --- a/package.v2.json +++ b/package.v2.json @@ -252,13 +252,13 @@ "v2.0": "兼容MoviePilot V2" } }, - "PlayletCategory_v2": { + "PlayletCategory": { "name": "短剧自动分类", "description": "网络短剧自动整理到独立的分类目录。", "labels": "文件整理", - "version": "2.17", + "version": "2.1", "icon": "Amule_A.png", - "author": "longqiuyu", + "author": "jxxghp,longqiuyu", "level": 1, "history": { "v2.1": "兼容MoviePilot V2", diff --git a/plugins.v2/playletcategory_v2/__init__.py b/plugins.v2/playletcategory/__init__.py similarity index 98% rename from plugins.v2/playletcategory_v2/__init__.py rename to plugins.v2/playletcategory/__init__.py index d2e6751..109d4e0 100644 --- a/plugins.v2/playletcategory_v2/__init__.py +++ b/plugins.v2/playletcategory/__init__.py @@ -19,7 +19,7 @@ from app.utils.system import SystemUtils lock = threading.Lock() -class PlayletCategory_v2(_PluginBase): +class PlayletCategory(_PluginBase): # 插件名称 plugin_name = "短剧自动分类" # 插件描述 @@ -27,13 +27,13 @@ class PlayletCategory_v2(_PluginBase): # 插件图标 plugin_icon = "Amule_A.png" # 插件版本 - plugin_version = "2.17" + plugin_version = "2.1" # 插件作者 - plugin_author = "longqiuyu" + plugin_author = "jxxghp,longqiuyu" # 作者主页 - author_url = "https://github.com/LongShengWen" + author_url = "https://github.com/jxxghp" # 插件配置项ID前缀 - plugin_config_prefix = "playletcategory_v2_" + plugin_config_prefix = "playletcategory_" # 加载顺序 plugin_order = 29 # 可使用的用户级别 @@ -215,7 +215,6 @@ class PlayletCategory_v2(_PluginBase): event_data = event.event_data media_info: MediaInfo = event_data.get("mediainfo") transfer_info: TransferInfo = event_data.get("transferinfo") - # logger.debug(transfer_info) if not media_info or not transfer_info: return if not transfer_info.success: From 754ee90a1389ca7f690ee880fe7ed95bd3350d31 Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Wed, 20 Nov 2024 15:37:58 +0800 Subject: [PATCH 21/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=A7=86=E9=A2=91V2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index c9eb20a..0871bda 100644 --- a/package.json +++ b/package.json @@ -653,7 +653,6 @@ "icon": "Amule_A.png", "author": "jxxghp", "level": 1, - // "v2": true, "history": { "v2.0": "适配新的目录结构变化,短剧分类名称调整为配置目录路径,升级后需要重新调整设置后才能使用。" } From 4f8825c3838008294e348b4136484229bb526066 Mon Sep 17 00:00:00 2001 From: LongShengWen Date: Wed, 20 Nov 2024 15:40:28 +0800 Subject: [PATCH 22/22] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=A7=86=E9=A2=91V2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins.v2/chinesesubfinder/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins.v2/chinesesubfinder/__init__.py b/plugins.v2/chinesesubfinder/__init__.py index 71a3b6e..eb80ff7 100644 --- a/plugins.v2/chinesesubfinder/__init__.py +++ b/plugins.v2/chinesesubfinder/__init__.py @@ -23,8 +23,7 @@ class ChineseSubFinder(_PluginBase): # 插件版本 plugin_version = "2.0" # 插件作者 - # plugin_author = "jxxghp" - plugin_author = "longqiuyu" + plugin_author = "jxxghp" # 作者主页 author_url = "https://github.com/jxxghp" # 插件配置项ID前缀