Apply remaining working-tree updates

This commit is contained in:
2026-02-14 00:36:01 -08:00
parent cb9a599b23
commit a1209ca69f
40 changed files with 1001 additions and 607 deletions

View File

@@ -1,34 +1,14 @@
import test from "node:test";
import assert from "node:assert/strict";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import { getSubsyncConfig, runCommand } from "./utils";
import { codecToExtension } from "./utils";
test("getSubsyncConfig applies fallback executable paths for blank values", () => {
const config = getSubsyncConfig({
defaultMode: "manual",
alass_path: " ",
ffsubsync_path: "",
ffmpeg_path: undefined,
});
assert.equal(config.defaultMode, "manual");
assert.equal(config.alassPath, "/usr/bin/alass");
assert.equal(config.ffsubsyncPath, "/usr/bin/ffsubsync");
assert.equal(config.ffmpegPath, "/usr/bin/ffmpeg");
test("codecToExtension maps stream/web formats to ffmpeg extractable extensions", () => {
assert.equal(codecToExtension("subrip"), "srt");
assert.equal(codecToExtension("webvtt"), "vtt");
assert.equal(codecToExtension("vtt"), "vtt");
assert.equal(codecToExtension("ttml"), "ttml");
});
test("runCommand returns failure on timeout", async () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "subsync-utils-"));
const sleeperPath = path.join(tmpDir, "sleeper.sh");
fs.writeFileSync(sleeperPath, "#!/bin/sh\nsleep 2\n", {
encoding: "utf8",
mode: 0o755,
});
fs.chmodSync(sleeperPath, 0o755);
const result = await runCommand(sleeperPath, [], 50);
assert.equal(result.ok, false);
test("codecToExtension returns null for unsupported codecs", () => {
assert.equal(codecToExtension("unsupported-codec"), null);
});

View File

@@ -101,8 +101,16 @@ export function getTrackById(
export function codecToExtension(codec: string | undefined): string | null {
if (!codec) return null;
const normalized = codec.toLowerCase();
if (normalized === "subrip" || normalized === "srt") return "srt";
if (
normalized === "subrip" ||
normalized === "srt" ||
normalized === "text" ||
normalized === "mov_text"
)
return "srt";
if (normalized === "ass" || normalized === "ssa") return "ass";
if (normalized === "webvtt" || normalized === "vtt") return "vtt";
if (normalized === "ttml") return "ttml";
return null;
}