From 02d8f60709d8e497a21350cbfaaafe54f4cf502a Mon Sep 17 00:00:00 2001 From: x1ao4 Date: Mon, 15 Sep 2025 03:07:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E9=9B=86=E6=95=B0=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=97=B6=E5=A2=9E=E5=8A=A0=E5=AF=B9=20=E2=80=9C=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=20=E8=BF=9E=E6=8E=A5=E7=AC=A6=20=E7=AC=ACx=E6=9C=9F?= =?UTF-8?q?=E2=80=9D=20=E6=A0=BC=E5=BC=8F=E7=9A=84=E7=89=B9=E6=AE=8A?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改前端 buildProgressByTaskNameFromLatestFiles 函数,优先检测"日期 连接符 第x期"格式 - 修改后端 extract_progress_from_latest_file 函数,支持相同的格式检测 - 支持多种日期格式:2025-09-08、2025/09/08、2025.09.08 - 支持多种连接符号:空格、连字符、下划线、点号、斜杠 - 当同时存在日期和"第x期"时,优先使用日期进行集数统计 - 保持向后兼容,不影响现有的纯集数和纯日期格式处理 问题:最近转存文件中的"2025-09-08 - 第128期"等格式被错误地使用第128期而不是日期 解决:增加特殊格式检测,当同时存在日期和"第x期"时优先使用日期,支持各种连接符号 --- app/templates/index.html | 22 ++++++++++++++++++++++ app/utils/task_extractor.py | 20 ++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/app/templates/index.html b/app/templates/index.html index 9115f94..5423fd1 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -4426,6 +4426,26 @@ ]; const parseOne = (txt) => { if (!txt) return null; + + // 特殊处理:检测"日期 连接符 第x期"格式,优先使用日期 + // 支持各种连接符号:空格、-、_、.、/等 + const dateEpisodePatterns = [ + /(\d{4})-(\d{1,2})-(\d{1,2})\s*[-\s_\.\/]\s*第(\d{1,3})期/, // 2025-09-08 - 第128期, 2025-09-08 第128期, 2025-09-08_第128期, 2025-09-08.第128期 + /(\d{4})\/(\d{1,2})\/(\d{1,2})\s*[-\s_\.\/]\s*第(\d{1,3})期/, // 2025/09/08 - 第128期, 2025/09/08 第128期, 2025/09/08_第128期, 2025/09/08.第128期 + /(\d{4})\.(\d{1,2})\.(\d{1,2})\s*[-\s_\.\/]\s*第(\d{1,3})期/, // 2025.09.08 - 第128期, 2025.09.08 第128期, 2025.09.08_第128期, 2025.09.08.第128期 + ]; + + for (const pattern of dateEpisodePatterns) { + const match = String(txt).match(pattern); + if (match) { + const y = match[1]; + const mm = String(match[2]).padStart(2, '0'); + const dd = String(match[3]).padStart(2, '0'); + return { episode_number: null, air_date: `${y}-${mm}-${dd}` }; + } + } + + // 原有的逻辑:先尝试提取集数信息 for (const re of patterns) { const m = String(txt).match(re); if (m) { @@ -4435,6 +4455,8 @@ return { episode_number: parseInt(m[1]), air_date: null }; } } + + // 最后尝试提取日期信息 for (const re of datePatterns) { const m = String(txt).match(re); if (m) { diff --git a/app/utils/task_extractor.py b/app/utils/task_extractor.py index d10dc32..ee9e6f3 100644 --- a/app/utils/task_extractor.py +++ b/app/utils/task_extractor.py @@ -160,6 +160,26 @@ class TaskExtractor: if not latest_file: return {'episode_number': None, 'air_date': None, 'progress_type': 'unknown'} + # 特殊处理:检测"日期 连接符 第x期"格式,优先使用日期 + # 支持各种连接符号:空格、-、_、.、/等 + date_episode_patterns = [ + r'(\d{4})-(\d{1,2})-(\d{1,2})\s*[-\s_\.\/]\s*第(\d{1,3})期', # 2025-09-08 - 第128期, 2025-09-08 第128期, 2025-09-08_第128期, 2025-09-08.第128期 + r'(\d{4})/(\d{1,2})/(\d{1,2})\s*[-\s_\.\/]\s*第(\d{1,3})期', # 2025/09/08 - 第128期, 2025/09/08 第128期, 2025/09/08_第128期, 2025/09/08.第128期 + r'(\d{4})\.(\d{1,2})\.(\d{1,2})\s*[-\s_\.\/]\s*第(\d{1,3})期', # 2025.09.08 - 第128期, 2025.09.08 第128期, 2025.09.08_第128期, 2025.09.08.第128期 + ] + + for pattern in date_episode_patterns: + match = re.search(pattern, latest_file) + if match: + year, month, day = match.groups()[:3] # 只取前3个组(年月日) + date_str = f"{year}-{month.zfill(2)}-{day.zfill(2)}" + return { + 'episode_number': None, + 'season_number': None, + 'air_date': date_str, + 'progress_type': 'date' + } + # 尝试提取集数信息 for pattern in self.episode_patterns: match = re.search(pattern, latest_file)