fix(parser): 修正集号解析误取年份,并支持用文件名标题兜底搜 TMDB
- 集号不再取 TARGET_EP 的第一个分组:它会先命中裸数字年份, 导致 Notes...2026.S01E05 解析成 E2026,被防撞锁截成同一个 S01E202, 误报「同剧集下发现重复的集号」并终止整个计划 改为优先匹配 SxxEyy,其次 第x集/EPx,最后兜底 01 - 目录名没写年份时,改从文件名里提取年份 - 中文目录名搜不到 TMDB 时,用文件名里的英文原名重试一次 - 实测:最后一排的男孩(无季目录)→ 自动新建 Season 01 并归档 6 集, 目录自动补成「末行手记 (2026) [tmdbid-286360]」
This commit is contained in:
@@ -60,8 +60,12 @@ class ParserService:
|
||||
title, year = clean_name.strip().replace(' ', '.'), ""
|
||||
|
||||
if not year:
|
||||
# 不再阻塞式追问:年份稍后由 TMDB 实体补全,实在查不到就省略年份段
|
||||
log.debug(f"目录名无年份,将由 TMDB 结果补全: {root_dir_path.name}")
|
||||
# 目录名没写年份时,先从文件名里找(如 ...Last.Row.2026.S01E05...)
|
||||
year_in_name = re.search(r"[.\s_\-\[\(]((?:19|20)\d{2})[.\s_\-\[\]\)]", file_path.stem)
|
||||
if year_in_name:
|
||||
year = year_in_name.group(1)
|
||||
else:
|
||||
log.debug(f"目录名与文件名都没有年份: {root_dir_path.name}")
|
||||
|
||||
context_cache[root_key] = (title, year)
|
||||
|
||||
@@ -80,6 +84,33 @@ class ParserService:
|
||||
return match.group(1)
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _title_from_filename(stem: str) -> str:
|
||||
"""从文件名里推出一个可搜索的标题(用于中文目录名搜不到时的兜底)。
|
||||
|
||||
例:Notes.from.the.Last.Row.2026.S01E05.2160p.NF.WEB-DL... → "Notes from the Last Row"
|
||||
"""
|
||||
head = re.split(r"[.\s_]+S\d{1,2}E\d{1,4}", stem, maxsplit=1, flags=re.I)[0]
|
||||
head = re.sub(r"[.\s_\-]+", " ", head).strip()
|
||||
head = re.sub(r"\s*[\[\(]?(?:19|20)\d{2}[\]\)]?\s*$", "", head).strip()
|
||||
return head
|
||||
|
||||
@staticmethod
|
||||
def _episode_of(stem: str) -> str:
|
||||
"""取集号:优先 SxxEyy,其次 第x集/EPx,最后兜底 01。
|
||||
|
||||
不能直接用 TARGET_EP 的第一个分组——它会先命中裸数字(比如年份 2026)。
|
||||
"""
|
||||
sxe = re.search(r"S(\d{1,2})E(\d{1,4})", stem, re.I)
|
||||
if sxe:
|
||||
return sxe.group(2).zfill(2)
|
||||
match = RegexPatterns.TARGET_EP.search(stem)
|
||||
if match:
|
||||
value = match.group(1) or match.group(2)
|
||||
if value:
|
||||
return value.zfill(2)
|
||||
return "01"
|
||||
|
||||
@staticmethod
|
||||
def get_target_info(f_path: Path, m_type: str, title: str, year: str, season_num: str, is_multi_version: bool = False):
|
||||
tags = MediaInfoService.get_scene_tags(f_path)
|
||||
@@ -88,6 +119,14 @@ class ParserService:
|
||||
known_tmdb_id=ParserService._known_tmdb_id(f_path, m_type),
|
||||
)
|
||||
|
||||
# 中文目录名搜不到时,用文件名里的英文原名再试一次
|
||||
if tmdb is None:
|
||||
alt_title = ParserService._title_from_filename(f_path.stem)
|
||||
plain_title = title.replace(".", " ").strip()
|
||||
if alt_title and alt_title.lower() != plain_title.lower():
|
||||
log.info(f"🔁 中文标题未命中,改用文件名标题重试: {alt_title}")
|
||||
tmdb = TMDBService.search_media(alt_title, year, m_type, season_num)
|
||||
|
||||
# 文件名主名:优先用媒体库里的安全标题(白名单清洗 + 截断)
|
||||
media_name = (tmdb or {}).get("media_title") or ""
|
||||
if not media_name:
|
||||
@@ -116,8 +155,7 @@ class ParserService:
|
||||
stem = f"{media_name}.{fit_year}" if fit_year else media_name
|
||||
return f"{stem}.{tech}", target_folder
|
||||
else:
|
||||
match = RegexPatterns.TARGET_EP.search(f_path.stem)
|
||||
ep = next((g for g in match.groups() if g), "01").zfill(2) if match else "01"
|
||||
ep = ParserService._episode_of(f_path.stem)
|
||||
|
||||
episode_year = fit_year
|
||||
season_years = (tmdb or {}).get("season_years") or {}
|
||||
|
||||
Reference in New Issue
Block a user