import { test } from "node:test"; import assert from "node:assert/strict"; import { CLIPS_DIR, LIVE_CHAT_MEDIA_FILENAME, classifyEntry, classifyVideoDir, isTierable, } from "./mediaTier"; import { LIVE_CHAT_FILENAME } from "./videoStatus"; import { CLIPS_DIR_NAME } from "./clipWindow"; // Run with: // pnpm --filter yt-dlp-transcript-common exec tsx --test lib/mediaTier.test.ts test("the classifier's two copied names agree with their owners", () => { assert.equal(LIVE_CHAT_MEDIA_FILENAME, LIVE_CHAT_FILENAME); assert.equal(CLIPS_DIR, CLIPS_DIR_NAME); }); // THE TABLE. By name, never by size; every row is a name this corpus holds. const TABLE: ReadonlyArray<[string, "media" | "text" | "scratch", boolean]> = [ // [name, tier, tierable] ["audio.mp3", "media", true], ["audio.m4a", "media", true], ["audio.opus", "media", true], ["audio.mp4", "media", true], ["audio.webm", "media", true], ["source-media.mp4", "media", false], ["source-media.webm", "media", false], ["transcript.live_chat.json", "media", true], // A subtitle named like audio is TEXT (the isRealAudioFile anchoring). ["audio.en-orig.vtt", "text", false], ["audio.en.vtt", "text", false], // Somebody's scratch. ["audio.tmp-2760235.mp3", "scratch", false], ["source-media.temp.mp4", "scratch", false], ["audio.temp.mp3", "scratch", false], ["audio.m4a.part", "scratch", false], ["audio.m4a.part.good", "scratch", false], ["audio.m4a.part.testing", "scratch", false], ["audio.live_chat.json.part-Frag114", "scratch", false], ["transcript.live_chat.json.part", "scratch", false], ["audio.m4a.ytdl", "scratch", false], [".audio.mp3.parakeet", "scratch", false], [".audio.mp3.tierlink-4242", "scratch", false], [".audio.mp3.tiering-4242", "scratch", false], [".syncthing.audio.mp3.tmp", "scratch", false], // The hot text. ["transcript.json", "text", false], ["transcript.en.vtt", "text", false], ["transcript.en-orig.vtt", "text", false], ["transcript.cues.json", "text", false], ["live_chat.cues.json", "text", false], ["metadata.info.json", "text", false], ["metadata.history.json", "text", false], ["diarization.json", "text", false], ["saved-video.json", "text", false], ["clips", "text", false], ["thumbnail.jpg", "text", false], ]; for (const [name, tier, tierable] of TABLE) { test(`classifyEntry(${name}) = ${tier}, tierable ${tierable}`, () => { assert.equal(classifyEntry(name), tier); assert.equal(isTierable(name), tierable); }); } test("classifyVideoDir splits a listing by tier, in order", () => { const out = classifyVideoDir([ "metadata.info.json", "audio.mp3", "audio.tmp-1.mp3", "transcript.json", "transcript.live_chat.json", ]); assert.deepEqual(out, { media: ["audio.mp3", "transcript.live_chat.json"], text: ["metadata.info.json", "transcript.json"], scratch: ["audio.tmp-1.mp3"], }); }); test("every tierable name is media (tierable is narrower)", () => { for (const [name] of TABLE) { if (isTierable(name)) assert.equal(classifyEntry(name), "media", name); } });