fix(variety): 期名用「-」后缀并与常规整理互不干扰
- 命名改为 标题.SxxEyy.年份.技术标签-期名,S00 年份取每集播出年 (与常规整理一致,避免两边各改一次) - renamer.scan_rename 把「<目标名>-说明」视为已规范,整库扫描不再改回去 - 新增 .variety.json 标识:综艺目录名常常不规范(「花儿与少年」会被 误匹配到衍生剧「同心季」),常规扫描据此按记录的 tmdb_id 识别 - 剧集根目录年份改用「首播年」而不是某集年份(综艺各集年份不同, 否则根目录会随扫描顺序乱变) - 附带把 花儿与少年 已整理的 70 个文件按集号重建为最终格式
This commit is contained in:
@@ -210,7 +210,10 @@ class MediaPipeline:
|
|||||||
else:
|
else:
|
||||||
dest_dir = f.parent
|
dest_dir = f.parent
|
||||||
|
|
||||||
is_perfect = (f.name == f"{target_stem}{f.suffix.lower()}")
|
# 「<目标名>-描述」视为已规范:综艺整理会在技术标签后用「-期名」补充说明,
|
||||||
|
# 整库扫描不应把它当作错名再改回去。
|
||||||
|
is_perfect = (f.name == f"{target_stem}{f.suffix.lower()}"
|
||||||
|
or f.stem.startswith(f"{target_stem}-"))
|
||||||
skip_heavy = config.SKIP_PERFECT_MATCH and is_perfect and self.args.mode not in ["clean-ads", "extract-subs"]
|
skip_heavy = config.SKIP_PERFECT_MATCH and is_perfect and self.args.mode not in ["clean-ads", "extract-subs"]
|
||||||
|
|
||||||
if skip_heavy and not self.auto_execute:
|
if skip_heavy and not self.auto_execute:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# src/services/parser.py
|
# src/services/parser.py
|
||||||
|
|
||||||
|
import json
|
||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from core import config
|
from core import config
|
||||||
@@ -74,7 +75,11 @@ class ParserService:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _known_tmdb_id(f_path: Path, m_type: str) -> str | None:
|
def _known_tmdb_id(f_path: Path, m_type: str) -> str | None:
|
||||||
"""目录名里已带 [tmdbid-xxx] 时直接返回,避免重复搜索与歧义。"""
|
"""目录名里已带 [tmdbid-xxx] 时直接返回,避免重复搜索与歧义。
|
||||||
|
|
||||||
|
另外检查「综艺整理」留下的 .variety.json 标识:综艺目录名常常不规范
|
||||||
|
(如「花儿与少年」会误匹配到衍生剧「同心季」),有了标识就按记录的 id 走。
|
||||||
|
"""
|
||||||
names = [f_path.parent.name]
|
names = [f_path.parent.name]
|
||||||
if m_type == "tv" and f_path.parent.parent is not None:
|
if m_type == "tv" and f_path.parent.parent is not None:
|
||||||
names.append(f_path.parent.parent.name)
|
names.append(f_path.parent.parent.name)
|
||||||
@@ -82,6 +87,27 @@ class ParserService:
|
|||||||
match = re.search(r"tmdbid-(\d+)", name, re.I)
|
match = re.search(r"tmdbid-(\d+)", name, re.I)
|
||||||
if match:
|
if match:
|
||||||
return match.group(1)
|
return match.group(1)
|
||||||
|
|
||||||
|
marker_id = ParserService._variety_marker_id(f_path)
|
||||||
|
if marker_id is None:
|
||||||
|
return None
|
||||||
|
return str(marker_id)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _variety_marker_id(f_path: Path) -> int | None:
|
||||||
|
"""读取综艺整理留下的 .variety.json(向上最多找 3 层)。"""
|
||||||
|
folder = f_path.parent
|
||||||
|
for _ in range(3):
|
||||||
|
marker = folder / ".variety.json"
|
||||||
|
if marker.is_file():
|
||||||
|
try:
|
||||||
|
data = json.loads(marker.read_text(encoding="utf-8"))
|
||||||
|
return int(data.get("tmdb_id")) if data.get("tmdb_id") else None
|
||||||
|
except (OSError, ValueError, TypeError):
|
||||||
|
return None
|
||||||
|
if folder.parent == folder:
|
||||||
|
break
|
||||||
|
folder = folder.parent
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -166,7 +192,13 @@ class ParserService:
|
|||||||
tech = f"{tags['res']}.{source}.{tags['v_codec']}.{tags['bits']}.{tags['a_info']}"
|
tech = f"{tags['res']}.{source}.{tags['v_codec']}.{tags['bits']}.{tags['a_info']}"
|
||||||
|
|
||||||
folder_title = title.replace('.', ' ')
|
folder_title = title.replace('.', ' ')
|
||||||
target_folder = f"{folder_title} ({fit_year})" if fit_year else folder_title
|
# 剧集根目录年份用「剧集首播年」:综艺每集年份不同(2022~2025),
|
||||||
|
# 若用某一集的年份,根目录就会随扫描顺序乱变。
|
||||||
|
root_year = fit_year
|
||||||
|
if m_type == "tv":
|
||||||
|
in_name = re.search(r"(?:19|20)\d{2}", folder_title)
|
||||||
|
root_year = in_name.group(0) if in_name else str((tmdb or {}).get("year") or "")
|
||||||
|
target_folder = f"{folder_title} ({root_year})" if root_year else folder_title
|
||||||
if tid:
|
if tid:
|
||||||
target_folder = f"{target_folder} {tid}"
|
target_folder = f"{target_folder} {tid}"
|
||||||
target_folder = target_folder.strip()
|
target_folder = target_folder.strip()
|
||||||
|
|||||||
@@ -108,8 +108,13 @@ class RenamerService:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def scan_rename(f_path: Path, target_stem: str, m_type: str, dest_dir: Path, target_season_folder: str, root_dir_path: Path, target_root_folder: str, task_mgr):
|
def scan_rename(f_path: Path, target_stem: str, m_type: str, dest_dir: Path, target_season_folder: str, root_dir_path: Path, target_root_folder: str, task_mgr):
|
||||||
new_path = dest_dir / f"{target_stem}{f_path.suffix.lower()}"
|
# 「<目标名>-说明」视为已规范:综艺整理会在技术标签后用「-期名」补充描述,
|
||||||
reserved_new_path = task_mgr.reserve_path(new_path, source_path=f_path)
|
# 整库扫描不应把它当作错名再改回去。
|
||||||
|
if f_path.stem == target_stem or f_path.stem.startswith(f"{target_stem}-"):
|
||||||
|
reserved_new_path = f_path
|
||||||
|
else:
|
||||||
|
new_path = dest_dir / f"{target_stem}{f_path.suffix.lower()}"
|
||||||
|
reserved_new_path = task_mgr.reserve_path(new_path, source_path=f_path)
|
||||||
|
|
||||||
if f_path.resolve() != reserved_new_path.resolve():
|
if f_path.resolve() != reserved_new_path.resolve():
|
||||||
task_mgr.add_file_rename(
|
task_mgr.add_file_rename(
|
||||||
|
|||||||
@@ -14,7 +14,9 @@
|
|||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
import re
|
import re
|
||||||
|
from datetime import datetime
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -109,6 +111,7 @@ class VarietyService:
|
|||||||
"season": str(number).zfill(2),
|
"season": str(number).zfill(2),
|
||||||
"ep": ep_no,
|
"ep": ep_no,
|
||||||
"name": episode.get("name") or "",
|
"name": episode.get("name") or "",
|
||||||
|
"air_year": air[:4],
|
||||||
})
|
})
|
||||||
log.info(f"📅 TMDB 索引: {len(index)} 个播出日期({len(seasons)} 季)")
|
log.info(f"📅 TMDB 索引: {len(index)} 个播出日期({len(seasons)} 季)")
|
||||||
return dict(index)
|
return dict(index)
|
||||||
@@ -247,15 +250,21 @@ class VarietyService:
|
|||||||
tags = MediaInfoService.get_scene_tags(file)
|
tags = MediaInfoService.get_scene_tags(file)
|
||||||
tech = f"{tags['res']}.WEB-DL.{tags['v_codec']}.{tags['bits']}.{tags['a_info']}"
|
tech = f"{tags['res']}.WEB-DL.{tags['v_codec']}.{tags['bits']}.{tags['a_info']}"
|
||||||
season = candidate["season"]
|
season = candidate["season"]
|
||||||
year = season_years.get(season) or ""
|
# S00(特别篇)按「本集」播出年份,其余按季年份 —— 与常规整理保持一致
|
||||||
ep_name = StringUtil.sanitize_title(candidate["name"])[:40].strip(".")
|
year = (candidate.get("air_year") if season == "00" else season_years.get(season)) or ""
|
||||||
parts = [media_title, f"S{season}E{candidate['ep']:02d}"]
|
parts = [media_title, f"S{season}E{candidate['ep']:02d}"]
|
||||||
if year:
|
if year:
|
||||||
parts.append(str(year))
|
parts.append(str(year))
|
||||||
parts.append(tech)
|
parts.append(tech)
|
||||||
|
stem = ".".join(parts)
|
||||||
|
|
||||||
|
# 期名用「-」接在技术标签之后:
|
||||||
|
# 常规整理把 `<stem>-任意描述` 视为已规范(不会再被改名),
|
||||||
|
# 所以这条尾巴既信息完整又不会在整库扫描时被判成错名。
|
||||||
|
ep_name = StringUtil.sanitize_title(candidate["name"])[:40].strip(".")
|
||||||
if ep_name:
|
if ep_name:
|
||||||
parts.append(ep_name)
|
stem = f"{stem}-{ep_name}"
|
||||||
return ".".join(parts) + file.suffix.lower()
|
return stem + file.suffix.lower()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def preview(cls, plan: dict, season_years: dict, media_title: str) -> None:
|
def preview(cls, plan: dict, season_years: dict, media_title: str) -> None:
|
||||||
@@ -311,4 +320,18 @@ class VarietyService:
|
|||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
log.warning(f"⚠️ 删除失败 {file.name}: {exc}")
|
log.warning(f"⚠️ 删除失败 {file.name}: {exc}")
|
||||||
stats["skipped"] += 1
|
stats["skipped"] += 1
|
||||||
|
|
||||||
|
# 留一个标识:综艺目录名往往不规范(「花儿与少年」会误匹配到衍生剧),
|
||||||
|
# 常规扫描看到 .variety.json 就按这里记录的 id 识别,不会再用错剧名。
|
||||||
|
try:
|
||||||
|
marker = folder / ".variety.json"
|
||||||
|
marker.write_text(
|
||||||
|
json.dumps(
|
||||||
|
{"tmdb_id": plan["show_id"], "title": plan["show"],
|
||||||
|
"organized_at": datetime.now().isoformat(timespec="seconds")},
|
||||||
|
ensure_ascii=False, indent=2),
|
||||||
|
encoding="utf-8")
|
||||||
|
log.info(f"🏷 已写入标识: {marker.name}(tmdb_id={plan['show_id']})")
|
||||||
|
except OSError as exc:
|
||||||
|
log.warning(f"⚠️ 标识写入失败: {exc}")
|
||||||
return stats
|
return stats
|
||||||
|
|||||||
Reference in New Issue
Block a user