Peach: Local-first video metadata scraper and media manager.
fix(sourcing): 为独立重采候选保留 JavDB 身份凭据
longmeidao3e277d1d1e02
diff --git a/scripts/scrape_codes.py b/scripts/scrape_codes.pyindex e41f87d42..0eff34945 100644--- a/scripts/scrape_codes.py+++ b/scripts/scrape_codes.py@@ -773,6 +773,8 @@ def _candidates_from(payload: dict, *, query: str, source: str, profile: str, snrow[field] += 1spec = SOURCE_SPECS[source]return {field: {+ **({'javdb_rule': payload.get('javdb_rule'), 'source_id': payload.get('source_id')}+ if source == 'javdb' else {}),"candidate_key": _candidate_key(query, field, source, extracted["value"]),"source": source,"provider": _provider_name(source),diff --git a/tests/test_processing_traffic.py b/tests/test_processing_traffic.pyindex 603ccd703..007131d0f 100644--- a/tests/test_processing_traffic.py+++ b/tests/test_processing_traffic.py@@ -234,7 +234,8 @@ class ProcessingTrafficTests(unittest.TestCase):directory.mkdir(parents=True)for source in ('r18dev', 'javdb'):path = directory / f'ABW-001-{source}.json'- path.write_text(json.dumps({'title': '影片'}), encoding='utf-8')+ payload = {'title': '影片', **({'javdb_rule': 2, 'source_id': 'VerifiedWork'} if source == 'javdb' else {})}+ path.write_text(json.dumps(payload), encoding='utf-8')artifact_rules.remember(path, str(upgrade_rules.PROVIDER_EVIDENCE))traffic = ProcessingTraffic(self.config, self.db, 'collect')with patch.object(traffic.plan.remote, '_chain', return_value=('r18dev', 'javdb')), patch.object(traffic.plan, '_ready', return_value=True):@@ -261,6 +262,23 @@ class ProcessingTrafficTests(unittest.TestCase):restored.refresh_plan([self._video()])self.assertEqual(sum(row['estimated_bytes'] for row in restored.snapshot()['sources'] if not row['root']), 100)+ def test_old_javdb_snapshot_plans_its_request_and_preserves_other_current_cache(self):+ directory = self.config.directory('sources') / 'library-metadata'+ directory.mkdir(parents=True)+ for source in ('r18dev', 'javdb'):+ path = directory / f'ABW-001-{source}.json'+ path.write_text(json.dumps({'title': '影片'}), encoding='utf-8')+ artifact_rules.remember(path, str(upgrade_rules.PROVIDER_EVIDENCE))+ old_path = directory / 'ABW-001-javdb.json'+ before = old_path.read_bytes()+ traffic = ProcessingTraffic(self.config, self.db, 'collect')+ with patch.object(traffic.plan.remote, '_chain', return_value=('r18dev', 'javdb')), \+ patch.object(traffic.plan, '_ready', return_value=True):+ traffic.refresh_plan([self._video()])+ self.assertEqual(sum(row['estimated_bytes'] for row in traffic.snapshot()['sources'] if not row['root']),+ 500 * 1024)+ self.assertEqual(old_path.read_bytes(), before)+def test_source_network_choice_splits_pending_downloads(self):traffic = ProcessingTraffic(self.config, self.db, 'collect')with patch.object(traffic.plan.remote, '_chain', return_value=('r18dev', 'javdb')), patch.object(traffic.plan, '_ready', return_value=True), patch('peach.scraping_access.values_for', side_effect=lambda root, source: {'network': 'direct' if source == 'javdb' else 'peach'}), patch('peach.peach_proxy.client_options', return_value={'proxy': 'http://example.invalid', 'trust_env': False}):diff --git a/tests/test_scripts.py b/tests/test_scripts.pyindex 4a32f5d0f..be9062d5e 100644--- a/tests/test_scripts.py+++ b/tests/test_scripts.py@@ -3876,7 +3876,8 @@ class OperationalScriptTests(unittest.TestCase):@staticmethoddef _full_payload(code, source):- return {"source": source, "id": code, "title": "Catalog title",+ return {**({'javdb_rule': 2, 'source_id': 'VerifiedWork'} if source == 'javdb' else {}),+ "source": source, "id": code, "title": "Catalog title","actresses": [{"japanese_name": "木村さん"}], "maker": "Studio A","release_date": "2020-09-13T00:00:00Z"}@@ -3984,7 +3985,9 @@ class OperationalScriptTests(unittest.TestCase):with output.open(encoding="utf-8-sig", newline="") as handle:tags = next(row for row in csv.DictReader(handle) if row["field"] == "tags")self.assertEqual(tags["current_value"], "肛交")- self.assertEqual(json.loads(tags["candidates_json"])[0]["source"], "javdb")+ candidate = json.loads(tags["candidates_json"])[0]+ self.assertEqual(candidate["source"], "javdb")+ self.assertEqual((candidate.get('javdb_rule'), candidate.get('source_id')), (2, 'VerifiedWork'))self.assertGreaterEqual(auto_apply_metadata(LedgerDatabase(db), candidate_root)["applied"], 1)with closing(sqlite3.connect(db)) as con:self.assertEqual(set(con.execute("SELECT tag,source FROM asset_tag WHERE asset_id=1"