feat(tmdb): Season 00 按每集播出年份命名
- 特别篇原来取 season_years['00'],那是 Season 00 整体的 air_date
(夏目是 2009,第一集是 3D 猫咪老师剧场),导致 2013/2014/2017 的
6 个 OVA 全被标成 2009
- 改为:遇到 S00 时拉一次 /tv/{id}/season/0,把每集年份存进实体的
special_years(如 {'06': '2013'}),命名时优先用本集年份
- 分季请求失败/404 时回落到季年份,不会变成空年份
- 实测:夏目 6 个 OVA 分别得到 2013 / 2014 / 2017 / 2017 / 2017 / 2017
This commit is contained in:
@@ -297,6 +297,13 @@ class TMDBService:
|
||||
if entity.get("type") != "tv" or not season_num:
|
||||
return entity
|
||||
|
||||
# Season 00(特别篇)不走季年份:整体 air_date 往往是第一篇的年份,
|
||||
# 逐个特别篇要用各自的播出年份,所以单独拉 season/0 的分集数据。
|
||||
if str(season_num).zfill(2) == "00":
|
||||
if not (entity.get("special_years") or {}):
|
||||
cls._load_special_years(entity)
|
||||
return entity
|
||||
|
||||
season_years = entity.setdefault("season_years", {})
|
||||
if season_num in season_years:
|
||||
return entity
|
||||
@@ -318,3 +325,41 @@ class TMDBService:
|
||||
except OSError as exc:
|
||||
log.warning(f"⚠️ 补季写入失败: {exc}")
|
||||
return entity
|
||||
|
||||
@classmethod
|
||||
def _load_special_years(cls, entity):
|
||||
"""拉一次 /tv/{id}/season/0,把每个特别篇的播出年份存进实体。"""
|
||||
log.info("🔄 缓存缺少 Season 00 的分集年份,按需补拉特别篇详情...")
|
||||
session = cls._get_session()
|
||||
payload = cls._fetch_season(session, "tv", entity["tmdb_id"], 0)
|
||||
entity["special_years"] = store.special_years_from(payload) if payload else {}
|
||||
if not entity["special_years"]:
|
||||
return
|
||||
try:
|
||||
with store.transaction(config.TMDB_CACHE_PATH) as db:
|
||||
store.put_entity(db, entity)
|
||||
except OSError as exc:
|
||||
log.warning(f"⚠️ 特别篇年份写入失败: {exc}")
|
||||
|
||||
@classmethod
|
||||
def _fetch_season(cls, session, mtype, tmdb_id, season_number) -> dict | None:
|
||||
try:
|
||||
key = (mtype, int(tmdb_id), int(season_number))
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
if key in cls._dead_ids:
|
||||
return None
|
||||
url = f"https://api.themoviedb.org/3/{mtype}/{tmdb_id}/season/{season_number}"
|
||||
try:
|
||||
resp = session.get(url, params=cls._params(), timeout=config.TMDB_TIMEOUT)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
log.warning(f"⚠️ TMDB 分季请求异常 [{mtype}/{tmdb_id} S{season_number}]: {exc}")
|
||||
return None
|
||||
if resp.status_code == 404:
|
||||
cls._dead_ids.add(key)
|
||||
log.warning(f"⚠️ TMDB 分季不存在(404): {mtype}/{tmdb_id} S{season_number}")
|
||||
return None
|
||||
if resp.status_code != 200:
|
||||
log.warning(f"⚠️ TMDB 分季获取失败 [{mtype}/{tmdb_id} S{season_number}]: HTTP {resp.status_code}")
|
||||
return None
|
||||
return resp.json()
|
||||
|
||||
Reference in New Issue
Block a user