Peach: Local-first video metadata scraper and media manager.
fix(metadata): 按原文快照复核 r18 标题候选
longmeidao6a32255f30e0
diff --git a/docs/REUSE.md b/docs/REUSE.mdindex a42e2ddc3..2370b223b 100644--- a/docs/REUSE.md+++ b/docs/REUSE.md@@ -1,5 +1,9 @@# 复用清单+## 元数据标题原文++持久元数据候选复用 `metadata.extract_peach_fields` 的原文取值和 `metadata_auto_apply` 的统一写入入口。r18 的纯拉丁字母标题需由同一作品快照的原文侧精确印证;缺少快照或只有英文译文时不进入自动结算,人工批准入口同样拒收。来源原文中的拉丁字母片名保留,不按字符集自动翻译。无新增依赖。+## 浏览器错误的构建映射前端复用官方 [`@sentry/vite-plugin` 11.8.0](https://github.com/getsentry/sentry-javascript-bundler-plugins)(MIT,维护中,Node ≥23.2,与项目 Node 24 和 Vite 8 兼容)生成确定性 Debug ID 与 hidden source maps;[`@sentry/cli` 3.8.0](https://github.com/getsentry/sentry-cli)(FSL-1.1-MIT)仅用于构建期本地定位和显式上传。两者精确固定在前端开发依赖,纳入现有 Dependabot;不进入 Python 运行时或独立包依赖。diff --git a/src/peach/metadata.py b/src/peach/metadata.pyindex c7991c9f1..8b8ed9eee 100644--- a/src/peach/metadata.py+++ b/src/peach/metadata.py@@ -443,7 +443,7 @@ def extract_catalog_evidence(payload: dict) -> dict[str, dict]:out: dict[str, dict] = {}text_fields = {"title": original_wording(payload, "title"),- "original_title": payload.get("original_title"),+ "original_title": original_wording(payload, "original_title"),"director": japanese.get("director") or payload.get("director"),"label": japanese.get("label") or payload.get("label"),}diff --git a/src/peach/metadata_auto_apply.py b/src/peach/metadata_auto_apply.pyindex 6388e7d2c..e24edcff7 100644--- a/src/peach/metadata_auto_apply.py+++ b/src/peach/metadata_auto_apply.py@@ -724,6 +724,31 @@ def _auto_apply_rule(candidate: dict, agreed: int) -> str:return f"adr-0018-empty-field-single-{kind}-source"+def _original_title_candidate(field: str, candidate: dict, code: str = '') -> bool:+ """r18 拉丁字母标题须能在快照的原文侧精确复核,适用于持久候选重放。"""+ if field not in {'title', 'original_title'} or candidate.get('source') != 'r18dev':+ return True+ value = ' '.join(str(candidate.get('value') or '').split())+ if not re.search(r'[A-Za-z]', value) or re.search(r'[\u3040-\u30ff\u3400-\u9fff]', value):+ return True+ snapshot = candidate.get('raw_snapshot')+ if not snapshot:+ return False+ try:+ payload = json.loads(Path(snapshot).read_text(encoding='utf-8'))+ if isinstance(payload, dict) and isinstance(payload.get('result'), dict):+ payload = payload['result']+ if not isinstance(payload, dict):+ return False+ from .metadata import extract_peach_fields, identifies_code+ if code and not identifies_code(code, payload):+ return False+ original = extract_peach_fields(payload).get(field, {}).get('value')+ return bool(original) and ' '.join(str(original).split()) == value+ except (OSError, ValueError, TypeError):+ return False++def _evidence_candidates(row: dict, field: str = "") -> list[dict]:"""能当补空证据的候选:已登记来源与本地 NFO,去掉这个字段上被拉黑的来源。@@ -736,7 +761,8 @@ def _evidence_candidates(row: dict, field: str = "") -> list[dict]:return [c for c in row.get("candidates") or []if (str(c.get("source") or "").strip() in SOURCE_SPECSor str(c.get("source") or "").strip() == LOCAL_NFO_SOURCE)- and not blacklisted(field, str(c.get("source") or "").strip())]+ and not blacklisted(field, str(c.get("source") or "").strip())+ and _original_title_candidate(field, c, str(row.get('code') or ''))]def _unmasked_titles(field: str, candidates: list[dict], current: str = "") -> list[dict]:@@ -1263,6 +1289,8 @@ def _apply_metadata_candidate(marks = ",".join("?" * len(asset_ids))if field in {"title", "original_title"}:+ if not _original_title_candidate(field, candidate, code):+ raise ValueError('r18 标题原文证据未取得,请重新采集资料')raw_value = str(candidate.get("value") or "")value = " ".join(raw_value.split())if (not value or len(value) > 1000diff --git a/tests/test_metadata_r18dev.py b/tests/test_metadata_r18dev.pyindex 1213979c5..798afdefc 100644--- a/tests/test_metadata_r18dev.py+++ b/tests/test_metadata_r18dev.py@@ -1,5 +1,6 @@"""r18.dev 套进站点解析器契约:作品 JSON 的解析、combined 页的日文补全、payload 逐键钉住,以及失败分档。"""import json+import tempfileimport unittestfrom unittest.mock import Mock, patch@@ -206,6 +207,28 @@ class OriginalWordingTests(unittest.TestCase):mixed = dict(self.ENGLISH, actresses=[{"japanese_name": "胡桃さくら"}, {"japanese_name": "Remu Suzumori"}])self.assertEqual([row["name"] for row in extract_peach_fields(mixed)["performers"]["value"]], ["胡桃さくら"])+ def test_an_english_original_title_in_an_r18_snapshot_is_source_only(self):+ fields = extract_peach_fields(dict(self.ENGLISH, original_title='English alternative'))+ self.assertNotIn('original_title', fields)++ def test_latin_title_candidates_require_same_work_original_language_evidence(self):+ from pathlib import Path+ from peach.metadata_auto_apply import _original_title_candidate, _evidence_candidates+ candidate = {'source':'r18dev', 'value':'BEAUTY VENUS 5', 'display_value':'BEAUTY VENUS 5'}+ self.assertFalse(_original_title_candidate('title', candidate, 'IPX-219'))+ self.assertEqual(_evidence_candidates({'code':'IPX-219','candidates':[candidate]}, 'title'), [])+ with tempfile.TemporaryDirectory() as directory:+ path = Path(directory) / 'source.json'+ candidate['raw_snapshot'] = str(path)+ payload = {'id':'IPX-219', 'source_url':'https://r18.dev/detail', 'title':'BEAUTY VENUS 5'}+ path.write_text(json.dumps(payload),encoding='utf-8')+ self.assertFalse(_original_title_candidate('title', candidate, 'IPX-219'))+ payload['translations'] = [{'language':'ja','title':'BEAUTY VENUS 5'}]+ path.write_text(json.dumps(payload),encoding='utf-8')+ self.assertTrue(_original_title_candidate('title', candidate, 'IPX-219'))+ self.assertFalse(_original_title_candidate('title', candidate, 'IPX-218'))+ self.assertTrue(_original_title_candidate('title', dict(candidate,source='makers'), 'IPX-219'))+def test_a_top_level_value_written_in_japanese_script_stays(self):payload = dict(self.ENGLISH, series="いつでも使えるオナホ後輩",translations=[{"language": "ja", "series": ""}])diff --git a/tests/test_web_review.py b/tests/test_web_review.pyindex 47b71b22e..19f21d823 100644--- a/tests/test_web_review.py+++ b/tests/test_web_review.py@@ -793,7 +793,7 @@ class ReviewQueueTests(unittest.TestCase):{"item_key": "ABW", "field": "title", "current": "","candidates": ["涼森れむ流 HOW TO SEX!!"], "code": "ABW-358", "source": "local_nfo"},{"item_key": "ABX", "field": "title", "current": "",- "candidates": ["涼森れむ流", {"value": "Remu Style", "source": "r18dev"}],+ "candidates": ["涼森れむ流", {"value": "涼森れむスタイル", "source": "r18dev"}],"code": "ABW-359", "source": "local_nfo"},])self.assertEqual(self._auto()["applied"], 2)@@ -814,7 +814,7 @@ class ReviewQueueTests(unittest.TestCase):# 被压下的说法要留痕:事后得答得出当时还有哪个值、为什么没选它。self.assertEqual(json.loads(notes["ABX"])["rule"], "adr-0038-chain-local_nfo")self.assertEqual(json.loads(notes["ABX"])["overruled"],- [{"source": "r18dev", "value": "Remu Style"}])+ [{"source": "r18dev", "value": "涼森れむスタイル"}])self.assertEqual(self.queue_keys("metadata_fields"), [])def test_the_chain_settles_a_disagreement_between_two_official_sources(self):@@ -2736,6 +2736,21 @@ class ReviewQueueTests(unittest.TestCase):).fetchone()[0], "正式作品标题")con.close()+ def test_r18_english_title_without_original_evidence_is_not_written(self):+ self._asset(890, 'PCH-890', 'PCH-890.mp4')+ candidate = {'candidate_key':'PCH-890:title:r18dev:old', 'source':'r18dev',+ 'source_url':'https://r18.dev/example','provider_id':'PCH-890',+ 'confidence':0.9,'value':'English translated title','display_value':'English translated title'}+ self.write_metadata_candidates([{'item_key':'PCH-890:title','code':'PCH-890','query':'PCH-890',+ 'field':'title','field_label':'标题','current_value':'','candidates_json':json.dumps([candidate]),+ 'source_count':'1','status':'candidate','size_gb':'1','videos':'1','fetched_at':'now'}])+ self.assertEqual(self._auto()['applied'], 0)+ with self.assertRaisesRegex(ValueError, '原文证据未取得'):+ rm_review.w_review_decision(self.contract, {'category':'metadata_fields','item_key':'PCH-890:title',+ 'candidate_key':candidate['candidate_key'],'status':'approved'})+ with contextlib.closing(sqlite3.connect(self.db_path)) as connection:+ self.assertFalse(connection.execute('SELECT catalog_title FROM asset WHERE id=890').fetchone()[0])+def test_metadata_approval_rejects_repeated_name_even_if_csv_is_tampered(self):con = sqlite3.connect(self.db_path)con.execute("UPDATE asset SET code='ABC-001' WHERE id=1")