Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit c466374c489a17c82d749ac36d679ffc34f9b70c
parent fc5f479e6e275718b5654b581fbbe485634171b5
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 12:55:33 -0500

vtt: short-form cue timings (mm:ss.mmm) as a second reading, the old line untouched

A line is first read exactly as before: hh:mm:ss.mmm on both sides, found
anywhere in the line, not range-checked. Only a line that reading does not
match is tried as a short-form cue line -- anchored, minutes and seconds 00-59,
three millisecond digits, hours optional on either side and of any length. So a
document gains cues it could not have before and loses or moves none.

Short-form word tags (<mm:ss.mmm>) make a document rolling only when it has no
hh:mm:ss.mmm tag and no hh:mm:ss.mmm cue line, i.e. when the old parser read
nothing from it; a document it could read keeps its shape, and a short tag in
one stays text as it was.

The contributed change tightened the one reading for every corpus instead
(anchored, range-checked, NaN for 0); this takes its short-form grammar and
leaves the rest. Five local-media test files go back to the short-form
fixtures they were contributed with, and the scan's short-timestamp test
asserts an importable row again.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/controller/buildIndexLocalRecording.test.ts | 2+-
Mcommon/controller/localMediaImport.test.ts | 6+++---
Mcommon/lib/localMediaCommit-server.test.ts | 2+-
Mcommon/lib/localMediaScan.test.ts | 13+++++--------
Mcommon/lib/localMediaTranscript.test.ts | 2+-
Mcommon/lib/vtt.ts | 66+++++++++++++++++++++++++++++++++++++++++++++++++++---------------
6 files changed, 62 insertions(+), 29 deletions(-)

diff --git a/common/controller/buildIndexLocalRecording.test.ts b/common/controller/buildIndexLocalRecording.test.ts @@ -39,7 +39,7 @@ const writeJson = (file: string, value: unknown) => { }; const channel = "classroom"; const dataDirectory = path.join(paths.channelsDir, channel, "data"); -const transcript = "WEBVTT\n\n00:00:00.000 --> 00:00:02.000\nSynthetic classroom discovery phrase\n"; +const transcript = "WEBVTT\n\n00:00.000 --> 00:02.000\nSynthetic classroom discovery phrase\n"; const first = "local-" + "a".repeat(32), second = "local-" + "b".repeat(32); const metadata = (id: string, recordedDate?: string) => prepareManualLocalRecordingMetadata({id, filename: "Lesson 2020-01-01.mp4", recordedDate}); diff --git a/common/controller/localMediaImport.test.ts b/common/controller/localMediaImport.test.ts @@ -17,7 +17,7 @@ async function fixture(t: TestContext) { async function add(name: string, id = name) { await writeFile(path.join(source, name + ".mp4"), "synthetic video"); await writeFile(path.join(source, name + ".info.json"), JSON.stringify({ id, title: "Synthetic", duration: 3, upload_date: "20261030", webpage_url: `https://www.youtube.com/watch?v=${id}` })); - await writeFile(path.join(source, name + ".vtt"), "WEBVTT\n\n00:00:01.000 --> 00:00:02.000\nSynthetic cue\n"); + await writeFile(path.join(source, name + ".vtt"), "WEBVTT\n\n00:01.000 --> 00:02.000\nSynthetic cue\n"); } return { root, source, paths, channel, config, add }; } @@ -48,7 +48,7 @@ test("preview creates nothing; import then rescan detects additions without chan }); test("changed transcript after preview is stale and no record is written", async (t) => { const f=await fixture(t); await f.add("first"); const p=await previewLocalMedia(f.paths,"sample"); - await writeFile(path.join(f.source,"first.vtt"),"WEBVTT\n\n00:00:01.000 --> 00:00:02.000\nChanged text\n"); + await writeFile(path.join(f.source,"first.vtt"),"WEBVTT\n\n00:01.000 --> 00:02.000\nChanged text\n"); const result=await importLocalMedia(f.paths,"sample",selection(p)); assert.equal(result.records[0].status,"stale"); assert.equal(result.needsIndexUpdate,false); assert.deepEqual(await readdir(f.channel),["config.json"]); @@ -173,7 +173,7 @@ test("managed job fails honestly for a stale selection after publishing another const f = await fixture(t); await f.add("first"); await f.add("second"); const p = await previewLocalMedia(f.paths, "sample"); const job = localMediaJobOptions(f.paths as Paths, "sample", selection(p)); - await writeFile(path.join(f.source, "second.vtt"), "WEBVTT\n\n00:00:01.000 --> 00:00:02.000\nChanged\n"); + await writeFile(path.join(f.source, "second.vtt"), "WEBVTT\n\n00:01.000 --> 00:02.000\nChanged\n"); const log: string[] = []; await assert.rejects(job.fn(line => log.push(line), new AbortController().signal, () => {}, jobContext()), /require review/); assert.deepEqual(await readdir(path.join(f.channel, "data")), ["first"]); diff --git a/common/lib/localMediaCommit-server.test.ts b/common/lib/localMediaCommit-server.test.ts @@ -11,7 +11,7 @@ async function fixture(t: TestContext) { const dataDirectory = path.join(root, "data"); await mkdir(dataDirectory); const input = { dataDirectory, directoryId: "test-id", metadata: JSON.stringify({ id: "test-id", title: "Synthetic", duration: 3, upload_date: "20261030", webpage_url: "https://www.youtube.com/watch?v=test-id" }), - transcript: "WEBVTT\r\n\r\n00:00:01.000 --> 00:00:02.000\r\nSynthetic cue\r\n", + transcript: "WEBVTT\r\n\r\n00:01.000 --> 00:02.000\r\nSynthetic cue\r\n", reference: { version: 1, kind: "external", sourceId: "library-1", relativePath: "Original ⧸ $title.mp4" } }; return { root, input, target: path.join(dataDirectory, "test-id") }; } diff --git a/common/lib/localMediaScan.test.ts b/common/lib/localMediaScan.test.ts @@ -145,22 +145,19 @@ test("read-only source files remain readable and unchanged", async (t) => { } finally { for (const file of files) await chmod(path.join(root, file), 0o644); } }); -// The parser reads only hh:mm:ss.mmm cue timings until slice 2 lands its -// short-form support (with a corpus regression check). Until then a short-form -// VTT is held for review, never imported with missing or misread cues. -test("short-form timestamps are held for review, not imported", async (t) => { +test("short timestamps produce index-compatible cues", async (t) => { const root = await fixture(t); await add(root, "short"); await writeFile(path.join(root, "short.vtt"), "WEBVTT\n\n00:00.250 --> 00:01.910\nShort cue\n"); const row = (await scan(root)).candidates[0]; - assert.equal(row.status, "issue"); - assert.match(row.issues.join(), /no usable cues/); - assert.equal(row.fingerprint, undefined); + assert.equal(row.status, "new"); + assert.equal(row.cueCount, 1); + assert.deepEqual(row.warnings, []); }); test("isolated zero-duration cues warn without changing source; all-point transcripts remain blocked", async (t) => { const root = await fixture(t); await add(root, "mixed"); await add(root, "points"); - const point = "00:00:03.000 --> 00:00:03.000\nPoint cue\n"; + const point = "00:03.000 --> 00:03.000\nPoint cue\n"; const mixed = VTT + "\n" + point; await writeFile(path.join(root, "mixed.vtt"), mixed); await writeFile(path.join(root, "points.vtt"), "WEBVTT\n\n" + point); diff --git a/common/lib/localMediaTranscript.test.ts b/common/lib/localMediaTranscript.test.ts @@ -7,7 +7,7 @@ test("SRT preserves multiline Unicode dialogue, emphasis, overlaps and milliseco assert.equal(srtToVtt(input), "WEBVTT\n\n00:00:01.001 --> 00:00:03.999\n<i>Hello</i> &amp; welcome\n録画\n\n00:00:02.050 --> 00:00:04.500\nSecond line\n"); }); test("VTT remains byte-for-byte text and SRT freshness includes unconverted source", () => { - const vtt = "\uFEFFWEBVTT\r\n\r\n00:00:01.000 --> 00:00:02.000\r\nHi\r\n"; + const vtt = "\uFEFFWEBVTT\r\n\r\n00:01.000 --> 00:02.000\r\nHi\r\n"; assert.equal(localTranscriptVtt("lesson.vtt", vtt), vtt); assert.equal(localTranscriptFingerprint("lesson.vtt",vtt), vtt); const srt = "1\n00:00:01,000 --> 00:00:02,000\nHi\n"; diff --git a/common/lib/vtt.ts b/common/lib/vtt.ts @@ -1,12 +1,39 @@ export type Cue = { start: number; end: number; text: string }; const TIMING_TAG_RE = /<\d{2}:\d{2}:\d{2}\.\d{3}>/; +// The cue line every existing corpus is read with: hh:mm:ss.mmm on both sides, +// found ANYWHERE in the line and not range-checked. Lenient on purpose now — +// every published site's cues came through it, so a line it matches is read +// exactly as it always was (vtt.test.ts pins the leniencies). +const CUE_TIMING_RE = + /(\d{2}:\d{2}:\d{2}\.\d{3})\s+-->\s+(\d{2}:\d{2}:\d{2}\.\d{3})/; + +// SHORT FORM (mm:ss.mmm — legal WebVTT, what FFmpeg and hand-made subtitle +// files write). Tried only on a line CUE_TIMING_RE did not match, so it can add +// cues to a document and never change one: it is strict where the old line is +// lenient (anchored, minutes and seconds 00–59, exactly three millisecond +// digits), either side may carry hours, and hours may exceed two digits. +const SHORT_TIMESTAMP = "(?:\\d{2,}:)?[0-5]\\d:[0-5]\\d\\.\\d{3}"; +const SHORT_TIMING_TAG_RE = new RegExp("<" + SHORT_TIMESTAMP + ">"); +const SHORT_TIMING_TAG_RE_G = new RegExp("<" + SHORT_TIMESTAMP + ">", "g"); +const SHORT_CUE_TIMING_RE = new RegExp( + "^[ \\t]*(" + SHORT_TIMESTAMP + ")[ \\t]+-->[ \\t]+(" + SHORT_TIMESTAMP + ")(?:[ \\t].*)?$", +); + +// A rolling track written with short-form word tags (<mm:ss.mmm>). It counts +// only in a document with no hh:mm:ss.mmm tag and no hh:mm:ss.mmm cue line — +// one the old parser read no cue from — so a document it could read keeps the +// shape it was always read as. +function hasShortWordTiming(src: string): boolean { + if (!SHORT_TIMING_TAG_RE.test(src)) return false; + return !src.split("\n").some((line) => CUE_TIMING_RE.test(line)); +} -// Whether VTT text carries inline word timing (<hh:mm:ss.mmm>) — the mark of -// YouTube's rolling auto-caption shape, which parseVtt reads differently from -// plain cue blocks. +// Whether VTT text carries inline word timing (<hh:mm:ss.mmm>, or <mm:ss.mmm> +// in a short-form document) — the mark of YouTube's rolling auto-caption +// shape, which parseVtt reads differently from plain cue blocks. export function hasWordTiming(src: string): boolean { - return TIMING_TAG_RE.test(src); + return TIMING_TAG_RE.test(src) || hasShortWordTiming(src); } function parseTimestamp(ts: string): number { @@ -16,6 +43,14 @@ function parseTimestamp(ts: string): number { return +h * 3600 + +mm * 60 + +s + +ms / 1000; } +// A stamp SHORT_CUE_TIMING_RE captured: hours optional. +function parseShortTimestamp(ts: string): number { + const m = ts.match(/^(?:(\d+):)?(\d{2}):(\d{2})\.(\d{3})$/); + if (!m) return Number.NaN; + const [, h = "0", mm, s, ms] = m; + return +h * 3600 + +mm * 60 + +s + +ms / 1000; +} + function decodeEntities(s: string): string { return s .replace(/&nbsp;/g, " ") @@ -26,9 +61,9 @@ function decodeEntities(s: string): string { .replace(/&quot;/g, '"'); } -function stripTags(s: string): string { +function stripTags(s: string, shortForm: boolean): string { return decodeEntities(s) - .replace(/<\d{2}:\d{2}:\d{2}\.\d{3}>/g, "") + .replace(shortForm ? SHORT_TIMING_TAG_RE_G : /<\d{2}:\d{2}:\d{2}\.\d{3}>/g, "") .replace(/<\/?c[^>]*>/g, "") .replace(/\s+/g, " ") .trim(); @@ -59,20 +94,21 @@ function stripPlainLine(s: string): string { export function parseVtt(src: string): Cue[] { const lines = src.replace(/\r\n/g, "\n").split("\n"); const cues: Cue[] = []; - const rolling = hasWordTiming(src); + const shortRolling = !TIMING_TAG_RE.test(src) && hasShortWordTiming(src); + const rolling = shortRolling || TIMING_TAG_RE.test(src); + const tagRe = shortRolling ? SHORT_TIMING_TAG_RE : TIMING_TAG_RE; let i = 0; while (i < lines.length) { const line = lines[i]; - const m = line.match( - /(\d{2}:\d{2}:\d{2}\.\d{3})\s+-->\s+(\d{2}:\d{2}:\d{2}\.\d{3})/, - ); - if (!m) { + const m = line.match(CUE_TIMING_RE); + const short = m ? null : line.match(SHORT_CUE_TIMING_RE); + if (!m && !short) { i++; continue; } - const start = parseTimestamp(m[1]); - const end = parseTimestamp(m[2]); + const start = m ? parseTimestamp(m[1]) : parseShortTimestamp(short![1]); + const end = m ? parseTimestamp(m[2]) : parseShortTimestamp(short![2]); i++; const body: string[] = []; while (i < lines.length && lines[i].trim() !== "") { @@ -84,9 +120,9 @@ export function parseVtt(src: string): Cue[] { if (!rolling) { text = body.map(stripPlainLine).filter(Boolean).join(" "); } else { - const taggedLines = body.filter((l) => TIMING_TAG_RE.test(l)); + const taggedLines = body.filter((l) => tagRe.test(l)); if (taggedLines.length === 0) continue; - text = stripTags(taggedLines[taggedLines.length - 1]); + text = stripTags(taggedLines[taggedLines.length - 1], shortRolling); } if (text) cues.push({ start, end, text });