Archilyzer · Source

archilyzer

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

commit 3a72d4456a38182b2006f5be65b5d006df3b3803
parent 0152ab6a690e874169fa1a75cca21bae89ae9de1
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu, 22 Oct 2026 15:28:23 -0400

import-media reuses attach-media's hashed copy and local-archive provenance; an attached container is protected from a shorter download too

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mcommon/controller/landMedia.test.ts | 5+++++
Mcommon/controller/landMedia.ts | 32+++++++++++++++++++++++++-------
Mcommon/ytdlp/landedGuard.ts | 4+++-
Mplans/live-capture.md | 11++++++++++-
4 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/common/controller/landMedia.test.ts b/common/controller/landMedia.test.ts @@ -118,6 +118,11 @@ test("keep the longer: a shorter file is not landed, the store and the original await stat(short); // not moved: nothing was landed from it const pointer = await loadSavedVideo(dir); assert.match(await readFile(path.join(pointer!.dir, pointer!.file), "utf8"), /seconds=5000/); + // attach-media's provenance: the directory, the entry, the copied bytes' sha256. + assert.equal(pointer?.origin?.kind, "local-archive"); + assert.equal(pointer?.origin?.entry, "long.mp4"); + assert.match(pointer?.sha256 ?? "", /^[0-9a-f]{64}$/); + assert.equal(pointer?.origin?.sha256, pointer?.sha256); // replace lands it anyway. const r2 = await landMediaFile({ paths, slug: SLUG, channelConfig: CONFIG, videoId: "v2", sourcePath: short, via: "import-media", replace: true, onLog, signal, deps }); assert.equal(r2.kept, "new"); diff --git a/common/controller/landMedia.ts b/common/controller/landMedia.ts @@ -8,7 +8,7 @@ // landed only when it is longer (or `replace`); a shorter one is left // where it was found, untouched. // 3. FINALIZE into a staging file beside the store dir, on the store's disk: -// a stream copy (`copy`, or a rename when `move` and the same disk) or a +// attach-media's hashed copy (copyFileHashed; a rename when `move` and the same disk) or a // `-c copy` remux through the heavy slot (preparePlayable.ts // ffmpegRemux). Verified: the bytes for a copy, ffprobe and the length for // a remux. @@ -33,7 +33,8 @@ // plus a margin free. import path from "node:path"; -import { appendFile, copyFile, mkdir, readFile, readdir, rename, rm, stat } from "node:fs/promises"; +import { appendFile, mkdir, readFile, readdir, rename, rm, stat } from "node:fs/promises"; +import { copyFileHashed } from "../lib/zipReader"; import { execa } from "execa"; import type { AudioFormat, ChannelConfig } from "../lib/channelConfig"; import type { Paths } from "../lib/paths"; @@ -284,6 +285,7 @@ export async function landMediaFile(opts: LandMediaOpts): Promise<LandMediaResul await mkdir(slugDir, { recursive: true }); const staging = path.join(slugDir, `.${opts.videoId}.land-${process.pid}.part`); await rm(staging, { force: true }); + let sha256: string | undefined; try { if (fin.action === "copy") { if (opts.move && (await sameDevice(opts.sourcePath, slugDir))) { @@ -291,11 +293,12 @@ export async function landMediaFile(opts: LandMediaOpts): Promise<LandMediaResul moved = true; say(`Moved ${opts.sourcePath} into the store's staging (same disk).`); } else { - await copyFile(opts.sourcePath, staging); - const copied = await stat(staging); - if (copied.size !== st.size) { - throw new Error(`the copy of ${name} is ${copied.size} bytes, the file ${st.size}`); + // attach-media's copy of a directory entry: bytes counted, sha256'd. + const copied = await copyFileHashed(opts.sourcePath, staging, { signal: opts.signal }); + if (copied.bytes !== st.size) { + throw new Error(`the copy of ${name} is ${copied.bytes} bytes, the file ${st.size}`); } + sha256 = copied.sha256; } } else { const remux = opts.deps?.remux ?? ((s: string, d: string, a: string[], sig?: AbortSignal) => ffmpegRemux(opts.paths, s, d, a, sig)); @@ -312,10 +315,24 @@ export async function landMediaFile(opts: LandMediaOpts): Promise<LandMediaResul ) { throw new Error(`the landed copy is ${Math.round(check.seconds)} s, the file ${Math.round(probed.seconds)} s`); } + const at = now().toISOString(); + // An imported file carries attach-media's provenance (the directory, the + // entry, the bytes' sha256 when copied — `kind: "local-archive"`), so the + // video page says where it came from the same way; a live recording + // names only who made it. const origin: SavedVideoOrigin = { requestedBy: opts.via, - requestedAt: now().toISOString(), + requestedAt: at, reason: opts.note ?? (opts.via === "record-live" ? "a live recording" : `imported from ${opts.sourcePath}`), + ...(opts.via === "import-media" + ? { + kind: "local-archive" as const, + archive: path.dirname(opts.sourcePath), + entry: name, + attachedAt: at, + ...(sha256 ? { sha256 } : {}), + } + : {}), }; const landed = await persistSourceVideo({ videoDir, @@ -324,6 +341,7 @@ export async function landMediaFile(opts: LandMediaOpts): Promise<LandMediaResul storeDir, keepReason: "pin", origin, + ...(sha256 ? { sha256 } : {}), paths: opts.paths, }); containerPath = savedVideoPath(landed); diff --git a/common/ytdlp/landedGuard.ts b/common/ytdlp/landedGuard.ts @@ -40,7 +40,9 @@ export type LandedGuardDeps = { export type LandedGuardPlan = { videoDir: string; asides: string[] }; -const LANDED_BY: ReadonlySet<string> = new Set(["import-media", "record-live"]); +// attach-media too: a container attached from a local archive is a recording +// somebody kept on purpose (keepReason "pin"), as an import is. +const LANDED_BY: ReadonlySet<string> = new Set(["import-media", "record-live", "attach-media"]); // Was this video's source landed (rather than downloaded)? export async function isLandedVideo(videoDir: string): Promise<boolean> { diff --git a/plans/live-capture.md b/plans/live-capture.md @@ -84,7 +84,7 @@ Polling the VOD playlist and appending each new segment records the whole stream - **The landing** (`common/controller/landMedia.ts`, shared): ffprobe — unreadable or no audio → refused; a file inside `channels/` or the store → refused (import); KEEP THE LONGER over a stored container (2 s slack, a tie and an unmeasurable store keep what is there; `replace` overrides); finalize into `.<id>.land-<pid>.part` on the - store's disk — copy (rename when `move` on the same disk) or `-c copy` remux (mp4 +faststart; mkv when mp4 + store's disk — attach-media's hashed copy (`copyFileHashed`; a rename when `move` on the same disk) or `-c copy` remux (mp4 +faststart; mkv when mp4 cannot hold the codecs) through the heavy slot; verify bytes (copy) or ffprobe + length (remux); `persistSourceVideo` (`source-media.<ext>`, `keepReason: "pin"`, `origin.requestedBy` import-media|record-live); `move` removes the original only after the verify; `audio.<fmt>` (channel's format, mp3 default) by @@ -92,6 +92,15 @@ Polling the VOD playlist and appending each new segment records the whole stream shorter (a shorter one of another name is removed with `removeMediaFile`); the channel's `archive` gains `<extractor> <id>` (not for a record by hand); `media-import.json` gains the entry (source path, original name, bytes, moved, url, finalized, container, kept, existingSeconds, audio, note; 50 kept). +- **import-media composes the existing steps** — the record by `refreshVideoMetadata` (the refresh-metadata op's + pass, into a new `data/<id>/`), the container by attach-media's copy and provenance (`copyFileHashed`, pointer + origin `{kind: "local-archive", archive: <dir>, entry: <file>, sha256, attachedAt}` with `requestedBy: + "import-media"`) through `persistSourceVideo`, the marker by `setDoNotClean` (keep-videos' writer); a directory or + archive is attach-media itself. Its own: one FILE path, the `.part`/`.ts` remux, `move` after the verify, keep the + longer, audio, the pending keep marker. A container attach-media attached is protected by the same guard as an + imported one (`requestedBy: "attach-media"` counts as landed). +- v7h8pxg (the 2026-10-22 recording) was attached by hand before this lane (attach-media + refresh-metadata + + keep-videos): nothing to import. - **The hand-off**: the log says what takes the audio — the transcription lane's rules (a leaf matching the channel), or that it does not — and names every hold (workers paused, lane held, channel paused). Nothing lifts a pause. `transcribe: true` queues `whisper-video` (the video page's Transcribe), held like any.