Peach: Local-first video metadata scraper and media manager.
fix(follow): rule34.paheal 列表按 data-mime 认出视频帖
longmeidaob834e7ba7469
diff --git a/src/peach/follow_sources.py b/src/peach/follow_sources.pyindex 791bf3cb9..6b974adb9 100644--- a/src/peach/follow_sources.py+++ b/src/peach/follow_sources.py@@ -1797,7 +1797,11 @@ class Rule34PahealConnector(_BaseConnector):出处抹掉。"""tags = str(thumb.get("data-tags") or "").split()+ # 列表缩略图有两种写法:归档里早期的页面给扩展名 `data-ext='mp4'`,+ # 现在的页面给 MIME `data-mime='video/mp4'`,两种都认。extension = str(thumb.get("data-ext") or "").casefold()+ mime = str(thumb.get("data-mime") or "").casefold()+ video = extension in {"mp4", "webm", "mov"} or mime.startswith("video/")link = thumb.select_one("a.shm-thumb-link[href]")file_link = thumb.select_one("a[href*='paheal-cdn.net'], a[href*='r34i.paheal']")image = thumb.select_one("img[src]")@@ -1814,8 +1818,7 @@ class Rule34PahealConnector(_BaseConnector):title_is_name=False,partial=True,extra={"tag": tag, "tags": " ".join(tags), "title_from": "tags",- "media_kind": "video" if extension in {"mp4", "webm", "mov"}- else "image",+ "media_kind": "video" if video else "image","tag_types": {value: "general" for value in tags}},)diff --git a/tests/test_follow_sources.py b/tests/test_follow_sources.pyindex bc52847a5..cb866135e 100644--- a/tests/test_follow_sources.py+++ b/tests/test_follow_sources.py@@ -587,6 +587,20 @@ class Rule34PahealConnectorTests(unittest.TestCase):"https://r34i.paheal-cdn.net/df/fb/video")self.assertFalse(item.title_is_name)+ def test_list_thumb_media_kind_reads_extension_or_mime(self):+ """视频帖在图片视图里没有图片尺寸可占位,判成图片就混进瀑布流。"""+ listing = b"""<div class='shm-image-list'>+<div class='shm-thumb thumb' data-ext='mp4' data-tags='initiala' data-post-id='1'></div>+<div class='shm-thumb thumb' data-mime='video/mp4' data-tags='initiala' data-post-id='2'></div>+<div class='shm-thumb thumb' data-mime='image/jpeg' data-tags='initiala' data-post-id='3'></div>+</div>"""+ connector = Rule34PahealConnector(transport=_routed(+ lambda request: HttpResponse(+ 200, {}, PAHEAL_DETAIL_HTML if "/post/view/" in request.url else listing)))+ kinds = {item.external_id: item.extra["media_kind"]+ for item in connector.fetch("initiala").candidates}+ self.assertEqual(kinds, {"1": "video", "2": "video", "3": "image"})+def test_backfill_404_means_history_is_exhausted(self):connector = Rule34PahealConnector(transport=_transport(status=404))with self.assertRaises(FollowHistoryEnd):