Files
UHD_Media_Tool/scripts/asset-spec-backfill.ts
T

56 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// LIBV-1 回填已入库视频资产的版本规格(media_asset.delivery)。默认只读(dry-run),加 --apply 才改库。
//
// 用法(DATABASE_URL 必须显式给出,脚本不带默认库):
// DATABASE_URL=… bun scripts/asset-spec-backfill.ts # 看清单:哪些资产会更新、前后规格
// DATABASE_URL=… bun scripts/asset-spec-backfill.ts --entity <作品 id> # 只看一部作品
// DATABASE_URL=… bun scripts/asset-spec-backfill.ts --probe # 对缺探测结果的本地文件跑 ffprobe(只读文件)
// DATABASE_URL=… bun scripts/asset-spec-backfill.ts --apply # 写库
// --json 输出 JSON;--limit N 只处理前 N 个资产
//
// 规格来源:库内文件名解析 + 已有 media_info.probe + 入库时记下的资源解析(media_info._umt.quality)。
// 不请求任何站点;--probe 只读库根里的本地文件。写回只合并 delivery 的键,可重复执行。
import { ffprobe } from "@umt/adapters";
import { createDb } from "@umt/db";
import { backfillVersionSpecs } from "../apps/server/src/modules/acquisition-organize/services/version-backfill.ts";
const argv = [...process.argv.slice(2)];
const APPLY = argv.includes("--apply");
if (APPLY && argv.includes("--dry-run")) {
console.error("--apply 与 --dry-run 不能同时给出");
process.exit(2);
}
const arg = (k: string) => {
const i = argv.indexOf(k);
return i >= 0 ? argv[i + 1] : undefined;
};
const url = process.env.DATABASE_URL;
if (!url) {
console.error("需要 DATABASE_URL(脚本不带默认库)");
process.exit(2);
}
const db = createDb({ connectionString: url, max: 2 });
try {
const report = await backfillVersionSpecs(db, {
apply: APPLY,
entityId: arg("--entity"),
limit: arg("--limit") ? Number(arg("--limit")) : undefined,
probe: argv.includes("--probe") ? (p) => ffprobe(p, { timeoutMs: 30_000 }) : undefined,
});
if (argv.includes("--json")) console.log(JSON.stringify(report, null, 2));
else {
console.log(`# asset-spec-backfill (${APPLY ? "APPLY" : "DRY-RUN"})\n`);
console.log(
`扫描 ${report.scanned} 个视频资产:已是当前口径 ${report.upToDate},${APPLY ? "已更新" : "将更新"} ${report.changed}` +
`,本次探测 ${report.probed},无库内位置 ${report.noLocation}\n`,
);
for (const it of report.items) {
console.log(`- [${it.reason}] ${it.entityTitle ?? "(无作品)"} · ${it.path ?? it.assetId}`);
console.log(` 前:${it.before}`);
console.log(` 后:${it.after}(来源 ${it.specFrom.join("+") || "无"})`);
}
}
} finally {
await db.destroy();
}