Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(settings): 转码方式只在确认可配置时出现,窄屏不换行

longmeidaof464d01abcd9
diff --git a/docs/OPERATIONS.md b/docs/OPERATIONS.md
index 51dccc5c4..9483f39e4 100644
--- a/docs/OPERATIONS.md
+++ b/docs/OPERATIONS.md
@@ -467,7 +467,7 @@ untrunc 按相同顺序查找,对应目录为 `tools/untrunc`。独立程序
- 同时最多进行 2 个转码或探测,单次最长 1 小时,关掉播放页会取消对应的任务。
- 115 和 PikPak 的视频通过 CloudDrive2 挂载的 `B:`、`A:` 播放。能不能播,以在 Peach 里实际打开一个已知视频为准。
-Peach 配置「媒体库与入库 → 视频预览」中的「抽帧解码方式」与设置弹窗「浏览与播放 → 播放」中的「编解码方式」分别保存为运行 Peach 那台电脑的偏好,两者互不影响,均可选择「自动(硬件优先)」或软件。编解码方式只在能修改 Peach 配置的设备上显示。抽帧设置控制封面、九宫格与时间轴;扫描、读 NFO 和时长探测不依赖 GPU。播放设置只控制 Peach 服务端的整片与 HLS 转码,浏览器直接播放时自行选择解码方式。保存无需重启,对新任务生效;已生成的有效缓存继续使用,运行中的 FFmpeg 不被强行中断。macOS 抽帧在同一超时预算内尝试 VideoToolbox,Windows 抽帧对 H.264、HEVC、VP9、AV1 尝试 D3D11VA,失败后都回退软件;视频编码格式探测按文件大小和修改时间缓存。Windows 播放的自动档依次探测 NVENC、AMF、QSV 编码,三者都不可用时用 D3D11VA 解码再交给 libx264;AMF 只接受 AMD 显卡上的 D3D11 设备,Peach 按显卡序号逐个探测。偏好通过 `/api/media-processing` 的 GET/POST 读写,`preview_acceleration` 和 `playback_acceleration` 分别接受 `auto/software`;省略的字段保持现值。`PEACH_TRANSCODE_BACKEND` 可用于管理员诊断,支持 `auto/software/nvenc/amf/qsv/vaapi/videotoolbox`,显式 `software` 会保持禁用硬件。
+Peach 配置「媒体库与入库 → 视频预览」中的「抽帧解码方式」与设置弹窗「浏览与播放 → 播放」中的「转码方式」分别保存为运行 Peach 那台电脑的偏好,两者互不影响,均可选择「自动(硬件优先)」或软件。转码方式只在能修改 Peach 配置的设备上显示。抽帧设置控制封面、九宫格与时间轴;扫描、读 NFO 和时长探测不依赖 GPU。播放设置只控制 Peach 服务端的整片与 HLS 转码,浏览器直接播放时自行选择解码方式。保存无需重启,对新任务生效;已生成的有效缓存继续使用,运行中的 FFmpeg 不被强行中断。macOS 抽帧在同一超时预算内尝试 VideoToolbox,Windows 抽帧对 H.264、HEVC、VP9、AV1 尝试 D3D11VA,失败后都回退软件;视频编码格式探测按文件大小和修改时间缓存。Windows 播放的自动档依次探测 NVENC、AMF、QSV 编码,三者都不可用时用 D3D11VA 解码再交给 libx264;AMF 只接受 AMD 显卡上的 D3D11 设备,Peach 按显卡序号逐个探测。偏好通过 `/api/media-processing` 的 GET/POST 读写,`preview_acceleration` 和 `playback_acceleration` 分别接受 `auto/software`;省略的字段保持现值。`PEACH_TRANSCODE_BACKEND` 可用于管理员诊断,支持 `auto/software/nvenc/amf/qsv/vaapi/videotoolbox`,显式 `software` 会保持禁用硬件。
卡片悬停预览请求的 `/stream` 不带流会话,取消不了,也看不到浏览器断开。片源需要整片转码且没有现成缓存时,这条请求直接回 415,不启动 FFmpeg;详情与沉浸模式带会话播放,关闭时按会话结束转码。
diff --git a/frontend/e2e/design-configuration-controls.test.ts b/frontend/e2e/design-configuration-controls.test.ts
index 2721c7e85..2ec4cc5a3 100644
--- a/frontend/e2e/design-configuration-controls.test.ts
+++ b/frontend/e2e/design-configuration-controls.test.ts
@@ -108,10 +108,11 @@ describe('设计决定:配置控件', () => {
})),
}));
});
- assert.equal(measured.length, 2);
- assert.deepEqual(measured.map((group) => group.rows.length), [2, 1]);
- assert.deepEqual(measured.map((group) => group.top), [0, 1]);
- assert.deepEqual(measured.flatMap((group) => group.rows.map((row) => row.bottom)), [1, 0, 0]);
+ // 总开关、时间轴档位、抽帧解码方式各占一个行组,组与组之间由下一组的上边线分开。
+ assert.equal(measured.length, 3);
+ assert.deepEqual(measured.map((group) => group.rows.length), [1, 1, 1]);
+ assert.deepEqual(measured.map((group) => group.top), [0, 1, 1]);
+ assert.deepEqual(measured.flatMap((group) => group.rows.map((row) => row.bottom)), [0, 0, 0]);
for (const row of measured.flatMap((group) => group.rows)) {
assert.ok(Math.abs(row.left - 12) <= .5 && Math.abs(row.right) <= .5, JSON.stringify(row));
}
diff --git a/frontend/e2e/media-processing-settings.test.ts b/frontend/e2e/media-processing-settings.test.ts
index bb9dbbab0..eb2e40e65 100644
--- a/frontend/e2e/media-processing-settings.test.ts
+++ b/frontend/e2e/media-processing-settings.test.ts
@@ -68,7 +68,7 @@ describe('视频预览设置', () => {
assert.equal(state.previewAcceleration, 'software');
assert.equal(state.playbackAcceleration, 'auto');
assert.deepEqual(writes.slice(-1), [{ preview_acceleration: 'software' }]);
- // 播放转码与其它播放设置同在设置弹窗,配置页上不再出现。
+ // 播放转码只在设置弹窗「浏览与播放」里,与其它播放设置同处。
assert.equal(await page.locator('#playbackAccelerationSetting').count(), 0);
await page.reload();
await preview.waitFor();
@@ -84,7 +84,7 @@ describe('视频预览设置', () => {
} finally { await opened.close() }
});
- it(`${viewport.name}:设置弹窗「浏览与播放」里改播放编解码方式,只写这一项,重新打开读回`, async () => {
+ it(`${viewport.name}:设置弹窗「浏览与播放」里改转码方式,只写这一项,重新打开读回`, async () => {
const { state, writes, route } = mediaProcessing();
const opened = await visit(browser, '/settings/playback', viewport, route);
const { page } = opened;
@@ -97,7 +97,7 @@ describe('视频预览设置', () => {
assert.match(await trigger.innerText(), /自动/);
await trigger.click();
await field.locator('[data-select-option="software"]').click();
- await page.getByText('已保存播放编解码方式', { exact: true }).waitFor();
+ await page.getByText('已保存转码方式', { exact: true }).waitFor();
assert.equal(state.playbackAcceleration, 'software');
assert.equal(state.previewAcceleration, 'auto');
assert.deepEqual(writes, [{ playback_acceleration: 'software' }]);
diff --git a/frontend/src/react/settings-panel/settings-panel.tsx b/frontend/src/react/settings-panel/settings-panel.tsx
index f55a473b4..c77e29069 100644
--- a/frontend/src/react/settings-panel/settings-panel.tsx
+++ b/frontend/src/react/settings-panel/settings-panel.tsx
@@ -13,7 +13,7 @@
* 每次打开时共用控件重画、数值框回到当前值,并重取共享设置。
* 焦点先交给关闭钮,Tab 在面板里转圈,关掉后还给打开前那一枚。 */
import {
- useLayoutEffect, useRef, useState, useSyncExternalStore,
+ useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore,
type KeyboardEvent, type ReactNode,
} from 'react';
import { flushSync } from 'react-dom';
@@ -409,10 +409,13 @@ function decorateDirection(field: HTMLElement, ascending: boolean): void {
}
/* 「浏览与播放」分两段:作品列表(网格、排序、卡片与悬停)在前,播放在后。转码方式写的是运行 Peach
- 那台电脑的配置,只在能改配置的设备上出现,排在播放段最后。 */
+ 那台电脑的配置,只在确认能改配置的设备上出现,排在播放段最后。每次打开面板时权限先回 null 再查,
+ 查的这一段沿用上一次的结论:这一行不在能改的设备上先消失再出现,也不在别的设备上先出现再消失。 */
function BrowseGroup({ host: current, tab, epoch, configurable }: GroupProps & { configurable: boolean | null }) {
const settings = current.store.value;
const save = () => current.store.save();
+ const [known, setKnown] = useState<boolean | null>(null);
+ if (configurable !== null && configurable !== known) setKnown(configurable);
const random = settings.defaultSort === 'seed';
const ascending = settings.defaultSortDirection === 'asc';
return (
@@ -453,7 +456,7 @@ function BrowseGroup({ host: current, tab, epoch, configurable }: GroupProps & {
</Row>
<h4 data-settings-subheading="">播放</h4>
<PlaybackRows host={current} epoch={epoch} />
- {configurable === false ? null : <TranscodeRow host={current} epoch={epoch} ready={configurable === true} />}
+ {(configurable ?? known) === true ? <TranscodeRow host={current} epoch={epoch} /> : null}
</Group>
);
}
@@ -537,21 +540,28 @@ function PlaybackRows({ host: current, epoch }: Omit<GroupProps, 'tab'>) {
const TRANSCODE_OPTIONS: readonly Choice[] = [['auto', '自动(硬件优先)'], ['software', '软件编解码']];
-/* 编解码方式跟着运行 Peach 的那台电脑走(`/api/media-processing`),和配置页「视频预览」同一个查询键。
- 打开面板时能不能改配置先回 null,确认能改才取数:每次打开都这样走一遍,取回的就是那台电脑此刻的值。
+/* 转码方式跟着运行 Peach 的那台电脑走(`/api/media-processing`),和配置页「视频预览」同一个查询键。
+ 挂上时取一次,之后每次打开面板(`epoch` 换代)再取一次,读到的是那台电脑此刻的值。
改完先存到服务端,往返期间下拉停在新值、挂忙态,失败退回原值。 */
-function TranscodeRow({ host: current, epoch, ready }: { host: SettingsPanelHost; epoch: number; ready: boolean }) {
- const policy = useQuery({ queryKey: MEDIA_PROCESSING_KEY, queryFn: ({ signal }) => fetchMediaProcessing(signal), enabled: ready });
+function TranscodeRow({ host: current, epoch }: { host: SettingsPanelHost; epoch: number }) {
+ const policy = useQuery({ queryKey: MEDIA_PROCESSING_KEY, queryFn: ({ signal }) => fetchMediaProcessing(signal) });
+ const refetch = policy.refetch;
+ const opened = useRef(epoch);
+ useEffect(() => {
+ if (opened.current === epoch) return;
+ opened.current = epoch;
+ void refetch();
+ }, [epoch, refetch]);
const save = useMutation({
mutationFn: (mode: string) => apiSend<MediaProcessingPolicy>(MEDIA_PROCESSING_URL, { playback_acceleration: mode }),
- onSuccess: (saved) => { queryClient.setQueryData(MEDIA_PROCESSING_KEY, saved); current.receipt('已保存播放编解码方式') },
- onError: (error) => current.failure('保存播放编解码方式', error),
+ onSuccess: (saved) => { queryClient.setQueryData(MEDIA_PROCESSING_KEY, saved); current.receipt('已保存转码方式') },
+ onError: (error) => current.failure('保存转码方式', error),
});
const value = save.isPending ? save.variables : policy.data?.playback_acceleration || 'auto';
return (
- <Row title="编解码方式" description="用于播放时的视频转码。">
- <SelectField id="playbackAccelerationSetting" label="播放编解码方式" options={TRANSCODE_OPTIONS} value={value}
- disabled={!ready || !policy.data} busy={save.isPending} epoch={epoch} onPick={(mode) => save.mutate(mode)} />
+ <Row title="转码方式">
+ <SelectField id="playbackAccelerationSetting" label="转码方式" options={TRANSCODE_OPTIONS} value={value}
+ disabled={!policy.data} busy={save.isPending} epoch={epoch} onPick={(mode) => save.mutate(mode)} />
</Row>
);
}
diff --git a/frontend/src/react/settings/media-processing-settings.tsx b/frontend/src/react/settings/media-processing-settings.tsx
index b8e9fa70d..f7580d0c2 100644
--- a/frontend/src/react/settings/media-processing-settings.tsx
+++ b/frontend/src/react/settings/media-processing-settings.tsx
@@ -1,5 +1,5 @@
/* 「视频预览」:这台机器为本地视频生成九宫格与时间轴预览的总开关、时间轴档位与抽帧解码方式。
- * 总开关在前,依赖它的档位次之,少改的解码方式最后。播放转码的编解码方式与其它播放设置同在
+ * 总开关在前,依赖它的档位次之,少改的解码方式最后。播放时的转码方式与其它播放设置同在
* 设置弹窗的「浏览与播放」,两处读写同一个 `['media-processing']` 键。 */
import { useQuery } from '@tanstack/react-query';
import { SettingsRow } from '@/components/application/settings/settings-rows';
diff --git a/frontend/test/react/settings-panel.test.tsx b/frontend/test/react/settings-panel.test.tsx
index 6229cbf72..61e79eaa1 100644
--- a/frontend/test/react/settings-panel.test.tsx
+++ b/frontend/test/react/settings-panel.test.tsx
@@ -189,7 +189,7 @@ describe('设置面板与壳的接缝', () => {
const headings = (index: number) => [...panel.querySelectorAll(`#settings-group-${index} [data-settings-subheading]`)]
.map((node) => node.textContent);
expect([headings(1), headings(2)]).toEqual([['作品列表', '播放'], ['作品显示', '新作显示']]);
- /* 编解码方式写运行 Peach 那台电脑的配置:不能改配置的设备上不出现。 */
+ /* 转码方式写运行 Peach 那台电脑的配置:不能改配置的设备上不出现。 */
expect(panel.querySelector('#playbackAccelerationSetting')).toBeNull();
const entry = panel.querySelector<HTMLButtonElement>('[data-settings-service] button')!;
expect(entry.disabled).toBe(true);
@@ -249,10 +249,12 @@ describe('设置面板与壳的接缝', () => {
await close(current);
});
- it('编解码方式:读写 /api/media-processing,成功后回执,不落浏览器那一份偏好', async () => {
+ it('转码方式:读写 /api/media-processing,成功后回执,不落浏览器那一份偏好;再打开面板重取', async () => {
const sent: unknown[] = [];
+ let reads = 0;
vi.stubGlobal('fetch', vi.fn(async (url: string, init?: RequestInit) => {
if (init?.method === 'POST') sent.push([url, JSON.parse(String(init.body))]);
+ else if (String(url).startsWith('/api/media-processing')) reads += 1;
const body = String(url).startsWith('/api/media-processing')
? { metadata_only: false, preview_acceleration: 'auto', playback_acceleration: init?.method === 'POST' ? 'software' : 'auto' }
: {};
@@ -270,9 +272,15 @@ describe('设置面板与壳的接缝', () => {
await click(field.querySelector('[data-select-option="software"]'));
await settle();
expect(sent).toEqual([['/api/media-processing', { playback_acceleration: 'software' }]]);
- expect(receipt).toHaveBeenCalledWith('已保存播放编解码方式');
+ expect(receipt).toHaveBeenCalledWith('已保存转码方式');
expect(current.save).not.toHaveBeenCalled();
await close(current);
+ const before = reads;
+ await open(current);
+ await settle();
+ expect(reads).toBe(before + 1);
+ expect(panel.querySelector('#playbackAccelerationSetting')).toBe(field);
+ await close(current);
});
it('「增加对比度」是一枚开关:按下交给壳切实色背景', async () => {
diff --git a/web/dist/peach-app.js b/web/dist/peach-app.js
index fa64622b2..1d73cc884 100644
--- a/web/dist/peach-app.js
+++ b/web/dist/peach-app.js
@@ -2,7 +2,7 @@
(function() {
try {
var e = typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {}, t = new e.Error().stack;
- t && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[t] = "95cfe51b-810a-455e-9ee9-1e47141b4a01", e._sentryDebugIdIdentifier = "sentry-dbid-95cfe51b-810a-455e-9ee9-1e47141b4a01");
+ t && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[t] = "9056bcfe-beeb-467d-ae9b-3705f826fc8f", e._sentryDebugIdIdentifier = "sentry-dbid-9056bcfe-beeb-467d-ae9b-3705f826fc8f");
} catch {}
})();
var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), s = (e, n) => {
@@ -80794,7 +80794,9 @@ function $Ue(e, t) {
r && (r.textContent = t ? "升序" : "降序");
}
function eWe({ host: e, tab: t, epoch: n, configurable: r }) {
- let i = e.store.value, a = () => e.store.save(), o = i.defaultSort === "seed", s = i.defaultSortDirection === "asc";
+ let i = e.store.value, a = () => e.store.save(), [o, s] = (0, E.useState)(null);
+ r !== null && r !== o && s(r);
+ let c = i.defaultSort === "seed", l = i.defaultSortDirection === "asc";
return /* @__PURE__ */ (0, D.jsxs)(AU, {
index: 1,
tab: t,
@@ -80835,14 +80837,14 @@ function eWe({ host: e, tab: t, epoch: n, configurable: r }) {
id: "defaultSortDirectionSetting",
label: "默认排序方向",
options: zUe,
- value: s ? "asc" : "desc",
- hidden: o,
- disabled: o,
+ value: l ? "asc" : "desc",
+ hidden: c,
+ disabled: c,
epoch: n,
onPick: (t) => {
i.defaultSortDirection = t, a(), e.changed("sortDirection");
},
- decorate: (e) => $Ue(e, s)
+ decorate: (e) => $Ue(e, l)
})]
})
}),
@@ -80896,11 +80898,10 @@ function eWe({ host: e, tab: t, epoch: n, configurable: r }) {
host: e,
epoch: n
}),
- r === !1 ? null : /* @__PURE__ */ (0, D.jsx)(aWe, {
+ (r ?? o) === !0 ? /* @__PURE__ */ (0, D.jsx)(aWe, {
host: e,
- epoch: n,
- ready: r === !0
- })
+ epoch: n
+ }) : null
]
});
}
@@ -81028,30 +81029,32 @@ function rWe({ host: e, epoch: t }) {
] });
}
var iWe = [["auto", "自动(硬件优先)"], ["software", "软件编解码"]];
-function aWe({ host: e, epoch: t, ready: n }) {
- let r = vt({
+function aWe({ host: e, epoch: t }) {
+ let n = vt({
queryKey: NL,
- queryFn: ({ signal: e }) => kMe(e),
- enabled: n
- }), i = yt({
+ queryFn: ({ signal: e }) => kMe(e)
+ }), r = n.refetch, i = (0, E.useRef)(t);
+ (0, E.useEffect)(() => {
+ i.current !== t && (i.current = t, r());
+ }, [t, r]);
+ let a = yt({
mutationFn: (e) => U(ML, { playback_acceleration: e }),
onSuccess: (t) => {
- W.setQueryData(NL, t), e.receipt("已保存播放编解码方式");
+ W.setQueryData(NL, t), e.receipt("已保存转码方式");
},
- onError: (t) => e.failure("保存播放编解码方式", t)
- }), a = i.isPending ? i.variables : r.data?.playback_acceleration || "auto";
+ onError: (t) => e.failure("保存转码方式", t)
+ }), o = a.isPending ? a.variables : n.data?.playback_acceleration || "auto";
return /* @__PURE__ */ (0, D.jsx)(MU, {
- title: "编解码方式",
- description: "用于播放时的视频转码。",
+ title: "转码方式",
children: /* @__PURE__ */ (0, D.jsx)(cH, {
id: "playbackAccelerationSetting",
- label: "播放编解码方式",
+ label: "转码方式",
options: iWe,
- value: a,
- disabled: !n || !r.data,
- busy: i.isPending,
+ value: o,
+ disabled: !n.data,
+ busy: a.isPending,
epoch: t,
- onPick: (e) => i.mutate(e)
+ onPick: (e) => a.mutate(e)
})
});
}
@@ -116860,4 +116863,4 @@ KSt(qSt);
//#endregion
export { vT as applyTheme, mN as peachHistory, qo as popCount, wvt as showToast };
-//# debugId=95cfe51b-810a-455e-9ee9-1e47141b4a01
\ No newline at end of file
+//# debugId=9056bcfe-beeb-467d-ae9b-3705f826fc8f
\ No newline at end of file