Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(metadata): 对齐 JavDB 类别契约并关闭回归临时库

longmeidao2917b206a7df
diff --git a/src/peach/sources/javdb.py b/src/peach/sources/javdb.py
index 02bc5cd2a..9e76267da 100644
--- a/src/peach/sources/javdb.py
+++ b/src/peach/sources/javdb.py
@@ -153,7 +153,7 @@ class JavDBSource(SiteSource):
studio=maker_writing(clean(panel.get("片商", ""))), label=clean(panel.get("發行", "")),
series=clean(panel.get("系列", "")), director=clean(panel.get("導演", "")),
release_date=clean(panel.get("日期", "")), runtime=int(runtime.group()) if runtime else None,
- genres=genres,
+ tags=genres,
cover_urls=(cover.group(1),) if cover else ())
diff --git a/tests/test_community_catalog.py b/tests/test_community_catalog.py
index 680243ab9..e52bdae9d 100644
--- a/tests/test_community_catalog.py
+++ b/tests/test_community_catalog.py
@@ -208,6 +208,28 @@ class CommunityCatalogTests(unittest.TestCase):
javdb_actresses('<a class="actor-female">名字没挂链接</a>'),
[{"japanese_name": "名字没挂链接", "profile_source": "javdb", "external_id": ""}])
+ def test_javdb_categories_keep_source_words_in_the_shared_record_and_snapshot(self):
+ categories = ('<div class="panel-block"><strong>類別:</strong><span class="value">'
+ '<a href="/tags/a"> 高跟鞋 </a><a href="/tags/b"><b>絲襪</b></a>'
+ '<a href="/tags/c">アナル</a><a href="/tags/d">未收录分類</a>'
+ '<a href="/tags/a">高跟鞋</a><a href="/tags/empty"> </a></span></div>')
+ page = JAVDB_PAGE + categories.encode()
+ record = JavDBSource().parse(Page("https://javdb.com/v/Zb7mX", page), "ABW-358")
+ self.assertEqual(record.tags, ("高跟鞋", "絲襪", "アナル", "未收录分類"))
+ found = work(JavDBSource(), {JAVDB_SEARCH: JAVDB_RESULTS, JAVDB_DETAIL: page}, "ABW-358")
+ self.assertEqual(found, record.payload())
+ self.assertEqual(found["genres"], ["高跟鞋", "絲襪", "アナル", "未收录分類"])
+
+ def test_javdb_empty_categories_are_an_empty_genres_snapshot(self):
+ empty_panel = ('<div class="panel-block"><strong>類別:</strong>'
+ '<span class="value"><a href="/tags/empty"> </a></span></div>')
+ for category_panel in ("", empty_panel):
+ with self.subTest(category_panel=category_panel):
+ record = JavDBSource().parse(
+ Page("https://javdb.com/v/Zb7mX", JAVDB_PAGE + category_panel.encode()), "ABW-358")
+ self.assertEqual(record.tags, ())
+ self.assertEqual(record.payload()["genres"], [])
+
def test_javdb_reports_a_missing_code_and_a_login_wall_differently(self):
with self.assertRaises(SourceFailure) as caught:
work(JavDBSource(), {JAVDB_SEARCH: JAVDB_RESULTS.replace(b"<strong>ABW-358</strong>", b"<strong>ABW-359</strong>")},
@@ -233,7 +255,7 @@ class CommunityCatalogTests(unittest.TestCase):
"id": "ABW-358", "source_url": "https://javdb.com/v/Zb7mX", "title": TITLE,
"actresses": [{"japanese_name": "涼森れむ", "profile_source": "javdb", "external_id": "a"}],
"maker": "プレステージ", "label": "", "series": "", "director": "", "release_date": "2023-05-23",
- "runtime": 210, "cover_urls": [JAVDB_COVER], "cover_url": JAVDB_COVER}
+ "runtime": 210, "genres": [], "cover_urls": [JAVDB_COVER], "cover_url": JAVDB_COVER}
self.assertEqual(work(JavDBSource(), {JAVDB_SEARCH: JAVDB_RESULTS, JAVDB_DETAIL: JAVDB_PAGE}, "ABW-358"), expected)
record = JavDBSource().parse(Page("https://javdb.com/v/Zb7mX", JAVDB_PAGE), "ABW-358")
self.assertEqual((record.source, record.provenance, record.code), ("javdb", "javdb-page", "ABW-358"))
diff --git a/tests/test_genre_taxonomy.py b/tests/test_genre_taxonomy.py
index d9691b0d1..2118dc86a 100644
--- a/tests/test_genre_taxonomy.py
+++ b/tests/test_genre_taxonomy.py
@@ -437,7 +437,7 @@ class VocabularyHygieneTests(unittest.TestCase):
(("ドキュメンタリー", "Documentary"), "纪录片"),
(("イメージビデオ", "Image Video", "グラビア"), "写真映像"),
(("痴漢", "Molester", "Groping"), "痴汉"),
- (("妊婦", "Pregnant"), "孕妇"),
+ (("妊婦", "妊娠", "Pregnant"), "孕妇"),
(("巨根", "Big Cock", "デカチン"), "巨根"),
(("放尿", "Peeing", "おしっこ"), "放尿"),
(("黒人", "Black Guy"), "黑人"),
@@ -532,11 +532,11 @@ class Fc2SellerTagTests(unittest.TestCase):
def test_words_the_catalog_has_no_slot_for_stay_on_the_review_page(self):
"""词表里没有对应一格、或者含义还没查清的词,留给人判。
- `神乳` 剥掉夸法只剩「乳」这一级,和 `おっぱい` 同理;受孕那一簇说的是内射到怀孕的
- 题材,`孕妇` 说的是出镜时已经怀孕,两边不是一回事;`Iカップ` 是尺寸;`ハイレグ` 既可能是
+ `神乳` 剥掉夸法只剩「乳」这一级,和 `おっぱい` 同理;`孕ませ`、`排卵`、`種付け` 说的是
+ 受孕相关题材,不等同于 `孕妇` 表达的怀孕状态;`Iカップ` 是尺寸;`ハイレグ` 既可能是
泳装也可能是体操服;`モザ` 在一部已判无码的片子上出现,是半个词。
"""
- for word in ("神乳", "妊娠", "孕ませ", "排卵", "種付け", "Iカップ", "ハイレグ", "モザ"):
+ for word in ("神乳", "孕ませ", "排卵", "種付け", "Iカップ", "ハイレグ", "モザ"):
with self.subTest(word=word):
self.assertEqual(resolve_genre(word), UNMAPPED)
diff --git a/tests/test_scripts.py b/tests/test_scripts.py
index b5f6fb620..d61d309f4 100644
--- a/tests/test_scripts.py
+++ b/tests/test_scripts.py
@@ -3271,9 +3271,9 @@ class OperationalScriptTests(unittest.TestCase):
from peach.repository import LedgerDatabase
with tempfile.TemporaryDirectory() as tmp:
- root = Path(tmp)
+ root = Path(tmp).resolve()
db = self._chain_ledger(root, ["ABW-220"])
- with sqlite3.connect(db) as con:
+ with closing(sqlite3.connect(db)) as con, con:
con.execute("UPDATE asset SET name='ABW-220.mp4',path='ABW-220.mp4',"
"catalog_title='Catalog title',studio='Studio A',release_date='2020-09-13'")
con.execute("INSERT INTO asset_tag(asset_id,tag,confidence,source) "
@@ -3314,7 +3314,7 @@ class OperationalScriptTests(unittest.TestCase):
self.assertEqual(tags["current_value"], "肛交")
self.assertEqual(json.loads(tags["candidates_json"])[0]["source"], "javdb")
self.assertGreaterEqual(auto_apply_metadata(LedgerDatabase(db), candidate_root)["applied"], 1)
- with sqlite3.connect(db) as con:
+ with closing(sqlite3.connect(db)) as con:
self.assertEqual(set(con.execute("SELECT tag,source FROM asset_tag WHERE asset_id=1"
" AND tag NOT LIKE '演员:%'")),
{("高跟", "javinizer:javdb:tag"), ("丝袜", "javinizer:javdb:tag")})