feat(identity): trust site-provided IMDb/TMDB IDs in scoring (ID-3)

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]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-10-01 00:15:20 +08:00
1 parent a9e6e6c36a
commit a6d655d2ce
6 files changed
+317

No files matched your search

@@ -0,0 +1,62 @@
"""身份匹配差分(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))
@@ -0,0 +1,13 @@
{
"note": "ID-3 站点外部 ID 组的逐条归因。MP `_match_source` 只要种子 IMDb 与作品一致就判命中;我们把站点 ID 当强证据但保留年份 / 类型硬规则。",
"deviations": {
"S-004": {
"kind": "intentional",
"note": "年份差 37 年:站点 IMDb 链接挂错(挂到同名新片)的典型。我们只作候选(needs_confirm → 待确认),不自动绑定;MP 直接按 IMDb 命中"
},
"S-006": {
"kind": "intentional",
"note": "剧集标题(S01)配电影 IMDb:类型冲突,只作候选;MP 按 IMDb 命中"
}
}
}
@@ -0,0 +1,27 @@
{
"generatedFrom": {
"repo": "MoviePilot",
"commit": "e6820a8",
"entry": "app.chain.search.result._match_source"
},
"results": {
"S-001": {
"match": "imdb"
},
"S-002": {
"match": "imdb"
},
"S-003": {
"match": "imdb"
},
"S-004": {
"match": "imdb"
},
"S-005": {
"match": "imdb"
},
"S-006": {
"match": "imdb"
}
}
}
@@ -0,0 +1,97 @@
{
"note": "ID-3 站点外部 ID 组:种子标题 / 副标题取自观众(DET-2)详情样本与憨憨样本,IMDb ID 为样本页面上的链接;作品侧 TMDB id / 标题为测试夹具(不是 TMDB 真实数据)。expectOurs = 我们在 trustedIds 下的判定(auto / ambiguous / no_match)。",
"samples": [
{
"id": "S-001",
"note": "观众 725858:标题与作品名一致,IMDb 一致",
"torrent": {
"title": "Rose 2026 1080p BluRay AVC DTS-HD MA 5.1-DIY@Audies",
"subtitle": "罗斯 / 扑朔迷离的露丝(港)【德版原盘DIY 简繁字幕】",
"imdbId": "tt25399154"
},
"work": {
"type": "movie",
"tmdbId": 990001,
"title": "罗斯",
"originalTitle": "Rose",
"year": 2026,
"imdbId": "tt25399154"
},
"expectOurs": "auto"
},
{
"id": "S-002",
"note": "观众 727077:英文名(A Prophet)与作品英文名对不上,IMDb 一致",
"torrent": {
"title": "A Prophet S01E16 2026 2160p iQIYI WEB-DL H265 HDR DDP5.1-ADWeb",
"subtitle": "我不是大师 第16集 | 类型:剧情 悬疑 | 主演:李现 李一桐 吴刚 刘冠麟 果靖霖 | 长风起 / 将相 / 江相 / 我是个算命先生",
"imdbId": "tt36758489"
},
"work": {
"type": "tv",
"tmdbId": 990002,
"title": "我不是大师",
"originalTitle": "The Fortune Teller",
"year": 2026,
"imdbId": "tt36758489"
},
"expectOurs": "auto"
},
{
"id": "S-003",
"note": "标题完全对不上(站点用拼音名),IMDb 一致",
"torrent": { "title": "Wu Ji 2005 1080p BluRay x264-WiKi", "imdbId": "tt0417976" },
"work": {
"type": "movie",
"tmdbId": 990003,
"title": "The Promise",
"originalTitle": "The Promise",
"year": 2005,
"imdbId": "tt0417976"
},
"expectOurs": "auto"
},
{
"id": "S-004",
"note": "IMDb 一致但年份差 37 年(站点 IMDb 链接挂错的典型)",
"torrent": { "title": "Dune 1984 1080p BluRay x264-GRP", "imdbId": "tt1160419" },
"work": {
"type": "movie",
"tmdbId": 990004,
"title": "Dune",
"originalTitle": "Dune",
"year": 2021,
"imdbId": "tt1160419"
},
"expectOurs": "ambiguous"
},
{
"id": "S-005",
"note": "IMDb 一致,标题对不上,年份差 1 年(容差内)",
"torrent": { "title": "Hero 2003 1080p BluRay x264-GRP", "imdbId": "tt0299977" },
"work": {
"type": "movie",
"tmdbId": 990005,
"title": "英雄",
"originalTitle": "英雄",
"year": 2002,
"imdbId": "tt0299977"
},
"expectOurs": "auto"
},
{
"id": "S-006",
"note": "剧集标题(S01)配电影的 IMDb:类型冲突",
"torrent": { "title": "Sherlock S01 2010 1080p BluRay x264-GRP", "imdbId": "tt1475582" },
"work": {
"type": "movie",
"tmdbId": 990006,
"title": "Sherlock Holmes",
"originalTitle": "Sherlock Holmes",
"year": 2009,
"imdbId": "tt1475582"
},
"expectOurs": "ambiguous"
}
]
}