MatchOptions.trustedIds: a candidate fetched by a site-given ID is at least multi_evidence even when titles differ; year/type conflicts stay candidates. Differential group site-ids-* against MP search/result.py _match_source. Co-Authored-By: Claude Opus 5.5 <[email protected]>
63 lines
2.4 KiB
Python
63 lines
2.4 KiB
Python
"""身份匹配差分(ID-3 站点外部 ID 组):用 MP 上游 search/result.py `_match_source` 生成 site-ids-mp.json。
|
|
|
|
用法(MP 仓库根目录,用其 .venv;不访问网络):
|
|
cd /opt/moviepilot-plus/upstream/MoviePilot && PYTHONPATH=. \
|
|
.venv/bin/python /opt/uhd_media_tool/packages/domain/test/differential/identity/gen-site-ids-mp.py
|
|
|
|
每条样本 = 站点种子(标题 / 副标题 / 站点给出的 IMDb ID)+ 目标作品(TMDB 标题 / 年份 / 类型 / IMDb ID)。
|
|
记录 MP `_match_source` 的判定:种子 IMDb 与作品一致时返回 "imdb"(不再比标题),否则走标题匹配。
|
|
只记录行为输出,不复制 MP 源码。
|
|
"""
|
|
|
|
import json
|
|
import pathlib
|
|
import subprocess
|
|
|
|
from app.chain.search.result import _match_source
|
|
from app.domain.context import MediaInfo, TorrentInfo
|
|
from app.domain.metainfo import MetaInfo
|
|
from app.schemas.types import MediaSource, MediaType
|
|
|
|
HERE = pathlib.Path(__file__).parent
|
|
samples = json.loads((HERE / "site-ids-samples.json").read_text(encoding="utf-8"))["samples"]
|
|
|
|
|
|
def run(s: dict) -> dict:
|
|
t = s["torrent"]
|
|
w = s["work"]
|
|
torrent = TorrentInfo(
|
|
site=1,
|
|
site_name="site",
|
|
title=t["title"],
|
|
description=t.get("subtitle"),
|
|
media_source=MediaSource.IMDb if t.get("imdbId") else None,
|
|
media_id=t.get("imdbId"),
|
|
)
|
|
meta = MetaInfo(t["title"], t.get("subtitle"))
|
|
media = MediaInfo()
|
|
media.type = MediaType.MOVIE if w["type"] == "movie" else MediaType.TV
|
|
media.title = w["title"]
|
|
media.original_title = w.get("originalTitle") or w["title"]
|
|
media.en_title = w.get("originalTitle") or w["title"]
|
|
media.year = str(w["year"])
|
|
media.tmdb_id = w["tmdbId"]
|
|
media.imdb_id = w.get("imdbId")
|
|
media.names = []
|
|
try:
|
|
by = _match_source(torrent, meta, media, {})
|
|
except Exception as e: # noqa: BLE001 - 标题匹配分支需要的上下文缺失时记为未命中
|
|
return {"match": None, "error": f"{type(e).__name__}: {e}"}
|
|
return {"match": by}
|
|
|
|
|
|
out = {
|
|
"generatedFrom": {
|
|
"repo": "MoviePilot",
|
|
"commit": subprocess.check_output(["git", "rev-parse", "--short", "HEAD"], text=True).strip(),
|
|
"entry": "app.chain.search.result._match_source",
|
|
},
|
|
"results": {s["id"]: run(s) for s in samples},
|
|
}
|
|
(HERE / "site-ids-mp.json").write_text(json.dumps(out, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
print(json.dumps(out["results"], ensure_ascii=False, indent=1))
|