feat(search): align quick-filter facets with MP (SEARCH-4)
Add audioCodec, subtitle, dub, feature, year, category, size and seeders facets with disjunctive counts; parser records dub languages (audioLangs). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
c3b25be676
commit
d9cf8f1c3a
10 files changed
+409
-5
No files matched your search
@@ -1,11 +1,16 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
applyFacets,
|
||||
audioBuckets,
|
||||
type FacetInput,
|
||||
formatFacetParam,
|
||||
parseFacetParam,
|
||||
parseRelease,
|
||||
promotionBuckets,
|
||||
releaseTypeBucket,
|
||||
seedersBucket,
|
||||
sizeBucket,
|
||||
subtitleBuckets,
|
||||
} from "../src/index.ts";
|
||||
|
||||
// SEARCH-3 快速筛选:档位、计数(按其它维度已选条件)、同维度 OR / 跨维度 AND、qf 编解码
|
||||
@@ -186,4 +191,115 @@ describe("release-facets", () => {
|
||||
expect(parseFacetParam(s)).toEqual(sel);
|
||||
expect(parseFacetParam("bogus:1;hdr:;hdr:DV,DV")).toEqual({ hdr: ["DV"] });
|
||||
});
|
||||
|
||||
// ── SEARCH-4:对齐 MP 后新增的维度 ──
|
||||
|
||||
const GB = 1024 ** 3;
|
||||
const rich = [
|
||||
mk("a", {
|
||||
audio: ["TrueHD", "Atmos 7.1"],
|
||||
subtitles: ["zh-Hans", "en"],
|
||||
audioLangs: ["cmn"],
|
||||
bitDepth: 10,
|
||||
year: 2024,
|
||||
category: "电影",
|
||||
sizeBytes: 60 * GB,
|
||||
seeders: 80,
|
||||
}),
|
||||
mk("b", {
|
||||
audio: ["DDP 5.1"],
|
||||
subtitles: ["zh-Hant"],
|
||||
audioLangs: ["cmn", "yue"],
|
||||
fps: 60,
|
||||
year: 2023,
|
||||
category: "电影",
|
||||
sizeBytes: 8 * GB,
|
||||
seeders: 0,
|
||||
}),
|
||||
mk("c", { audio: ["DTS-HD MA 5.1", "2Audios"], year: 2024, category: "剧集", sizeBytes: 3 * GB, seeders: 12 }),
|
||||
mk("d", { audio: [], cut: "Extended", sizeBytes: null, seeders: null }),
|
||||
];
|
||||
const run2 = (sel: Parameters<typeof applyFacets>[2]) => applyFacets(rich, (x) => x, sel, { now: NOW });
|
||||
|
||||
it("新维度档位与计数:音频 / 字幕 / 配音 / 特性 / 年份 / 分类 / 大小 / 做种", () => {
|
||||
const r = run2({});
|
||||
expect(counts(r.facets.audioCodec)).toEqual({
|
||||
Atmos: 1,
|
||||
TrueHD: 1,
|
||||
"DTS-HD": 1,
|
||||
DTS: 0,
|
||||
DDP: 1,
|
||||
DD: 0,
|
||||
AAC: 0,
|
||||
unknown: 1,
|
||||
});
|
||||
expect(r.facets.audioCodec.find((o) => o.value === "DDP")?.label).toBe("DD+");
|
||||
expect(counts(r.facets.subtitle)).toEqual({ zh: 2, "zh-Hans": 1, "zh-Hant": 1, en: 1, unknown: 2 });
|
||||
expect(counts(r.facets.dub)).toEqual({ cmn: 2, yue: 1, unknown: 2 });
|
||||
expect(counts(r.facets.feature)).toEqual({ "10bit": 1, hfr: 1, cut: 1 });
|
||||
// 年份新的在前;分类按条数
|
||||
expect(r.facets.year.map((o) => [o.value, o.count])).toEqual([
|
||||
["2024", 2],
|
||||
["2023", 1],
|
||||
]);
|
||||
expect(r.facets.category.map((o) => [o.label, o.count])).toEqual([
|
||||
["电影", 2],
|
||||
["剧集", 1],
|
||||
]);
|
||||
expect(counts(r.facets.size)).toEqual({
|
||||
lt1: 0,
|
||||
"1-5": 1,
|
||||
"5-10": 1,
|
||||
"10-20": 0,
|
||||
"20-50": 0,
|
||||
"50+": 1,
|
||||
unknown: 1,
|
||||
});
|
||||
expect(counts(r.facets.seeders)).toEqual({ "0": 1, "1-9": 0, "10-49": 1, "50+": 1, unknown: 1 });
|
||||
});
|
||||
|
||||
it("新维度组合:同维度 OR、跨维度 AND,计数按其它维度已选条件", () => {
|
||||
// 中文字幕 AND 国语 → a、b;再加 Atmos → 只剩 a
|
||||
expect(ids(run2({ subtitle: ["zh"], dub: ["cmn"] }))).toEqual(["a", "b"]);
|
||||
const r = run2({ subtitle: ["zh"], dub: ["cmn"], audioCodec: ["Atmos"] });
|
||||
expect(ids(r)).toEqual(["a"]);
|
||||
// 音频维度自己的计数不受已选 Atmos 影响:DD+ 仍可多出 b
|
||||
expect(counts(r.facets.audioCodec).DDP).toBe(1);
|
||||
// 同维度 OR:Atmos 或 DTS-HD
|
||||
expect(ids(run2({ audioCodec: ["Atmos", "DTS-HD"] }))).toEqual(["a", "c"]);
|
||||
// 年份 × 分类 × 做种
|
||||
expect(ids(run2({ year: ["2024"], category: ["电影", "剧集"], seeders: ["10-49", "50+"] }))).toEqual(["a", "c"]);
|
||||
expect(ids(run2({ size: ["unknown"], feature: ["cut"] }))).toEqual(["d"]);
|
||||
// 已选但当前没有资源的年份列出、计数 0
|
||||
expect(run2({ year: ["1999"] }).facets.year.find((o) => o.value === "1999")).toEqual({
|
||||
value: "1999",
|
||||
label: "1999",
|
||||
count: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it("新维度的归档函数", () => {
|
||||
expect(audioBuckets(["E-AC3", "AC3 2.0", "PCM", "Opus", "5.1"])).toEqual(["DDP", "DD", "LPCM", "other"]);
|
||||
expect(audioBuckets(["2Audios"])).toEqual(["unknown"]);
|
||||
expect(subtitleBuckets(["zh"])).toEqual(["zh"]);
|
||||
expect(subtitleBuckets(null)).toEqual(["unknown"]);
|
||||
expect([0.5 * GB, GB, 49.9 * GB, 50 * GB, null, -1].map(sizeBucket)).toEqual([
|
||||
"lt1",
|
||||
"1-5",
|
||||
"20-50",
|
||||
"50+",
|
||||
"unknown",
|
||||
"unknown",
|
||||
]);
|
||||
expect([0, 9, 10, 50, null].map(seedersBucket)).toEqual(["0", "1-9", "10-49", "50+", "unknown"]);
|
||||
});
|
||||
|
||||
it("解析器补齐配音语言(MP 的 CNVOI / HKVOI)", () => {
|
||||
expect(parseRelease("Movie 2020 1080p 国语中字 WEB-DL").audioLangs).toEqual(["cmn"]);
|
||||
expect(parseRelease("某剧 第01集 国粤双语 1080p").audioLangs).toEqual(["cmn", "yue"]);
|
||||
expect(parseRelease("Movie.2020.1080p.BluRay.x264-GRP").audioLangs).toBeUndefined();
|
||||
expect(
|
||||
parseRelease("Movie.2020.2160p.BluRay.x265-GRP", { subtitle: "电影 | 国英双语 简繁字幕" }).audioLangs,
|
||||
).toEqual(["cmn", "en"]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user