feat(variety): 根目录规范化,与媒体整理阶段 5 对齐

- 综艺整理结束后把剧集根目录改成 <标题> (<首播年>) [tmdbid-XXX]
  例:你好星期六 → 你好,星期六 (2022) [tmdbid-154770]
- 首播年取自 TMDB 实体(不是某一集的年份)
- 与媒体整理保持一致的几项:季目录 Season XX、附属文件跟随、
  extras 跳过、目录带 tmdbid 便于下次直接识别
- 实测三个目录:你好,星期六 (2022)、哈哈哈哈哈 (2020)、花儿与少年 (2014)
This commit is contained in:
ali
2026-11-20 00:58:50 +08:00
parent ef881c3975
commit d1a3327839
2 changed files with 24 additions and 5 deletions
+4 -3
View File
@@ -64,9 +64,9 @@ class MediaPipeline:
if not show:
log.error("❌ 无法识别剧集:请在目录名里加 [tmdbid-xxx],或用 --show <id> 指定")
return 1
show_id, show_name, season_years, media_title = show
show_id, show_name, season_years, media_title, show_year = show
plan = VarietyService.plan(folder, show_id, show_name, season_years)
plan = VarietyService.plan(folder, show_id, show_name, season_years, show_year)
VarietyService.preview(plan, season_years, media_title)
total = len(plan["renames"]) + len(plan["extras"]) + len(plan["deletes"])
@@ -119,7 +119,8 @@ class MediaPipeline:
if not entity:
return None
return (entity["tmdb_id"], entity["title"],
entity.get("season_years") or {}, entity.get("media_title") or entity["title"])
entity.get("season_years") or {}, entity.get("media_title") or entity["title"],
str(entity.get("year") or ""))
def _analyze_files(self):
files_to_process = self.target_dir.rglob("*")
+20 -2
View File
@@ -170,7 +170,7 @@ class VarietyService:
# ---------------------------------------------------------------- 主流程
@classmethod
def plan(cls, folder: Path, show_id: int, show_name: str, season_years: dict) -> dict:
def plan(cls, folder: Path, show_id: int, show_name: str, season_years: dict, show_year: str = "") -> dict:
index = cls.build_index(show_id)
videos = [p for p in sorted(folder.rglob("*"))
if p.is_file() and p.suffix.lower() in cls.VIDEO_EXTS
@@ -210,7 +210,7 @@ class VarietyService:
continue
groups[date].append(file)
plan = {"show_id": show_id, "show": show_name, "folder": folder,
plan = {"show_id": show_id, "show": show_name, "folder": folder, "show_year": show_year,
"renames": [], "extras": [], "deletes": [], "undated": undated}
for date, files in sorted(groups.items()):
@@ -434,4 +434,22 @@ class VarietyService:
log.info(f"🏷 已写入标识: {marker.name}(tmdb_id={plan['show_id']})")
except OSError as exc:
log.warning(f"⚠️ 标识写入失败: {exc}")
# 根目录规范化:<标题> (<首播年>) [tmdbid-XXX],与「媒体整理」阶段 5 一致
folder_title = (plan.get("show") or media_title).replace(".", " ")
parts = [folder_title]
if plan.get("show_year"):
parts.append(f"({plan['show_year']})")
target_folder_name = " ".join(parts) + f" [tmdbid-{plan['show_id']}]"
if folder.name != target_folder_name:
target_folder = folder.parent / target_folder_name
if target_folder.exists():
log.warning(f"⚠️ 目标目录已存在,跳过根目录改名: {target_folder_name}")
else:
try:
folder.rename(target_folder)
log.info(f"📁 根目录: {folder.name} → {target_folder_name}")
stats["folder"] = target_folder_name
except OSError as exc:
log.warning(f"⚠️ 根目录改名失败: {exc}")
return stats