Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(follow): 详情反复打不开、关闭重取、归档站封面全空、版本数少一个

longmeidao9cb6d08d11ab
diff --git a/docs/reference-snapshots/kemono-archive-media-host.md b/docs/reference-snapshots/kemono-archive-media-host.md
new file mode 100644
index 000000000..3142d2682
--- /dev/null
+++ b/docs/reference-snapshots/kemono-archive-media-host.md
@@ -0,0 +1,51 @@
+# 归档站静态资源主机实测
+
+- 取证日期:2026-08-30
+- 取证方式:`curl` 带常规浏览器 UA,无 Referer,记录状态码、`content-type` 与字节数;
+ 不跟随重定向以外的处理,不带任何凭据
+- **不登记进 `docs/reference-sources.json`**:那张表要求每个来源有可哈希的上游快照,
+ 这里记的是「哪个主机能取到静态资源」,站点改版就会变。复核就按下面的方式重测。
+
+## 起因
+
+关注页上 pawchive 的卡片一律没有封面,详情里的媒体也是空白。前端对封面用
+`onerror="this.remove()"`,所以取不到时表现为「没有预览图」,看不出是 404 还是防盗链。
+
+## 实测
+
+同一份路径分别请求主域与 `img.` 子域:
+
+| URL | 状态 | content-type | 字节 |
+| --- | --- | --- | --- |
+| `kemono.cr/thumbnail/data/7e/6b/<hash>.jpg` | 302 | text/html | 138 |
+| `img.kemono.cr/thumbnail/data/7e/6b/<hash>.jpg` | **200** | image/jpeg | 24,050 |
+| `pawchive.pw/thumbnail/data/3f/9c/<hash>.gif` | 404 | text/html | 207 |
+| `img.pawchive.pw/thumbnail/data/3f/9c/<hash>.gif` | **200** | image/gif | 12,796 |
+
+结论:**两站的静态资源都应走 `img.` 子域。**kemono 主域只是重定向,浏览器跟随之后
+仍能显示,所以这个问题在 kemono 上看不出来;pawchive 主域直接 404,卡片因此永远是空的。
+
+`follow_sources.py` 里原来那条注释记的是 2026-08-27 主域回 200 `image/jpeg`——
+站点行为在这三天里变了。**这类"当前哪个主机能取到"的结论必须带日期,并且会过期。**
+
+## 未取得
+
+pawchive 的**原始媒体**(`media_url`,非缩略图)正确形式未取得。已测且全部 404:
+
+ pawchive.pw/<path>
+ pawchive.pw/data/<path>
+ img.pawchive.pw/<path>
+ img.pawchive.pw/data/<path>
+
+只有 `img.pawchive.pw/thumbnail/data/<path>` 可用,那是缩略图路径。原始文件可能需要
+从帖子页另取链接,或者需要会话。**没有猜测代入**:详情里的媒体在拿到确证之前仍会失败,
+不用缩略图冒充原图。
+
+## 复核方式
+
+```bash
+curl -s -o /dev/null -w "%{http_code} %{content_type} %{size_download}\n" \
+ -A "Mozilla/5.0" "https://img.pawchive.pw/thumbnail/data/<path>"
+```
+
+`<path>` 取自 `follow_item.thumb_url` 里 `/thumbnail/data` 之后的部分。
diff --git a/src/peach/follow_sources.py b/src/peach/follow_sources.py
index 22b1efd1c..1afb0cd44 100644
--- a/src/peach/follow_sources.py
+++ b/src/peach/follow_sources.py
@@ -622,17 +622,20 @@ class KemonoConnector(_BaseConnector):
def _thumb_url(self, media: str | None) -> str | None:
"""归档站的封面。
- 2026-08-27 实测:`https://kemono.cr/thumbnail/data<path>` 与
- `https://img.kemono.cr/thumbnail/data<path>` 都回 200 `image/jpeg`
- (同一张 35,387 字节的图);换成 `/data<path>` 则是 404,所以这个
- `thumbnail/` 前缀是必需的,不是可选的美化。
+ `thumbnail/` 前缀是必需的,不是可选的美化:换成 `/data<path>` 是 404。
+
+ **主机用 `img.` 子域。**2026-08-30 实测(取证见
+ `docs/reference-snapshots/kemono-archive-media-host.md`):主域
+ `kemono.cr` 只回 302,`pawchive.pw` 直接 404,两者的 `img.` 子域都回 200。
+ 2026-08-27 那次记的是主域回 200——站点行为后来变了,pawchive 的卡片因此
+ 一直是空的。
以前这里根本没设 `thumb_url`,归档站的卡片因此一律没有封面——
不是取不到,是压根没去取。
"""
if not media or not str(media).lower().endswith(self._THUMBABLE):
return None
- return f"https://{self.host}/thumbnail/data{media}"
+ return f"https://img.{self.host}/thumbnail/data{media}"
def _candidate(self, post: dict, service: str, user: str) -> FollowCandidate:
post_id = str(post.get("id") or "")
@@ -640,13 +643,21 @@ class KemonoConnector(_BaseConnector):
page = f"https://{self.host}/{service}/user/{user}/post/{post_id}" if post_id else None
primary = post.get("file") if isinstance(post.get("file"), dict) else {}
attachments = [a for a in (post.get("attachments") or []) if isinstance(a, dict)]
- media = primary.get("path") or (attachments[0].get("path") if attachments else None)
+ paths = [primary.get("path"), *(item.get("path") for item in attachments)]
+ # 交付文件优先取**非图片**的那个。作者常把 gif 预览放在 `file` 位、真正的
+ # mp4 放进附件——2026-08-30 实测 pawchive `patreon/user/80149692/post/166107691`:
+ # file 是 TFCLASSIC01.gif,附件里才是两个 1080p mp4。按 `file.path` 优先会把
+ # 整条判成图片,两个正片直接不见,卡片也进不了「视频」那个页签。
+ media = next((path for path in paths
+ if path and not str(path).lower().endswith(self._THUMBABLE)), None)
+ if media is None:
+ media = primary.get("path") or (attachments[0].get("path") if attachments else None)
# 正片/压缩包仍是主要资源;封面则要从所有附件里另找第一张图片。
# 过去把两件事绑在同一个 `media` 上,主文件只要是 mp4/zip,后面明明附了
# jpg 也会显示「没有预览图」。
- preview = next((path for path in (
- primary.get("path"), *(item.get("path") for item in attachments)
- ) if path and str(path).lower().endswith(self._THUMBABLE)), None)
+ # 封面仍从所有路径里找第一张图片:正片是 mp4 时,那张 gif/jpg 预览就是封面。
+ preview = next((path for path in paths
+ if path and str(path).lower().endswith(self._THUMBABLE)), None)
return FollowCandidate(
provider=self.provider,
external_id=post_id or stable_id(title, str(post.get("published"))),
diff --git a/src/peach/web_follow.py b/src/peach/web_follow.py
index 2e86ab41c..46dc5d798 100644
--- a/src/peach/web_follow.py
+++ b/src/peach/web_follow.py
@@ -154,6 +154,29 @@ def _media_items(item) -> list[dict]:
return result
+def _archive_media_host(provider: str, url: str) -> str:
+ """把归档站的静态资源指到 `img.` 子域。
+
+ 2026-08-30 实测(见 docs/reference-snapshots/kemono-archive-media-host.md):
+
+ kemono.cr/thumbnail/data/<path> 302
+ img.kemono.cr/thumbnail/data/<path> 200 image/jpeg 24,050 B
+ pawchive.pw/thumbnail/data/<path> 404
+ img.pawchive.pw/thumbnail/data/<path> 200 image/gif 12,796 B
+
+ kemono 主域只是重定向,浏览器跟随后仍能显示,所以一直没人发现;pawchive 主域
+ 直接 404,卡片因此永远是空的(`onerror` 把 img 摘掉,看起来像"没有预览图")。
+ 连接器里那条注释记的是 2026-08-27 主域回 200——站点行为后来变了。
+
+ 在读取时改写而不是改 ledger:坏 URL 已经写进两千多行,而这是可推导的投影,
+ 不是真相字段。站点再变时也只需要改这一处。
+ """
+ host = KemonoConnector.HOSTS.get(provider)
+ if not host or not url.startswith(f"https://{host}/"):
+ return url
+ return url.replace(f"https://{host}/", f"https://img.{host}/", 1)
+
+
def _thumb_url(item) -> str | None:
# rule34.xxx 的历史行存的是 250px preview。官方 dapi 的 sample_url 与它使用
# 同一 bucket/hash;2026-08-28 对生产历史行实测推导后为 1920x1080。
@@ -171,13 +194,15 @@ def _thumb_url(item) -> str | None:
if kind == "video":
return f"/follow-cover?id={item.id}"
if item.thumb_url:
- return item.thumb_url
+ return _archive_media_host(item.provider, str(item.thumb_url))
# 旧的 Kemono/Pawchive 行在封面修复前已入库:media_url 是图片,但 thumb_url
# 为空。按连接器同一条已验证规则即时推导缩略图,不改 ledger 就能补齐旧卡片。
if item.provider in KemonoConnector.HOSTS and _IMAGE_MEDIA_RE.search(
str(item.media_url or "")):
parsed = urllib.parse.urlsplit(str(item.media_url))
- return f"https://{KemonoConnector.HOSTS[item.provider]}/thumbnail/data{parsed.path}"
+ return _archive_media_host(
+ item.provider,
+ f"https://{KemonoConnector.HOSTS[item.provider]}/thumbnail/data{parsed.path}")
return None
diff --git a/tests/test_follow_sources.py b/tests/test_follow_sources.py
index 5774abbe8..6f6df9a59 100644
--- a/tests/test_follow_sources.py
+++ b/tests/test_follow_sources.py
@@ -390,7 +390,10 @@ class KemonoConnectorTests(unittest.TestCase):
self.assertEqual(first.published_at, "2026-02-14T21:51:10Z")
self.assertEqual(first.url,
"https://kemono.cr/fanbox/user/30917150/post/11406814")
- self.assertEqual(first.media_url, "https://kemono.cr/1c/fa/1cfae7.png")
+ # 交付文件取非图片的那个:夹具里 file 是 a.png、附件是 a.zip,压缩包才是正片。
+ # 按 file.path 优先会把整条判成图片——pawchive 上作者用 gif 当预览、mp4 放附件,
+ # 正是这条路径让两个 1080p 正片消失(2026-08-30 取证)。
+ self.assertEqual(first.media_url, "https://kemono.cr/1c/fa/1cfae7.zip")
self.assertEqual(first.extra["attachment_count"], 1)
# post id 就是原平台的 post id,和别的站点从 source 归一出的键同一个命名空间。
self.assertEqual(first.group_hint, "fanbox:11406814")
@@ -398,12 +401,12 @@ class KemonoConnectorTests(unittest.TestCase):
def test_archive_posts_get_a_cover_thumbnail(self):
"""归档站的卡片以前一律没有封面——不是取不到,是压根没去取。
- 2026-08-27 实测 `https://kemono.cr/thumbnail/data<path>` 回 200 `image/jpeg`;
+ 2026-08-30 实测缩略图走 `img.` 子域:主域 kemono.cr 回 302、pawchive.pw 回 404;
去掉 `thumbnail/` 前缀则是 404,所以这个前缀是必需的。
"""
result = KemonoConnector(transport=_transport(body=KEMONO_POSTS)).fetch("fanbox/1")
self.assertEqual(result.candidates[0].thumb_url,
- "https://kemono.cr/thumbnail/data/1c/fa/1cfae7.png")
+ "https://img.kemono.cr/thumbnail/data/1c/fa/1cfae7.png")
def test_archive_video_uses_an_image_attachment_as_its_cover(self):
"""主资源是视频/压缩包时,后附的图片仍然是可用封面。"""
@@ -421,7 +424,7 @@ class KemonoConnectorTests(unittest.TestCase):
candidate = result.candidates[0]
self.assertEqual(candidate.media_url, "https://kemono.cr/video/release.mp4")
self.assertEqual(candidate.thumb_url,
- "https://kemono.cr/thumbnail/data/cover/release.webp")
+ "https://img.kemono.cr/thumbnail/data/cover/release.webp")
def test_no_thumbnail_is_offered_for_things_that_have_none(self):
# 视频和压缩包没有缩略图,给了也是 404——那会让卡片显示一张碎图,
diff --git a/tests/test_follow_web.py b/tests/test_follow_web.py
index 06e363ff6..075b1279a 100644
--- a/tests/test_follow_web.py
+++ b/tests/test_follow_web.py
@@ -317,7 +317,7 @@ class FollowContractTests(unittest.TestCase):
),), provider="kemono", ref="fanbox/1")
item = self._get()["groups"][0]["primary"]
self.assertEqual(
- item["thumb_url"], "https://kemono.cr/thumbnail/data/ab/cd/image.jpg")
+ item["thumb_url"], "https://img.kemono.cr/thumbnail/data/ab/cd/image.jpg")
self.assertEqual(item["media_kind"], "image")
self.assertTrue(item["playable"])
@@ -419,6 +419,34 @@ class FollowContractTests(unittest.TestCase):
self._seed()
self.assertEqual(len(self._get(limit="nope")["groups"]), 1)
+ def test_archive_thumbnails_use_the_img_subdomain(self):
+ """归档站静态资源走 img. 子域,主域取不到。
+
+ 2026-08-30 实测:kemono.cr 回 302、pawchive.pw 回 404,两者的 img. 子域都回
+ 200(取证见 docs/reference-snapshots/kemono-archive-media-host.md)。kemono
+ 主域因为是重定向、浏览器跟随后仍能显示,所以只有 pawchive 的卡片一直是空的。
+
+ 改写发生在读取时:坏 URL 已经写进两千多行,而这是可推导的投影不是真相字段。
+ """
+ from peach.web_follow import _archive_media_host
+
+ for provider, host in (("kemono", "kemono.cr"), ("pawchive", "pawchive.pw"),
+ ("coomer", "coomer.st")):
+ self.assertEqual(
+ _archive_media_host(provider, f"https://{host}/thumbnail/data/a/b/c.jpg"),
+ f"https://img.{host}/thumbnail/data/a/b/c.jpg",
+ )
+ # 已经是 img. 的不再叠加
+ self.assertEqual(
+ _archive_media_host(provider, f"https://img.{host}/thumbnail/data/a/b/c.jpg"),
+ f"https://img.{host}/thumbnail/data/a/b/c.jpg",
+ )
+ # 别的站点原样返回,不要顺手改写
+ self.assertEqual(_archive_media_host("rule34video", "https://rule34video.com/a.jpg"),
+ "https://rule34video.com/a.jpg")
+ self.assertEqual(_archive_media_host("kemono", "https://example.test/a.jpg"),
+ "https://example.test/a.jpg")
+
def test_counts_are_whole_library_while_groups_are_one_page(self):
"""计数是全库口径,列表只有一页——界面并排显示这两个数时看起来像自相矛盾。
@@ -1614,7 +1642,17 @@ class FollowWebSourceTests(unittest.TestCase):
self.assertPageContains("'(仅附件)'")
def test_thread_activity_is_not_called_a_version(self):
- self.assertPageContains("group.is_release?`${group.variants.length+1} 条动态`")
+ """线程动态叫「条动态」,作品版本叫「个版本」,两者都含主条目。
+
+ 计数以前是分开写的:release 记 `variants.length+1`、work 记 `variants.length`。
+ 同一份数据两种口径,两个视频的组会显示成「1 个版本」。现在共用一个表达式,
+ 只有量词不同。
+ """
+ self.assertPageContains(
+ "`${group.variants.length+1} ${group.is_release?'条动态':'个版本'}`")
+ self.assertPageLacks(
+ "`${group.variants.length} 个版本`",
+ "版本数必须含主条目,否则两个视频显示成 1 个版本")
def test_cross_site_duplicates_are_shown_as_another_source(self):
self.assertPageContains("另见 ")
diff --git a/web/app.js b/web/app.js
index 3fc42ebff..483173969 100644
--- a/web/app.js
+++ b/web/app.js
@@ -2301,7 +2301,9 @@ function followBadges(group){
if(group.has_wip)badges.push('<span class="fbadge wip">WIP</span>');
if(group.primary.version)badges.push(`<span class="fbadge ver">${esc(group.primary.version)}</span>`);
if(group.variants.length)badges.push(`<span class="fbadge">${
- group.is_release?`${group.variants.length+1} 条动态`:`${group.variants.length} 个版本`}</span>`);
+ // 两个分支都含主条目:以前 release 记 +1、work 不记,同一份数据两种口径,
+ // 两个视频的组会显示成「1 个版本」。
+ `${group.variants.length+1} ${group.is_release?'条动态':'个版本'}`}</span>`);
if(group.duplicates.length)badges.push(`<span class="fbadge dup">另见 ${
esc([...new Set(group.duplicates.map(d=>d.provider_label))].join('、'))}</span>`);
return badges.join('');
@@ -2406,9 +2408,14 @@ function followEmbeddedQueueHtml(item,mediaIndex){
}).join('')}</div></aside>`;
}
-function indexFollowItems(data){
+/* 重建条目索引。`merge` 时只往里加,不清空已有的。
+
+ 单条查询(followItemById)以前也走整表重建,于是点一个不在索引里的条目会把索引
+ 替换成只剩那一条;再点别的又没有、又替换。列表能翻页之后这条路径被踩得很频繁,
+ 表现就是「多点几次详情就打不开了」。 */
+function indexFollowItems(data,{merge=false}={}){
const groups=data?.groups||[];
- followItemsById=new Map();followGroupByItemId=new Map();
+ if(!merge){followItemsById=new Map();followGroupByItemId=new Map()}
groups.forEach(group=>followCollectionItems(group).forEach(item=>{
followItemsById.set(item.id,item);followGroupByItemId.set(item.id,group)}));
}
@@ -2417,7 +2424,7 @@ async function followItemById(id){
if(followItemsById.has(id))return followItemsById.get(id);
const data=await api(`/api/follow?item=${encodeURIComponent(id)}`);
if(!followData)followData=data;
- indexFollowItems(data);
+ indexFollowItems(data,{merge:true});
return followItemsById.get(id);
}
@@ -2487,7 +2494,14 @@ async function openFollowDetail(id,push=true,mediaIndex=null,preserveReturn=fals
</div></div></div>`;
$('#stage').classList.toggle('ambient-on',selectedKind==='video'&&appSettings.ambientMode);
$('#stage').classList.toggle('theater-mode',selectedKind==='video'&&appSettings.theaterMode);
- const closeDetail=async()=>{disposeStage(false);route(followDetailReturnPath||'/follow');await openFollow(false)};
+ /* 关掉详情只是回到列表,不该重新取一遍。重取要等一个网络往返(慢),而且只会
+ 取回第一页——「加载更多」出来的条目会连同索引一起消失,那些卡片的详情随后
+ 就打不开了。列表数据还在 followData 里,直接重画。 */
+ const closeDetail=async()=>{
+ disposeStage(false);
+ route(followDetailReturnPath||'/follow');
+ if(followData)renderFollow();else await openFollow(false);
+ };
$('#closeStage').onclick=closeDetail;
$('#stage').querySelectorAll('[data-follow-queue-close]').forEach(button=>button.onclick=closeDetail);
$('#stage').querySelectorAll('[data-follow-queue-item]').forEach(button=>button.onclick=()=>