Skip to content

armgit / peach

Public Imported from GitHub
0

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

feat(scraping): 抓取默认 UA 换成用户浏览器的 Chrome 153,同主机 http 跳转升回 https

longmeidaobd60dbfd7833
diff --git a/docs/REUSE.md b/docs/REUSE.md
index 5f7741836..aee568b51 100644
--- a/docs/REUSE.md
+++ b/docs/REUSE.md
@@ -345,7 +345,7 @@ Python、npm 与 GitHub Actions 的版本由 `.github/dependabot.yml` 每周检
只复用成功日志的精确 URL。MDC-NG 公共仓库只证明 Amazon 日本渠道存在,后端匹配逻辑未公开,故只留
POC 候选。该流程不新增依赖、不写 ledger,操作步骤见 `peach-jav-cover-workflow`。
-- 对外请求的 UA 统一取 `peach.user_agent.USER_AGENT`(标准桌面 Chrome);HTTPX、来源连接器、FFmpeg 抽帧与脚本共用。复用现有 transport、限速和证书校验,无新增依赖;标准 UA 不保证站点放行。FANBOX 浏览器传输使用已安装 curl_cffi 的 Chrome 150 配置。
+- 对外请求的 UA 统一取 `peach.user_agent.USER_AGENT`(与用户这台机器的 Chrome 同大版本,ADR-0060);HTTPX、来源连接器、FFmpeg 抽帧与脚本共用。复用现有 transport、限速和证书校验,无新增依赖;标准 UA 不保证站点放行。FANBOX 浏览器传输使用已安装 curl_cffi 的 Chrome 150 配置。
- 整张作品封面不装成头像:单人作品关联不证明画面中的人物身份,`cover_fallback` 显式标记身份未核实,采集脚本的安装闸门拒绝这类来源。图库给不出唯一人像时,补头像后继(`peach.avatar_followup`)从单人作品封面截脸周围一块方图(`peach.avatar_cover_face`,YuNet 脸框放大 2.4 倍),按脸宽像素挑封面,最差是缩略图;其余检得出脸的封面各截一张进候选缓存(至多 8 张),挑图弹层里一点就换。面具、眼罩照样算脸,检不出的不降门槛去捞:低分框多落在手和身体上。来源记 `cover-face` 与 `identity_verified: false`。图库同名多张时先按脸认人(`peach.face_match`,ADR-0056;一张参照截错人时,两张不同照片与另一张参照三方互证也算,ADR-0057),认不出才截封面。整张封面装的旧头像和截过的脸遇到更宽的脸自动替换,图库装的与人挑的不碰。头像选择器的作品组按封面像素面积排序。
- 复核页面上下文复用原生 CSS sticky、主导航 `--topH` 与既有滚动/尺寸调度,分类及筛选栏合为同一吸附区,分组标题按实测栏高接续吸附。仅吸附时显示通栏背景,全选本组紧邻标题;桌面、手机、换组、尺寸变化及返回顶部均用隔离候选验证。卡片以 flex 分开标题、既有 Scroller、当前信息和操作;只有资料滚动,当前信息过长时可聚焦滚动阅读。多选计数共用 `selectiondockcount`,保留首页的文字口径;不新增依赖,不改变候选与提交协议。
- 复核分类复用 `selectFieldHtml`、`wireSelectField` 和现有 `list-filter` 图标;图标只在筛选入口显示,选项保留文字与选中标记。按当前候选数据提供字段及来源选项,批量决定复用既有协议。字段次级分类采用具名 Listbox 分区,依据见 `reference-snapshots/vercel-review-actions.md`。人工复核与馆藏、关注、标签、垃圾文件和回收站共用 `selectiondock` 浮窗布局,保留各自操作与提交协议;复核卡片内作品样本选择仍属于单条候选,不混入页面级多选。没有新增依赖。Shift 连选使用原生 `mousedown.preventDefault()` 防止文字选区;实际浏览器验证覆盖亮暗主题、宽屏和 390px。
diff --git a/docs/SOURCING.md b/docs/SOURCING.md
index fb2f8a65b..4fd65630f 100644
--- a/docs/SOURCING.md
+++ b/docs/SOURCING.md
@@ -226,9 +226,10 @@ r18.dev 对 85 个 FC2 番号全空,AVBase 与 JavBus 对本地这批一律「
站上的中文是机器翻译(用户判定),只收日文原页,`og:url` 带 `/tw/`、`/en/`、`/ko/` 归 `parse_error`。
- 这两站都在 Cloudflare 的 JS 验证后面:httpx 与模拟 Chrome 指纹的 curl_cffi 直连都回 403、标题
`Just a moment...`(`sources.base.challenge_page`),只有浏览器过完验证发下的 `cf_clearance` 能进,而它绑着
- 解题那台浏览器的 User-Agent 与出口 IP。所以「来源和凭证」里这两张卡除 Cookie 外还收浏览器 User-Agent
- (`scraping_access.SOURCES[...]['user_agent']`),请求头照它发,连接方式要选与那台浏览器同一个出口。
- 没配或过期时回 403,按 `blocked_pause` 整站冷却(15 分钟起翻倍到 6 小时),链照常往下走;保存新 Cookie 清冷却。
+ 解题那台浏览器的 User-Agent 与出口 IP。整站 UA(`peach.user_agent.USER_AGENT`)与用户这台机器的 Chrome
+ 保持一致,Chrome 大版本升了就改那一处;「来源和凭证」里这两张卡只收 Cookie,连接方式要选与那台浏览器
+ 同一个出口。没配或过期时回 403,按 `blocked_pause` 整站冷却(15 分钟起翻倍到 6 小时),链照常往下走;
+ 保存新 Cookie 清冷却。JAVten 搜索一跳的 Location 是 `http://`,HTTP 层把同主机的明文跳转升回 https 再带 Cookie 去。
- 几处都没有的落到 JavArchive。它的作品地址里夹着站内文章号和标题(`/926949-FC2-PPV-4137487-…-pn.html`),
拼不出来,所以先问 `/search?q=<番号>` 再取那一条作品页;商品号按数字边界比,`4137487` 不能
命中 `41374870`。搜索结果只有标题和一张缩略图,作品页才有标签、发行日、时长和封面位,所以这一跳
diff --git a/docs/adr/0060-fc2-archives-behind-cloudflare-take-the-browser-cookie.md b/docs/adr/0060-fc2-archives-behind-cloudflare-take-the-browser-cookie.md
index 82dca6c4e..d43bb62f8 100644
--- a/docs/adr/0060-fc2-archives-behind-cloudflare-take-the-browser-cookie.md
+++ b/docs/adr/0060-fc2-archives-behind-cloudflare-take-the-browser-cookie.md
@@ -1,4 +1,4 @@
-# ADR-0060:FC2 链接上 FC2PPV-DB 与 JAVten,Cloudflare 后面的站用浏览器的 Cookie 与 User-Agent 进
+# ADR-0060:FC2 链接上 FC2PPV-DB 与 JAVten,Cloudflare 后面的站用浏览器的 Cookie 进
- 状态:Accepted
- 日期:2026-09-24
@@ -21,6 +21,7 @@ javten.com(fc2hub.com 的后继,OpenAver issue #186 的 FC2 刮削经验点
| 给什么 | 女优(链到站内女优页)、卖家(slug 与发行方用户页同名)、販売日、タグ、時長、「流出あり/なし」 | 日文标题、标签、卖家名、時長、販売日(`videos:published_time`)、FC2 存储原件封面地址两处 |
| 封面 | 360×360 的 CloudFront 缩略图(`og:image:width` 写 800,实测 360),不合封面最低宽度 | `storage*.contents.fc2.com` 原件,与发行方商品页同一文件,下架后可能已删 |
| 没有 | 回 200 的 404 页,`<h1>` 写 `404` | 搜索结果里没有 `id<号>` 那一条 |
+| 跳转 | 无 | 搜索单命中 302 的 Location 写成 `http://`,且带着用户会话时落到用户上次选的语言版(`/tw/`) |
| 语言 | 日文原页 `/ja/` | 有 `/tw/`、`/en/`、`/ko/` 译文版,中文是机器翻译(用户判定) |
| 演员 | `FC2-PPV-4898837` 写 `川北すずね`,日文原名 | 不给演员 |
@@ -37,17 +38,18 @@ Cloudflare 验证页由 `sources.base.challenge_page` 认,归 `cloudflare_chal
排在 fc2cmadb 之后、javdb 之前。
**三、JAVten 只收日文原页。** `fetch` 只取不带语言前缀的地址,落到译文页再取原页;`parse` 见 `og:url` 带语言前缀
-归 `parse_error`,不把机翻写进标题。
+归 `parse_error`,不把机翻写进标题。搜索那一跳的 Location 是 `http://`:`HttpxTransport` 跟跳时把同主机的
+`http://` 升回 `https://`(浏览器靠 HSTS 做同一件事),否则 Secure 的 `cf_clearance` 不随明文地址发出,
+Cookie 对了也回验证页。只升不降,换了主机的明文地址仍按跨源丢凭据。
**四、FC2PPV-DB 不交封面。** 缩略图连最低宽度都过不了,交下去只是白花一次请求;封面留给链上前后指着存储原件的几档。
「流出」标记进 `extra['leaked']`,只作证据,不投影到账本字段。
-**五、来源设置加浏览器 User-Agent。** `scraping_access.SOURCES` 里这两站 `cookie`、`session`、`user_agent` 三样都收,
-`blocked_pause` 6 小时。`save` 存 `user_agent`(压空白、512 字符上限,不收的来源报错);`describe` 回
-`accepts_user_agent` 与明文 `user_agent`;`client_for` 的默认头与 `SourceTransport._request` 都把请求头的 UA 换成
-用户存的那一个(调用方在 `_fetch` 里写的是整站 UA,会压过 client 默认头,所以要在传输层换)。
-保存新 Cookie 时清掉该来源的冷却:冷却记的是旧 Cookie 撞出来的账。403 时的暂停措辞指向「更新 Cookie 与浏览器
-User-Agent」。「来源和凭证」页在收 UA 的卡上多一个明文输入框。
+**五、UA 走整站那一份,不按来源另收。** `cf_clearance` 绑着解题那台浏览器的 UA,但 Peach 是单人自托管应用,
+浏览器就是用户这一台 Chrome:`peach.user_agent.USER_AGENT` 按它的 `chrome://version` 定(2026-09-24 为
+Chrome 153),Chrome 大版本升了就改那一处,全部对外请求一起换。用户的判据是「不要我单独输 UA」。
+`scraping_access.SOURCES` 里这两站收 `cookie`、`session`,`blocked_pause` 6 小时;保存新 Cookie 时清掉该来源的
+冷却:冷却记的是旧 Cookie 撞出来的账。收 Cookie 的来源 403 时的暂停措辞指向「更新它的 Cookie」。
**六、bigboobs.pink 不接。** 可直接抓(WordPress,无 Cloudflare),但只有按女优聚合的文章,没有 FC2 号入口,
作女优别名与作品聚合的参考,不进链。
@@ -58,5 +60,6 @@ User-Agent」。「来源和凭证」页在收 UA 的卡上多一个明文输入
链照常往下走,不影响别的档。
- `cf_clearance` 有效期短(站方一般数小时到一天),过期就要用户重新贴。这是这两站的固有成本,不是 Peach 的缺陷;
自动过验证(无头浏览器、第三方解题服务)不做。
-- UA 与 Cookie 必须来自同一台浏览器,连接方式必须选与那台浏览器同一个出口;配错的表现是 Cookie 对了仍 403。
+- Cookie 必须来自 UA 所指的那台 Chrome,连接方式必须选与它同一个出口;Chrome 升了大版本而 `USER_AGENT` 没跟上,
+ 表现是 Cookie 对了仍 403。
- 演员栏多一处日文原名来源;两站的女优名不一致时按现有的候选与复核流程处理。
diff --git a/frontend/e2e/design.test.ts b/frontend/e2e/design.test.ts
index c58d8392f..73dd17d7d 100644
--- a/frontend/e2e/design.test.ts
+++ b/frontend/e2e/design.test.ts
@@ -92,7 +92,6 @@ async function openQualityGoals(browser: Browser, items: unknown[]): Promise<Vis
const scrapingSource = (source: string, label: string, cookie: boolean) => ({
source, label, login: `https://${source}.example/login`,
accepts_cookie: cookie, network: 'peach', cookie_saved: cookie,
- accepts_user_agent: false, user_agent: '',
});
/** 来源和凭证页按给定的一份 `/api/scraping` 打开:演示库里未必同时有收 Cookie 和不收的来源。
diff --git a/frontend/src/react/scraping/scraping-page.tsx b/frontend/src/react/scraping/scraping-page.tsx
index bd86e3fad..1457ede28 100644
--- a/frontend/src/react/scraping/scraping-page.tsx
+++ b/frontend/src/react/scraping/scraping-page.tsx
@@ -59,7 +59,6 @@ function SourceCard({ source, toast }: { source: Source } & ScrapingProps) {
const [network, setNetwork] = useState(source.network);
const [cookie, setCookie] = useState('');
const [cookieText, setCookieText] = useState('');
- const [userAgent, setUserAgent] = useState(source.user_agent);
const [method, setMethod] = useState<string>(COOKIE_METHODS[0][0]);
const [fileName, setFileName] = useState('');
const [fileProblem, setFileProblem] = useState('');
@@ -78,7 +77,6 @@ function SourceCard({ source, toast }: { source: Source } & ScrapingProps) {
const save = useMutation({
mutationFn: (revoke: boolean) => apiSend<{ saved: Source }>(SCRAPING_SETTINGS_URL, {
source: source.source, network, cookie, cookies_text: cookieText, revoke,
- ...(source.accepts_user_agent ? { user_agent: userAgent } : {}),
}),
onSuccess: (result, revoke) => {
// 服务端回的就是这一条的新样子,换进列表即可,不为一次保存把整页重取一遍。
@@ -200,13 +198,6 @@ function SourceCard({ source, toast }: { source: Source } & ScrapingProps) {
<input ref={file} type="file" accept=".txt" tabIndex={-1} aria-hidden
className="hidden" onChange={(event) => { void pickFile(event) }} />
</div>}
- {/* Cloudflare 发下的 Cookie 绑着解题那台浏览器的 UA,请求头要照它发。UA 不是秘密,
- 明文显示,保存后留在框里让用户看到现在发的是哪一个。 */}
- {source.accepts_user_agent
- ? <Input label="浏览器 User-Agent" autoComplete="off" value={userAgent} onChange={setUserAgent}
- placeholder="Mozilla/5.0 (Windows NT 10.0; Win64; x64) …"
- hint="过验证的那台浏览器的 User-Agent;Chrome 在地址栏输入 chrome://version 可以复制到。" />
- : null}
</> : null}
{problem ? <ErrorText>{problem}</ErrorText> : null}
{results.map((result) => (
diff --git a/frontend/src/react/scraping/scraping.ts b/frontend/src/react/scraping/scraping.ts
index fae30e056..9d5a310b4 100644
--- a/frontend/src/react/scraping/scraping.ts
+++ b/frontend/src/react/scraping/scraping.ts
@@ -30,9 +30,6 @@ export interface Source {
accepts_cookie: boolean;
network: string;
cookie_saved: boolean;
- /** 在 Cloudflare 验证后面的来源还收用户浏览器的 User-Agent:Cookie 绑着解题那台浏览器。 */
- accepts_user_agent: boolean;
- user_agent: string;
}
export interface ScrapingData {
diff --git a/frontend/test/react/scraping.test.tsx b/frontend/test/react/scraping.test.tsx
index 4a46b23cd..42bdfce29 100644
--- a/frontend/test/react/scraping.test.tsx
+++ b/frontend/test/react/scraping.test.tsx
@@ -29,8 +29,6 @@ const source = (overrides: Partial<Source> = {}): Source => ({
accepts_cookie: true,
network: 'peach',
cookie_saved: false,
- accepts_user_agent: false,
- user_agent: '',
...overrides,
});
diff --git a/src/peach/http.py b/src/peach/http.py
index ae58dd9bc..6751ffe96 100644
--- a/src/peach/http.py
+++ b/src/peach/http.py
@@ -218,6 +218,11 @@ class HttpxTransport:
str(response.url),
)
target = response.url.join(location)
+ if url.scheme == "https" and target.scheme == "http" and target.host == url.host:
+ # 反向代理后面的站点常把 Location 写成 `http://`:源站看到的是明文连接(2026-09-24 实测
+ # javten.com 搜索一跳)。浏览器靠 HSTS 升回 https,这里也升:明文地址不带 Secure Cookie,
+ # 站前的 Cloudflare 会把这一跳当成陌生人。只升不降,https 落到别的主机照旧按跨源处理。
+ target = target.copy_with(scheme="https", port=None)
if not _same_origin(url, target):
headers = _without(headers, _CREDENTIAL_HEADERS)
# 303 一律改成 GET;301/302 只把非 GET 改成 GET,和浏览器与 httpx 的做法一致。
diff --git a/src/peach/scraping_access.py b/src/peach/scraping_access.py
index 35188d986..82ffaab36 100644
--- a/src/peach/scraping_access.py
+++ b/src/peach/scraping_access.py
@@ -35,12 +35,12 @@ SOURCES = {
"cookie": True, "session": True},
# FC2 商品的两个存档站都在 Cloudflare 的 JS 验证后面:httpx 与模拟 Chrome 指纹的直连都回 403,
# 只有浏览器过完验证发下的 `cf_clearance` 能进,而它绑着解题那台浏览器的 User-Agent 与出口。
- # 所以这两个来源除 Cookie 外还收用户浏览器的 UA(`user_agent`),请求头照它发;连接方式由用户
+ # 整站 UA(`peach.user_agent`)与用户的 Chrome 保持一致就够了,Cookie 由用户贴;连接方式由用户
# 选成与浏览器同一个出口。Cookie 过期后回 403,按 `blocked_pause` 停下等用户换新的,不反复撞。
"fc2ppvdb": {"label": "FC2PPV-DB", "domains": ("fc2ppv-db.com",), "login": "https://fc2ppv-db.com/",
- "cookie": True, "session": True, "user_agent": True, "blocked_pause": 6 * 3600},
+ "cookie": True, "session": True, "blocked_pause": 6 * 3600},
"javten": {"label": "JAVten", "domains": ("javten.com",), "login": "https://javten.com/",
- "cookie": True, "session": True, "user_agent": True, "blocked_pause": 6 * 3600},
+ "cookie": True, "session": True, "blocked_pause": 6 * 3600},
# 下架 FC2 的最后一档。作品页在 javarchive.com、封面转存在 javstore.net 上,两边算同一个
# 来源。免登录可读,不收 Cookie,`robots.txt` 是全站放行。
"javarchive": {"label": "JavArchive", "domains": ("javarchive.com", "javstore.net"),
@@ -200,16 +200,6 @@ def save(root: Path, source: str, body: dict) -> dict:
values.update(supplied)
# 新 Cookie 多半是为了解开 403 才换的;冷却记的是旧 Cookie 撞出来的账,别让它压着新的等到期。
cooldown_path(root, source).unlink(missing_ok=True)
- if "user_agent" in body:
- agent = " ".join(str(body.get("user_agent") or "").split())
- if agent and not SOURCES[source].get("user_agent"):
- raise ValueError("此来源不接受浏览器 User-Agent")
- if len(agent) > 512:
- raise ValueError("User-Agent 超过 512 字符")
- if agent:
- values["user_agent"] = agent
- else:
- values.pop("user_agent", None)
path = _store(root).path_for("scraping-" + source)
path.parent.mkdir(parents=True, exist_ok=True)
temporary = None
@@ -232,22 +222,14 @@ def describe(root: Path, source: str) -> dict:
return {"source": source, "label": SOURCES[source]["label"],
"login": SOURCES[source]["login"], "accepts_cookie": bool(SOURCES[source].get("cookie")),
"network": "direct" if values.get("network") == "direct" else "peach",
- "cookie_saved": bool(values.get("cookie") or values.get("cookies_text")),
- "accepts_user_agent": bool(SOURCES[source].get("user_agent")),
- # UA 不是秘密,回给页面让用户看到现在发的是哪一个浏览器的。
- "user_agent": user_agent_for(values, source)}
-
-
-def user_agent_for(values: dict, source: str) -> str:
- """这个来源的请求该报的 User-Agent:收 UA 的来源用用户存的那一个,其余与整站一致。"""
- return str(values.get("user_agent") or "") if SOURCES.get(source, {}).get("user_agent") else ""
+ "cookie_saved": bool(values.get("cookie") or values.get("cookies_text"))}
def client_for(root: Path, source: str, *, session: bool = False, **kwargs) -> httpx.Client:
values = values_for(root, source)
network = {"trust_env": False} if values.get("network") == "direct" else peach_proxy.client_options(root)
options = {**network, "follow_redirects": True,
- "headers": {"User-Agent": user_agent_for(values, source) or USER_AGENT}}
+ "headers": {"User-Agent": USER_AGENT}}
if session:
options["cookies"] = cookie_jar(values, source)
options.update(kwargs)
@@ -261,8 +243,6 @@ class SourceTransport:
max_bytes: int = 0, max_seconds: float = 0):
self.root = secrets_root
self.transports: dict[str | None, HttpxTransport] = {}
- #: 来源 → 用户存的浏览器 UA;与连接池同时定下,采集一趟里不换。
- self.agents: dict[str | None, str] = {}
self.max_requests, self.max_bytes = max_requests, max_bytes
self.deadline = time.monotonic() + max_seconds if max_seconds else 0
self.requests = self.bytes = 0
@@ -307,12 +287,6 @@ class SourceTransport:
follow_redirects=False) if source else
httpx.Client(**peach_proxy.client_options(self.root), follow_redirects=False, headers={"User-Agent": USER_AGENT}))
self.transports[source] = HttpxTransport(client, owns_client=True)
- self.agents[source] = user_agent_for(values_for(self.root, source), source) if source else ""
- if self.agents.get(source):
- # 调用方在请求头里写了整站的 UA,它压过 client 那一份;收 UA 的来源要发的是用户浏览器的。
- headers = {key: value for key, value in request.headers.items() if key.lower() != "user-agent"}
- request = HttpRequest(request.method, request.url, {**headers, "User-Agent": self.agents[source]},
- request.body)
self.requests += 1
try:
response = self.transports[source](request, timeout, max_bytes)
@@ -335,9 +309,9 @@ class SourceTransport:
blocks += 1
_pause(cooldown, time.time()
+ min(FIRST_BLOCKED_PAUSE * 2 ** (blocks - 1), blocked_pause), blocks)
- if SOURCES[source].get("user_agent"):
- raise SourcePaused("来源要求浏览器验证,暂停向它请求一段时间;"
- "请在采集设置里更新它的 Cookie 与浏览器 User-Agent;已有图片保留")
+ if SOURCES[source].get("cookie"):
+ raise SourcePaused("来源拒绝访问,暂停向它请求一段时间;"
+ "请在采集设置里更新它的 Cookie;已有图片保留")
raise SourcePaused("来源拒绝访问,暂停向它请求一段时间;已有图片保留")
if blocks and response.status < 400:
# 这一趟通了,封已经解除:清掉记录,下次撞上从最短的一档重新起算。
diff --git a/src/peach/sources/fc2ppvdb.py b/src/peach/sources/fc2ppvdb.py
index 7ea349955..4dc68e5e0 100644
--- a/src/peach/sources/fc2ppvdb.py
+++ b/src/peach/sources/fc2ppvdb.py
@@ -8,7 +8,8 @@
站上没有的商品回一张 200 的「404 ページが見つかりません」页,`<h1>` 里没有番号。
站前是 Cloudflare 的 JS 验证:httpx 与模拟 Chrome 指纹的 curl_cffi 直连都回 403,只有浏览器过完验证发下的
-`cf_clearance` 能进(`scraping_access.SOURCES['fc2ppvdb']`),所以请求带用户在采集设置里贴的 Cookie 与浏览器 UA。
+`cf_clearance` 能进(`scraping_access.SOURCES['fc2ppvdb']`),所以请求带用户在采集设置里贴的 Cookie;它绑着解题
+那台浏览器的 UA,整站 UA(`peach.user_agent`)与用户的 Chrome 保持一致。
不交封面:站上那张是 360×360 的 CloudFront 缩略图(`og:image:width` 写 800,实测 360),连封面的最低宽度都
过不了,下回来只是白花一次请求;封面留给链上前后指着 FC2 存储原件的几档。
@@ -147,7 +148,7 @@ class Fc2ppvdbSource(SiteSource):
raise unrecognised()
if challenge_page(page.body):
raise SourceFailure(FailureReason.CLOUDFLARE_CHALLENGE,
- f"{self.config.label} 要求 Cloudflare 验证,请在采集设置里更新 Cookie 与浏览器 User-Agent",
+ f"{self.config.label} 要求 Cloudflare 验证,请在采集设置里更新 Cookie",
status_code=403)
soup = BeautifulSoup(page.text, "html.parser")
heading = soup.select_one("main h1") or soup.select_one("h1")
diff --git a/src/peach/sources/javten.py b/src/peach/sources/javten.py
index 8c6188826..c22b944a6 100644
--- a/src/peach/sources/javten.py
+++ b/src/peach/sources/javten.py
@@ -14,8 +14,8 @@
站上的中文是机器翻译(用户判定),只收日文原页:`fetch` 只取不带语言前缀的地址,`parse` 见到
`og:url` 带 `/tw/`、`/en/`、`/ko/` 就按结构对不上处置,不把译文写进标题。
-站前是 Cloudflare 的 JS 验证,进法与 `fc2ppvdb` 相同:请求带用户在采集设置里贴的 Cookie 与浏览器 UA
-(`scraping_access.SOURCES['javten']`)。
+站前是 Cloudflare 的 JS 验证,进法与 `fc2ppvdb` 相同:请求带用户在采集设置里贴的 Cookie
+(`scraping_access.SOURCES['javten']`),整站 UA 与用户的 Chrome 保持一致。
"""
from __future__ import annotations
@@ -112,7 +112,7 @@ class JavtenSource(SiteSource):
raise unrecognised()
if challenge_page(page.body):
raise SourceFailure(FailureReason.CLOUDFLARE_CHALLENGE,
- f"{self.config.label} 要求 Cloudflare 验证,请在采集设置里更新 Cookie 与浏览器 User-Agent",
+ f"{self.config.label} 要求 Cloudflare 验证,请在采集设置里更新 Cookie",
status_code=403)
soup = BeautifulSoup(page.text, "html.parser")
heading = text_of(soup.select_one("h1.fc2-id"))
diff --git a/src/peach/user_agent.py b/src/peach/user_agent.py
index 537d5b428..052137067 100644
--- a/src/peach/user_agent.py
+++ b/src/peach/user_agent.py
@@ -1,5 +1,10 @@
-"""对外请求使用同一份标准桌面 Chrome User-Agent。"""
+"""对外请求使用同一份标准桌面 Chrome User-Agent。
-# Chrome 152,2026-09-06 核对本机版本 152.0.7977.77;采用标准缩减版本格式。
+与用户这台机器上的 Chrome 保持一致,不只是为了像浏览器:Cloudflare 验证后发下的 `cf_clearance`
+绑着解题那台浏览器的 UA,FC2PPV-DB 与 JAVten 这两个来源带着用户贴的 Cookie 请求时,UA 必须是同一个
+(ADR-0060)。Chrome 大版本升了就改这里,全部对外请求一起换。
+"""
+
+# Chrome 153,2026-09-24 按用户 Chrome 的 `chrome://version` 核对;采用标准缩减版本格式。
USER_AGENT = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
- "(KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36")
+ "(KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36")
diff --git a/tests/test_http.py b/tests/test_http.py
index c003e4364..83d351df3 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -157,6 +157,34 @@ class HttpTransportTests(unittest.TestCase):
("https://cdn.example/x", None, None),
])
+ def test_a_plain_http_redirect_back_to_the_same_host_is_lifted_to_https_and_keeps_the_cookie(self):
+ """反向代理后面的站点把 Location 写成 `http://`,浏览器靠 HSTS 升回去。
+
+ 真实用例:javten.com 的搜索 302 到 `http://javten.com/tw/video/...`(2026-09-24 实测);
+ 照明文地址请求,Secure 的 `cf_clearance` 不随请求发出,Cloudflare 回验证页。
+ 换了主机的 `http://` 不升,仍按跨源丢凭据。
+ """
+ seen = []
+
+ def handler(request: httpx.Request) -> httpx.Response:
+ seen.append((str(request.url), request.headers.get("Cookie")))
+ if request.url.path == "/search":
+ return httpx.Response(302, headers={"Location": "http://javten.test/tw/video/1"})
+ if request.url.path == "/tw/video/1":
+ return httpx.Response(302, headers={"Location": "http://mirror.test/video/1"})
+ return httpx.Response(200, content=b"ok")
+
+ with httpx.Client(transport=httpx.MockTransport(handler)) as client:
+ response = HttpxTransport(client)(
+ HttpRequest("GET", "https://javten.test/search?kw=1", {"Cookie": "cf_clearance=x"}),
+ timeout=2, max_bytes=64)
+ self.assertEqual(response.url, "http://mirror.test/video/1")
+ self.assertEqual(seen, [
+ ("https://javten.test/search?kw=1", "cf_clearance=x"),
+ ("https://javten.test/tw/video/1", "cf_clearance=x"),
+ ("http://mirror.test/video/1", None),
+ ])
+
def test_a_303_turns_the_post_into_a_get_without_its_body(self):
seen = []
diff --git a/tests/test_metadata_fc2.py b/tests/test_metadata_fc2.py
index 3254b69a9..6c3496bee 100644
--- a/tests/test_metadata_fc2.py
+++ b/tests/test_metadata_fc2.py
@@ -590,7 +590,7 @@ class Fc2ppvdbTests(unittest.TestCase):
(db_page(video="48988370"), "FC2-PPV-4898837", FailureReason.NOT_FOUND, "FC2PPV-DB 上没有这个商品"),
(db_page(), "ORETD-615", FailureReason.NOT_FOUND, UNRECOGNISED),
(CHALLENGE, "FC2-PPV-4898837", FailureReason.CLOUDFLARE_CHALLENGE,
- "FC2PPV-DB 要求 Cloudflare 验证,请在采集设置里更新 Cookie 与浏览器 User-Agent")):
+ "FC2PPV-DB 要求 Cloudflare 验证,请在采集设置里更新 Cookie")):
with self.subTest(code=code, html=html[:40]), self.assertRaises(SourceFailure) as caught:
database(html, code)
self.assertEqual((caught.exception.reason, str(caught.exception)), (reason, wording))
diff --git a/tests/test_metadata_sources.py b/tests/test_metadata_sources.py
index c3da1ab6a..a4ee6140d 100644
--- a/tests/test_metadata_sources.py
+++ b/tests/test_metadata_sources.py
@@ -277,13 +277,11 @@ class ConfigConsistencyTests(unittest.TestCase):
{"r18dev", "dmm", "1pondo", "fc2"})
self.assertEqual(tuple(name for name in SITE_SOURCES if name in FC2_STAGE), FC2_STAGE,
"FC2 五站按链上先后登记")
- # 在 Cloudflare 验证后面的两站:Cookie 绑着浏览器的 UA,采集设置里两样都收,403 时整站冷却。
+ # 在 Cloudflare 验证后面的两站:公开采集带用户贴的 Cookie,403 时整站冷却。
for name in ("fc2ppvdb", "javten"):
- self.assertEqual({key: scraping_access.SOURCES[name].get(key) for key in ("cookie", "session", "user_agent")},
- {"cookie": True, "session": True, "user_agent": True}, name)
+ self.assertEqual({key: scraping_access.SOURCES[name].get(key) for key in ("cookie", "session")},
+ {"cookie": True, "session": True}, name)
self.assertTrue(scraping_access.SOURCES[name]["blocked_pause"], name)
- self.assertEqual({name for name, spec in scraping_access.SOURCES.items() if spec.get("user_agent")},
- {"fc2ppvdb", "javten"})
if __name__ == "__main__":
diff --git a/tests/test_scraping_access.py b/tests/test_scraping_access.py
index 4122e61a6..4486a07a3 100644
--- a/tests/test_scraping_access.py
+++ b/tests/test_scraping_access.py
@@ -256,44 +256,24 @@ class ScrapingAccessTests(unittest.TestCase):
self.assertIn("peach_session=abc", client.build_request(
"GET", "https://fc2cmadb.com/articles/4030617").headers["cookie"])
- def test_a_cloudflare_source_sends_the_browser_user_agent_the_cookie_was_issued_to(self):
- """`cf_clearance` 绑着解题那台浏览器的 UA:请求头写整站 UA 的话,Cookie 对了也进不去。"""
- browser = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/153.0.0.0 Safari/537.36"
- shown = save(self.root, "fc2ppvdb", {"cookie": "cf_clearance=abc", "user_agent": f" {browser}\n"})
- self.assertEqual((shown["accepts_user_agent"], shown["user_agent"], shown["cookie_saved"]),
- (True, browser, True))
- self.assertFalse(describe(self.root, "javdb")["accepts_user_agent"])
- seen = []
-
- def record(request, timeout, limit):
- seen.append(request.headers)
- return HttpResponse(200, {}, b"ok")
-
+ def test_the_cloudflare_sources_carry_the_pasted_cookie_under_the_shared_browser_user_agent(self):
+ """`cf_clearance` 绑着解题那台浏览器的 UA:整站 UA 与用户的 Chrome 一致,Cookie 由用户贴,卡上不另收 UA。"""
+ from peach.user_agent import USER_AGENT
+ shown = save(self.root, "fc2ppvdb", {"cookie": "cf_clearance=abc"})
+ self.assertEqual(set(shown), {"source", "label", "login", "accepts_cookie", "network", "cookie_saved"})
+ self.assertTrue(shown["cookie_saved"])
+ for name in ("fc2ppvdb", "javten"):
+ with client_for(self.root, name) as client:
+ self.assertEqual(client.headers["user-agent"], USER_AGENT, name)
transport = SourceTransport(self.root)
- transport.transports["fc2ppvdb"] = record
- transport.agents["fc2ppvdb"] = browser
- transport(HttpRequest("GET", "https://fc2ppv-db.com/ja/videos/4898837",
- {"User-Agent": "Peach/1.0", "Referer": "https://fc2ppv-db.com/"}), 1, 100)
- self.assertEqual(seen[0]["User-Agent"], browser)
- self.assertEqual(seen[0]["Referer"], "https://fc2ppv-db.com/")
- # 连接池按来源建的那一刻把 UA 一起定下;client 自己的默认头也是它。
+ self.addCleanup(transport.close)
with patch("peach.scraping_access.client_for") as factory:
fake = factory.return_value
fake.stream.return_value.__enter__.return_value.iter_bytes.return_value = [b"ok"]
- fresh = SourceTransport(self.root)
- self.addCleanup(fresh.close)
- fresh(HttpRequest("GET", "https://javten.com/search?kw=4898837", {"User-Agent": "Peach/1.0"}), 1, 10)
- self.assertEqual(fresh.agents["javten"], "")
- save(self.root, "javten", {"user_agent": browser})
- fresh(HttpRequest("GET", "https://fc2ppv-db.com/ja/videos/1", {"User-Agent": "Peach/1.0"}), 1, 10)
- self.assertEqual(fresh.agents["fc2ppvdb"], browser)
- self.assertEqual(client_for(self.root, "javten").headers["user-agent"], browser)
- self.assertNotEqual(client_for(self.root, "javdb").headers["user-agent"], browser)
- with self.assertRaises(ValueError):
- save(self.root, "javdb", {"user_agent": browser})
- with self.assertRaises(ValueError):
- save(self.root, "javten", {"user_agent": "x" * 513})
- self.assertEqual(save(self.root, "javten", {"user_agent": ""})["user_agent"], "")
+ transport(HttpRequest("GET", "https://fc2ppv-db.com/ja/videos/4898837", {}), 1, 10)
+ transport(HttpRequest("GET", "https://javten.com/search?kw=4898837", {}), 1, 10)
+ self.assertEqual([(call.args[1], call.kwargs["session"]) for call in factory.call_args_list],
+ [("fc2ppvdb", True), ("javten", True)])
def test_a_new_cookie_lifts_the_pause_the_old_one_earned(self):
"""过期的 `cf_clearance` 撞出 403 后整站冷却;用户换了新 Cookie 就该立刻再试,不等旧账到期。"""
@@ -304,7 +284,7 @@ class ScrapingAccessTests(unittest.TestCase):
refused.transports["javten"] = lambda *args: HttpResponse(403, {}, b"")
with self.assertRaises(SourcePaused) as caught:
refused(request, 1, 100)
- self.assertIn("Cookie 与浏览器 User-Agent", str(caught.exception))
+ self.assertIn("更新它的 Cookie", str(caught.exception))
self.assertTrue(cooldown.exists())
save(self.root, "javten", {"network": "peach"})
self.assertTrue(cooldown.exists(), "只改连接方式不算换了 Cookie")
diff --git a/web/dist/peach-react.js b/web/dist/peach-react.js
index f2395d2aa..e2505ee8f 100644
--- a/web/dist/peach-react.js
+++ b/web/dist/peach-react.js
@@ -32145,53 +32145,52 @@ function aO({ source: e }) {
});
}
function oO({ source: e, toast: t }) {
- let [n, r] = (0, C.useState)(e.network), [i, a] = (0, C.useState)(""), [o, s] = (0, C.useState)(""), [c, l] = (0, C.useState)(e.user_agent), [u, d] = (0, C.useState)(iO[0][0]), [f, p] = (0, C.useState)(""), [m, h] = (0, C.useState)(""), g = (0, C.useRef)(null);
- function _() {
- a(""), s(""), p(""), h(""), g.current && (g.current.value = "");
+ let [n, r] = (0, C.useState)(e.network), [i, a] = (0, C.useState)(""), [o, s] = (0, C.useState)(""), [c, l] = (0, C.useState)(iO[0][0]), [u, d] = (0, C.useState)(""), [f, p] = (0, C.useState)(""), m = (0, C.useRef)(null);
+ function h() {
+ a(""), s(""), d(""), p(""), m.current && (m.current.value = "");
}
- let v = mt({
+ let g = mt({
mutationFn: (t) => J(UD, {
source: e.source,
network: n,
cookie: i,
cookies_text: o,
- revoke: t,
- ...e.accepts_user_agent ? { user_agent: c } : {}
+ revoke: t
}),
onSuccess: (e, n) => {
hh.setQueryData(YD, (t) => t && {
...t,
sources: t.sources.map((t) => t.source === e.saved.source ? e.saved : t)
- }), _(), t(n ? "Cookie 已撤销" : "来源设置已保存");
- }
- }), y = mt({ mutationFn: () => J(WD, { source: e.source }) }), b = v.isPending || y.isPending, x = (e) => {
- e.preventDefault(), !b && (y.reset(), v.mutate(!1));
- }, S = () => {
- b || (y.reset(), v.mutate(!0));
- }, T = () => {
- b || (v.reset(), y.mutate());
+ }), h(), t(n ? "Cookie 已撤销" : "来源设置已保存");
+ }
+ }), _ = mt({ mutationFn: () => J(WD, { source: e.source }) }), v = g.isPending || _.isPending, y = (e) => {
+ e.preventDefault(), !v && (_.reset(), g.mutate(!1));
+ }, b = () => {
+ v || (_.reset(), g.mutate(!0));
+ }, x = () => {
+ v || (g.reset(), _.mutate());
};
- async function E(e) {
+ async function S(e) {
let t = e.currentTarget, n = t.files?.[0];
- if (s(""), h(""), !n) {
- p("");
+ if (s(""), p(""), !n) {
+ d("");
return;
}
if (n.size > 262144) {
- t.value = "", p(""), h("Cookie 文本超过 256 KiB");
+ t.value = "", d(""), p("Cookie 文本超过 256 KiB");
return;
}
try {
let e = await n.text();
- s(e), p(n.name);
+ s(e), d(n.name);
} catch {
- h("Cookie 文件未读取,请重新选择");
+ p("Cookie 文件未读取,请重新选择");
}
}
- let D = m || (v.error ? q(v.error) : "") || (y.error ? q(y.error) : ""), O = y.data?.results ?? [], k = n === "peach" || e.accepts_cookie || !!D || O.length > 0;
+ let T = f || (g.error ? q(g.error) : "") || (_.error ? q(_.error) : ""), E = _.data?.results ?? [], D = n === "peach" || e.accepts_cookie || !!T || E.length > 0;
return /* @__PURE__ */ (0, w.jsxs)(aC, {
title: e.label,
- onSubmit: x,
+ onSubmit: y,
aside: /* @__PURE__ */ (0, w.jsxs)("span", {
className: "flex min-w-0 items-center gap-1",
children: [/* @__PURE__ */ (0, w.jsx)(aO, { source: e.source }), /* @__PURE__ */ (0, w.jsx)(fC, {
@@ -32214,7 +32213,7 @@ function oO({ source: e, toast: t }) {
}, e))
})
}) }),
- k ? /* @__PURE__ */ (0, w.jsxs)(sC, {
+ D ? /* @__PURE__ */ (0, w.jsxs)(sC, {
divided: !0,
children: [
n === "peach" ? /* @__PURE__ */ (0, w.jsx)("span", {
@@ -32233,9 +32232,9 @@ function oO({ source: e, toast: t }) {
}),
/* @__PURE__ */ (0, w.jsx)(Ev, {
"aria-label": "提供 Cookie 的方式(二选一)",
- value: u,
+ value: c,
onChange: (e) => {
- d(e), _();
+ l(e), h();
},
className: FS,
children: iO.map(([e, t]) => /* @__PURE__ */ (0, w.jsx)(Dv, {
@@ -32244,7 +32243,7 @@ function oO({ source: e, toast: t }) {
children: t
}, e))
}),
- u === "paste" ? /* @__PURE__ */ (0, w.jsx)(sb, {
+ c === "paste" ? /* @__PURE__ */ (0, w.jsx)(sb, {
type: "password",
label: "Cookie",
autoComplete: "off",
@@ -32258,37 +32257,29 @@ function oO({ source: e, toast: t }) {
className: "flex flex-wrap items-center gap-3",
children: [/* @__PURE__ */ (0, w.jsx)(K, {
variant: "secondary",
- onClick: () => g.current?.click(),
+ onClick: () => m.current?.click(),
children: "选择文件"
}), /* @__PURE__ */ (0, w.jsx)("span", {
className: "min-w-0 text-body-2-regular break-all text-text-secondary",
- children: f || "未选择文件"
+ children: u || "未选择文件"
})]
}),
/* @__PURE__ */ (0, w.jsx)("input", {
- ref: g,
+ ref: m,
type: "file",
accept: ".txt",
tabIndex: -1,
"aria-hidden": !0,
className: "hidden",
onChange: (e) => {
- E(e);
+ S(e);
}
})
]
- }),
- e.accepts_user_agent ? /* @__PURE__ */ (0, w.jsx)(sb, {
- label: "浏览器 User-Agent",
- autoComplete: "off",
- value: c,
- onChange: l,
- placeholder: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) …",
- hint: "过验证的那台浏览器的 User-Agent;Chrome 在地址栏输入 chrome://version 可以复制到。"
- }) : null
+ })
] }) : null,
- D ? /* @__PURE__ */ (0, w.jsx)(uC, { children: D }) : null,
- O.map((t) => /* @__PURE__ */ (0, w.jsx)(Y, {
+ T ? /* @__PURE__ */ (0, w.jsx)(uC, { children: T }) : null,
+ E.map((t) => /* @__PURE__ */ (0, w.jsx)(Y, {
tone: t.ok ? "success" : "error",
children: nO(t, e.label)
}, t.label))
@@ -32297,19 +32288,19 @@ function oO({ source: e, toast: t }) {
/* @__PURE__ */ (0, w.jsxs)(cC, { children: [
e.accepts_cookie && e.cookie_saved ? /* @__PURE__ */ (0, w.jsx)(K, {
variant: "secondary",
- onClick: S,
- ...X(b),
+ onClick: b,
+ ...X(v),
children: "撤销 Cookie"
}) : null,
/* @__PURE__ */ (0, w.jsx)(K, {
variant: "secondary",
- onClick: T,
- ...X(b),
+ onClick: x,
+ ...X(v),
children: "检查连接"
}),
/* @__PURE__ */ (0, w.jsx)(K, {
type: "submit",
- ...X(b),
+ ...X(v),
children: "保存"
})
] })