Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(catalog): FC2 缺集合集归组并按人脸取景

longmeidaoae08b552d14c
diff --git a/docs/REUSE.md b/docs/REUSE.md
index c6960f00b..5bd0d88d5 100644
--- a/docs/REUSE.md
+++ b/docs/REUSE.md
@@ -303,7 +303,7 @@ CloudDrive 为外部应用,本项目不捆绑其二进制或依赖其管理 AP
| 播放器设置与影院布局 | Video.js 8.24.1 的 `playbackRate`、既有 QualityLevel、原生 tooltip 与控制栏插槽;YouTube `e937390a` 实际 DOM/CSS/JS 提供可复现的几何、状态、动画和图形证据 | Peach 在现有 DOM 上组合氛围模式、播放速度、真实清晰度和影院模式,并复用 59 px 两排控制栏、40→111 px 横向音量、4→6 px 进度动画、右侧共享胶囊、整行悬停的 274 px 设置菜单和视口级全屏;普通视图 `contain` 保全片源,全屏用 `cover` 铺满视口,接受非等比例片源的边缘裁切。全屏命中同时使用 Video.js/原生类和 `isFullscreen()` 同步的 `data-peach-fullscreen`,并覆盖 `body.vjs-full-window` 回退,不能靠单个 CSS 类推断运行态;标准、WebKit、Gecko 等浏览器专用伪类必须放进 forgiving `:is(...)` 或拆成独立规则,不能在普通 selector list 混写后让某浏览器因未知伪类废掉整组声明。要求图形精准的设置项、radio 选中勾、菜单箭头、中央 bezel 与 loading 只 vendoring 当前锁定版本的 SVG path/spinner 结构,音量 hover 与滑轨中心沿用上游外层伪元素和 50% 几何,tooltip 仅补 Peach 两排控制栏需要的显式层级与越界可见;不复制播放器控制逻辑、不迁移到 Video.js 10 Menu,也不引入重复现有质量选择的插件 |
| 播放器时刻预览 | Video.js 原生进度控件 + Peach 自己的 `/timeline?id=&s=`(10×10 接触印相),取不到时退到既有 `/poster?id=&c=0…8` 九宫格切片 | 时间轴图由 `peach.timeline_sheets` 按每 10 或 30 秒一帧预先铺好,只覆盖 `location='local'`:网盘上的每抽一帧都要回源拉一次,实测 115 单文件抽九帧约 285 MB,两万部按每 10 秒一帧算流量以 TB 计。没铺到的片子和在线视频退回九宫格,那九格是全片九等分、只给近似时刻。抽帧与拼图命令与九宫格脚本共用 `peach.frame_capture`,不另起一份裸 ffmpeg 调用。`videojs-vtt-thumbnails` 与 `videojs-sprite-thumbnails` 都要求另建 sprite/VTT 契约并多一层运行时依赖,而格子位置的换算在 Peach 这边是一行整除,所以不引入 |
| 外挂字幕 sidecar | 浏览器原生 `TextTrack` 与 [WebVTT 规范](https://www.w3.org/TR/webvtt1/);配对判据复用 `catalog_rules` 的 `VERSION_TAIL_TOKENS` 与 `release_code_from_filename`。两份本机参考项目只作行为证据:sakuramediabe `src/service/transfers/imports/import_service.py` 加 `src/common/movie_numbers.py` 的 `subtitle_matches_movie_number`(限同目录、纯番号匹配、不回退到同名匹配),NeoAVDC `src/main/media/organizeMedia.ts` 加 `src/main/number/parseNumber.ts` 的 `SUBTITLE_EXTS`/`isSubtitleFile`(`.srt .ass .sub .vtt .ssa`,按视频主名前缀跟随)。Peach 的三条判据正是这两者的并集加顺序 | `subtitles.py` 只做三件事:同目录配对(exact/suffix/code/orphan,跨目录一律不算)、`asset_subtitle` 幂等登记、srt/ass/ssa → WebVTT。转换不外包:`pysubs2` 会为一件几十行的事引入运行时依赖,而已经在管的 FFmpeg 要为每次取字幕起一个子进程、失败只给退出码,说不出「这份字幕的编码认不出来」,而编码恰是这个库最常踩的一项(GBK/Big5/Shift_JIS 各有)。`gb18030` 明确不用:它几乎吞下任何字节,放进来就再也报不出「认不出编码」。内封字幕轨不在这条里,现有 `probe.py` 只取 `v:0`,没有任何流信息落库 |
-| 分卷文件命名 | [Plex 官方命名](https://support.plex.tv/articles/naming-and-organizing-your-movie-media-files/)的 `cd/disc/disk/dvd/part/pt + 数字` 与 [Kodi 官方 File Stacking](https://kodi.wiki/view/File_stacking)只作行为证据;运行时复用当前树的 `part_marker`,不新增扫描器依赖 | 兼容馆藏已有的裸数字和 A–H 后缀;仅连续、唯一标记自动合卡,保留每个 asset 和播放会话,不拼接或改写媒体 |
+| 分卷文件命名 | [Plex 官方命名](https://support.plex.tv/articles/naming-and-organizing-your-movie-media-files/)的 `cd/disc/disk/dvd/part/pt + 数字` 与 [Kodi 官方 File Stacking](https://kodi.wiki/view/File_stacking)只作行为证据;运行时复用当前树的 `part_marker`,不新增扫描器依赖 | 兼容馆藏已有的裸数字和 A–H 后缀;连续、唯一标记自动合卡。FC2 合集的文件名前缀与登记番号一致、数字序号唯一时允许缺集,按原序号浏览;裸名文件不推断缺失序号。保留每个 asset 和播放会话,不拼接或改写媒体 |
| 照片灯箱轮播 | Swiper 14.2.0(MIT,本地固定版本,按需加载 CSS/JS)的 Thumbs / Keyboard / Zoom 模块,由 React 灯箱(`frontend/src/react/photo-lightbox/`)只经核心 API 驱动,不用 Swiper 的 React 封装 | 构造轮播前必须同时等到样式与脚本就绪,并保留 scoped 的单 slide 结构样式防止首载竞态重叠;Swiper 管轮播、键盘、缩放变换与缩略图,Peach 管图集来源与顺序、当前缩略图居中、相对原图百分比、适应窗口/原大小语义、缩略图缓存与计费口径。图片墙本身是 CSS 网格,不经过 Swiper。 |
| 导航排序 | 浏览器原生 HTML Drag and Drop | 桌面鼠标直接拖动、落点提示、上下移动按钮作为键盘与触屏回退、`localStorage` 持久化;不为单列排序引入额外运行时依赖 |
| 单列拖动排序 | `web/js/ui-components.js` 的 `wireDragReorder()` | 侧栏顺序与播放列表队列共用这一份:`dragstart` 标记被拖行,`dragover` 按指针落在行的上半还是下半给出落点线,`drop` 把整份新顺序交给调用方落库。落点线、抓手和键盘焦点样式都在共用件里,每加一处可拖列表不必各写一份 |
diff --git a/frontend/e2e/fc2-artwork.test.ts b/frontend/e2e/fc2-artwork.test.ts
new file mode 100644
index 000000000..cd9d43af5
--- /dev/null
+++ b/frontend/e2e/fc2-artwork.test.ts
@@ -0,0 +1,60 @@
+import assert from 'node:assert/strict';
+import { after, before, describe, it } from 'node:test';
+import type { Browser } from 'playwright-core';
+
+import { launch, layout, settle, VIEWPORTS } from './harness.ts';
+import { ITEM, openItemPage } from './item-fixture.ts';
+
+describe('FC2 合集与封面取景', () => {
+ let browser: Browser;
+ before(async () => { browser = await launch(); });
+ after(async () => { await browser?.close(); });
+
+ for (const viewport of VIEWPORTS) {
+ it(`${viewport.name}: 缺集归为一张卡,横图按人脸居中`, async () => {
+ const opened = await openItemPage(browser, '/', viewport, {
+ ready: '[data-media-card]', settings: { javLayout: 'big', homeLayout: 'big', javImage: 'cover' },
+ });
+ try {
+ const code = 'FC2-PPV-3312576';
+ const ids = [8001, 8008, 8010, 8021];
+ const base = await opened.page.evaluate(async (id) =>
+ (await fetch(`/api/item?id=${id}`)).json(), ITEM.plain);
+ const items = ids.map((id) => ({ ...base, id, code, is_jav: true, tags: [],
+ name: `${code}-${id - 8000}.mp4`, has_cover: true,
+ cover_frame: { cx: .519, cy: .294 }, poster_box: null,
+ part_group: { key: code, title: code, count: ids.length, seed_id: ids[0],
+ item_ids: ids, total_duration: 9000, total_size: 9000000000 },
+ }));
+ await opened.page.route('**/api/items?*', (route) => route.fulfill({ json: {
+ items, total: items.length, has_more: false,
+ } }));
+ await opened.page.route('**/cover?*', (route) => route.fulfill({
+ contentType: 'image/svg+xml', body: '<svg xmlns="http://www.w3.org/2000/svg" width="1548" height="948"><rect width="1548" height="948" fill="#ddd"/></svg>',
+ }));
+ await opened.page.reload({ waitUntil: 'load' });
+ const covers = opened.page.locator('[data-media-card] img.cover');
+ await covers.first().waitFor();
+ await opened.page.waitForFunction(() =>
+ document.querySelector<HTMLImageElement>('[data-media-card] img.cover')?.naturalWidth === 1548);
+ await settle(opened.page);
+ assert.equal(await covers.count(), 1);
+ const frame = await covers.first().evaluate((img: HTMLImageElement) => {
+ const style = getComputedStyle(img);
+ const rect = img.getBoundingClientRect();
+ const scale = Math.max(rect.width / img.naturalWidth, rect.height / img.naturalHeight);
+ const x = parseFloat(style.objectPosition) / 100;
+ const faceX = .519 * img.naturalWidth * scale + (rect.width - img.naturalWidth * scale) * x;
+ return { kind: img.dataset.frame, faceX, center: rect.width / 2,
+ croppedWidth: img.naturalWidth * scale - rect.width };
+ });
+ assert.equal(frame.kind, 'still');
+ assert.ok(frame.croppedWidth > 0, JSON.stringify(frame));
+ assert.ok(Math.abs(frame.faceX - frame.center) < 5, JSON.stringify(frame));
+ const bounds = await layout(opened.page);
+ assert.ok(bounds.scrollWidth <= bounds.viewportWidth + 1, JSON.stringify(bounds));
+ assert.deepEqual(opened.problems, []);
+ } finally { await opened.close(); }
+ });
+ }
+});
diff --git a/src/peach/catalog_rules.py b/src/peach/catalog_rules.py
index efc0663a4..d1b3ba162 100644
--- a/src/peach/catalog_rules.py
+++ b/src/peach/catalog_rules.py
@@ -1090,7 +1090,7 @@ def names_without_shared_part_tail(items: list[dict]) -> list[str]:
def ordered_multipart_items(items: list[dict]) -> list[dict]:
- """Return one unambiguous, contiguous multipart release in playback order.
+ """Return one unambiguous multipart release in playback order.
Bare A/B and numeric suffixes are both common in the existing library. A
repeated marker means that one part has duplicate encodes, while mixed
@@ -1101,8 +1101,8 @@ def ordered_multipart_items(items: list[dict]) -> list[dict]:
裸名也可能是整部完整版,所以只在数字标记、标记正好从 2 连续排起、且裸名时长与
其他卷相差不大时,才把它当第 1 卷;字母卷缺 A 时无从判断裸名是不是 A,不猜。
- 文件名原样认不出卷号时再按 `names_without_shared_part_tail` 剥一次共有尾缀重试:
- 先原样、后剥缀,已经成组的那些走的仍是第一条路,判据一个没松。
+ 文件名原样认不出卷号时再按 `names_without_shared_part_tail` 剥一次共有尾缀重试。
+ FC2 合集允许缺集,文件名前缀必须匹配登记番号,数字序号必须唯一且显式标出。
"""
ordered = _ordered_by_markers(items, [str(item.get("name") or "") for item in items])
if ordered:
@@ -1135,10 +1135,25 @@ def _ordered_by_markers(items: list[dict], names: list[str]) -> list[dict]:
return []
ordered.append((1, bare[0]))
elif sorted(positions) != list(range(1, len(positions) + 1)):
- return []
+ # FC2 合集按明确的文件序号浏览,允许馆藏缺集;不推断裸名文件的序号。
+ if not numeric or not _explicit_fc2_collection(items, names, positions):
+ return []
return [item for _, item in sorted(ordered, key=lambda pair: pair[0])]
+def _explicit_fc2_collection(items: list[dict], names: list[str], positions: list[int]) -> bool:
+ """缺集的 FC2 合集需要唯一数字序号与同一番号的文件名前缀。"""
+ codes = {normalise_code_key(item.get("code")) for item in items}
+ code = next(iter(codes)) if len(codes) == 1 else ""
+ if not code.startswith("FC2-PPV-") or len(set(positions)) != len(positions):
+ return False
+ for name in names:
+ match = _PART_MARKER.search(name)
+ if not match or normalise_code_key(name[:match.start()]) != code:
+ return False
+ return True
+
+
def duration_clusters(items: list[dict]) -> list[list[dict]]:
"""Cluster same-code files by tight duration and multipart evidence."""
clusters: list[list[dict]] = []
diff --git a/tests/test_rm_web.py b/tests/test_rm_web.py
index 34137a427..b93438abf 100644
--- a/tests/test_rm_web.py
+++ b/tests/test_rm_web.py
@@ -2722,6 +2722,32 @@ class DuplicateDetectionTests(unittest.TestCase):
self.assertEqual(rm_web.ordered_multipart_items(duplicate), [])
self.assertEqual(rm_web.ordered_multipart_items(gapped), [])
+ def test_fc2_collection_with_missing_parts_keeps_explicit_numbers(self):
+ numbers = [21, 1, 8, 10, 13, 15]
+ items = [{"id": n, "code": "FC2-PPV-3312576",
+ "name": f"FC2-PPV-3312576-{n}.mp4"} for n in numbers]
+ self.assertEqual([row["id"] for row in rm_web.ordered_multipart_items(items)],
+ sorted(numbers))
+ for extra in (
+ {"id": 31, "code": "FC2-PPV-3312576", "name": "FC2-PPV-3312576-01.mp4"},
+ {"id": 32, "code": "FC2-PPV-3312576", "name": "FC2-PPV-3312576.mp4"},
+ {"id": 33, "code": "FC2-PPV-3312576", "name": "FC2-PPV-1234567-3.mp4"},
+ ):
+ with self.subTest(extra=extra):
+ self.assertEqual(rm_web.ordered_multipart_items([*items, extra]), [])
+
+ def test_fc2_collection_api_keeps_all_available_parts_in_order(self):
+ numbers = [n for n in range(1, 22) if n not in (9, 14)]
+ for n in reversed(numbers):
+ self.add("FC2-PPV-3312576", 1800 + n * 100, 1_000_000_000 + n,
+ name=f"FC2-PPV-3312576-{n}.mp4")
+ listed = rm_web.q_items(self.contract, {"q": "FC2-PPV-3312576", "limit": "30"})["items"]
+ self.assertEqual(len(listed), 19)
+ self.assertEqual({row["part_group"]["count"] for row in listed}, {19})
+ self.assertTrue(all("edition_group" not in row for row in listed))
+ parts = rm_web.q_parts(self.contract, {"id": str(listed[0]["id"])})
+ self.assertEqual([row["part_label"] for row in parts["items"]], list(map(str, numbers)))
+
def test_parts_group_when_the_edition_suffix_sits_after_the_volume_number(self):
"""卷号后面挂着版次或修复标记时,剥掉组内共有尾缀仍认得出这是一部片的几卷。
diff --git a/web/app.js b/web/app.js
index a109bac72..c858db06b 100644
--- a/web/app.js
+++ b/web/app.js
@@ -3213,7 +3213,9 @@ function avatarFrame(img){
function coverAnchor(img){
const r=img.naturalWidth/img.naturalHeight;
if(!r)return;
- img.dataset.frame=r>=1.65?'still':r>1.2?'sleeve':'front';
+ const code=new URL(img.currentSrc||img.src,location.href).searchParams.get('code')||'';
+ // FC2 封面是整幅画面,横向取景跟随人脸;宽高比不代表有 DVD 正封。
+ img.dataset.frame=/^FC2(?:-PPV)?-/i.test(code)||r>=1.65?'still':r>1.2?'sleeve':'front';
/* `object-position` 的百分比说的是「图片上这个点对齐可见窗口的同一个百分比位置」,
不是「这个点落到窗口正中」。所以人脸中心原样当锚点只能保证脸还在画面里:0.81
那种偏右的脸会贴着窗口右缘,图片右边还剩一截永远露不出来。可见窗口占图片 w 时,