fix(scrape): 整理后刮削照 MP 对作品目录刮,集只刮本次整理的文件

原地入库逐个文件排刮削,单文件刮削只写该集,剧集根目录(tvshow.nfo、海报、季海报)与季目录
(season.nfo)没有元数据。照 MP ScrapingChain.scrape_metadata_event:按作品目录分组,目录元数据照常
初始化,集只刮本次文件;复制 / 移动同样改为只刮本次文件(此前刮整个作品目录)。

- 迁移 0062:scrape_record.videos(null = 目录下全部)
- queueScrape 支持 videos;同目录排队中还没开始的刮削合成一批(有一方刮全部则刮全部)
- 作品详情「重新刮削」与文件管理刮削不变(目录下全部)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-10-02 18:20:52 +08:00
1 parent 501b4eb403
commit f5bc6e9c40
7 files changed
+110 -36

No files matched your search

@@ -183,7 +183,8 @@ describe.skipIf(!hasPg)("刮削:NFO 与图片写进媒体库目录", () => {
const rec = await organize(series, "Severance.S01E01.1080p.WEB-DL.H264-GRP.mkv");
await organize(series, "Severance.S01E02.1080p.WEB-DL.H264-GRP.mkv");
const q = h.engine.enqueued.filter((x) => x.task === SCRAPE_TASK);
expect(q[0]!.key).toBe(`${SCRAPE_TASK}:record:${rec}:0`);
// 照 MP:对作品目录刮,集只刮本次整理的文件;两批还没开始时合成一条
expect(q[0]!.key.startsWith(`${SCRAPE_TASK}:record:${rec}:`)).toBe(true);
const first = await h.db
.selectFrom("scrape_record")
.selectAll()
@@ -3,6 +3,7 @@ import { mkdir, readdir, readFile, stat, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { executeRecord } from "../../src/modules/acquisition-organize/services/organize.ts";
import { runScrapeRecord } from "../../src/modules/acquisition-organize/services/scrape.ts";
import { createFmHarness, type FmHarness, key, pgAvailable, seedEntity } from "./harness.ts";
const skip = !(await pgAvailable());
@@ -100,6 +101,37 @@ describe.skipIf(skip)("file manager in-place import", () => {
.execute();
expect(units.some((u) => u.season_number === 2 && u.episode_number === 7)).toBe(true);
});
it("剧集原地入库后照 MP 刮削:剧集根目录与季目录写元数据,集只刮本次登记的", async () => {
const title = `Show-${randomUUID().slice(0, 8)}`;
const entity = await seedEntity(h.db, { title, kind: "series", year: 2022 });
const at = new Date().toISOString();
await h.db
.updateTable("media_entity")
.set({
metadata: JSON.stringify({ title: { value: title, source: "tmdb", language: "zh-CN", at, locked: false } }),
})
.where("id", "=", entity)
.execute();
await mkdir(join(h.lib, title, "Season 1"), { recursive: true });
const ep1 = `${title}/Season 1/original.name.S01E01.mkv`;
const ep2 = `${title}/Season 1/original.name.S01E02.mkv`;
for (const p of [ep1, ep2]) await writeFile(join(h.lib, p), "video");
const r = await queue([{ root: h.libRoot, path: ep1, mediaEntityId: entity }], { scrapeAfterImport: true });
expect((await executeRecord(h.module.deps().ao, r.recordId)).status).toBe("succeeded");
const recs = await h.db
.selectFrom("scrape_record")
.select(["id", "path", "videos"])
.where("organization_record_id", "=", r.recordId)
.execute();
expect(recs).toMatchObject([{ path: title, videos: [ep1] }]);
await runScrapeRecord(h.module.deps().ao, recs[0]!.id);
const show = await readdir(join(h.lib, title));
const season = await readdir(join(h.lib, title, "Season 1"));
expect(show).toContain("tvshow.nfo");
expect(season).toContain("season.nfo");
expect(season).toContain("original.name.S01E01.nfo");
expect(season).not.toContain("original.name.S01E02.nfo");
});
it("scrapes only the newly registered file, retaining its organization association on resume", async () => {
const s = await source("Scrape");
await h.db
@@ -118,10 +150,13 @@ describe.skipIf(skip)("file manager in-place import", () => {
await executeRecord(h.module.deps().ao, r.recordId);
const scrapes = await h.db
.selectFrom("scrape_record")
.select(["path", "organization_record_id"])
.select(["path", "organization_record_id", "videos"])
.where("organization_record_id", "=", r.recordId)
.execute();
expect(scrapes).toEqual([{ path: s.path, organization_record_id: r.recordId }]);
// 照 MP:对作品目录刮(目录海报 / 背景照常),视频只刮本次登记的这一个
expect(scrapes).toEqual([
{ path: s.path.split("/").slice(0, -1).join("/"), organization_record_id: r.recordId, videos: [s.path] },
]);
expect(await readFile(join(h.lib, s.path.split("/")[0]!, "Unrelated.mkv"), "utf8")).toBe("unrelated video");
});
it("rejects an unregistered download directory without submitting a task", async () => {