feat(variety): 新增综艺整理模式,按日期匹配 TMDB 播出日期定集号
- 新增 services/variety.py:日期提取(多格式/无年份补全)、TMDB 全季索引 (含 Season 00)、按日期分组的一对一分配、三类动作(改名/extras/删除) - 消歧不依赖「加更/特别」这类关键词:集名里含该日期 +6、类型关键词命中 +3、 季提示 +2,再靠一对一约束用排除法定 - 删除判定:期数 + 类型关键词都相同才算同一集的重复(保留体积最大的), 避免把「加更版第1期」误当成「正片第1期」删掉 - 命名:标题.SxxEyy.年份.技术标签.TMDB期名(期名放最后,按拍板) - main.py 新增 variety 模式与 --show 参数;pipeline 增加 run_variety - docs/variety-plan.md 补记拍板结果与实现状态 预览结果(未执行): 花儿与少年 特典 改名 70 / extras 3 / 删除 0 你好星期六 改名 284 / extras 31 / 删除 49 5.哈 第六季 改名 48 / extras 16 / 删除 0
This commit is contained in:
@@ -28,6 +28,9 @@ class MediaPipeline:
|
||||
|
||||
def run(self):
|
||||
"""返回退出码:0 正常(含无需变更),2 用户取消。"""
|
||||
if getattr(self.args, "mode", "") == "variety":
|
||||
return self.run_variety()
|
||||
|
||||
self._analyze_files()
|
||||
if not self.valid_files:
|
||||
if not self.auto_execute: log.warning("⚠️ 扫描结束:未检测到任何需要处理的媒体文件。")
|
||||
@@ -52,6 +55,72 @@ class MediaPipeline:
|
||||
return 2
|
||||
return 0
|
||||
|
||||
def run_variety(self) -> int:
|
||||
"""综艺整理:按日期匹配集号,产出 改名 / extras / 删除 三类动作。"""
|
||||
from services.variety import VarietyService
|
||||
|
||||
folder = self.target_dir
|
||||
show = self._resolve_variety_show(folder)
|
||||
if not show:
|
||||
log.error("❌ 无法识别剧集:请在目录名里加 [tmdbid-xxx],或用 --show <id> 指定")
|
||||
return 1
|
||||
show_id, show_name, season_years, media_title = show
|
||||
|
||||
plan = VarietyService.plan(folder, show_id, show_name, season_years)
|
||||
VarietyService.preview(plan, season_years, media_title)
|
||||
|
||||
total = len(plan["renames"]) + len(plan["extras"]) + len(plan["deletes"])
|
||||
if not total:
|
||||
log.info("✨ 无需整理。")
|
||||
return 0
|
||||
|
||||
if not self.auto_execute:
|
||||
try:
|
||||
answer = input("⚠️ 是否执行以上变更(含删除)?[y/n/q]: ").strip().lower()
|
||||
except EOFError:
|
||||
log.warning("⛔ 没有可用的终端输入,按取消处理。")
|
||||
return 2
|
||||
if answer not in {"y", "yes"}:
|
||||
log.info("💤 任务已由用户取消。")
|
||||
return 2
|
||||
|
||||
stats = VarietyService.execute(plan, season_years, media_title)
|
||||
log.info(f"🎉 综艺整理完成:改名 {stats['renamed']},extras {stats['extras']},"
|
||||
f"删除 {stats['deleted']},跳过 {stats['skipped']}")
|
||||
return 0
|
||||
|
||||
def _resolve_variety_show(self, folder: Path):
|
||||
"""返回 (tmdb_id, 标题, season_years, media_title);识别失败返回 None。"""
|
||||
import re as _re
|
||||
from services.tmdb import TMDBService
|
||||
|
||||
match = _re.search(r"\[tmdbid-(\d+)\]", folder.name)
|
||||
known = int(match.group(1)) if match else getattr(self.args, "show", None)
|
||||
|
||||
videos = [p for p in folder.rglob("*")
|
||||
if p.is_file() and p.suffix.lower() in {".mkv", ".mp4", ".avi"}]
|
||||
if not videos:
|
||||
return None
|
||||
probe = videos[0]
|
||||
|
||||
title = _re.sub(r"\[tmdbid-\d+\]", "", folder.name)
|
||||
title = _re.sub(r"[\(\(]?\s*(19|20)\d{2}\s*[\)\)]?", "", title)
|
||||
title = _re.sub(r"第\s*[0-9一二三四五六七八九十]+\s*季", "", title)
|
||||
title = _re.sub(r"[Ss]eason\s*\d+", "", title)
|
||||
title = _re.sub(r"[._]+", " ", title).strip(" -_")
|
||||
|
||||
year_match = _re.search(r"(19|20)\d{2}", folder.name)
|
||||
year = year_match.group(0) if year_match else None
|
||||
|
||||
log.info(f"🔎 识别剧集:标题=「{title}」年份={year or '无'}"
|
||||
f"{' 已知 id=' + str(known) if known else ''}")
|
||||
entity = TMDBService.search_media(title, year, "tv", None,
|
||||
known_tmdb_id=known, media_path=probe)
|
||||
if not entity:
|
||||
return None
|
||||
return (entity["tmdb_id"], entity["title"],
|
||||
entity.get("season_years") or {}, entity.get("media_title") or entity["title"])
|
||||
|
||||
def _analyze_files(self):
|
||||
files_to_process = self.target_dir.rglob("*")
|
||||
if not self.auto_execute: log.info("🔍 开始执行文件结构分析...")
|
||||
|
||||
Reference in New Issue
Block a user