Archilyzer · Source

archilyzer

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

commit d211915b3cd7758fa6f4764747fcaee827a6757c
parent 2d8dfd4aa78cdc0f17bd8c7f57026c34a919a2c4
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu, 12 Nov 2026 02:08:01 -0500

umtool: posts attach (and posts repeats) look for a capture in the project's channels tree, then the archive's behind it -- read only, the files copied into the project; --dry-run says which tree each file comes from

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

Diffstat:
Meditor/CHANGELOG.md | 1+
Mumtool/docs/cli.md | 2+-
Mumtool/docs/knobs.md | 2+-
Mumtool/lib/cli/groups.mjs | 2+-
Mumtool/lib/report/postComboCli.mjs | 55++++++++++++++++++++++++++++++++++++++++++++-----------
Mumtool/lib/report/postComboCli.test.mjs | 52+++++++++++++++++++++++++++++++++++++++++++++++++++-
Mumtool/report-to-video/post-combo-prints.mjs | 29++++++++++++++++++-----------
7 files changed, 117 insertions(+), 26 deletions(-)

diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## [Unreleased] +- **umtool: `posts attach` finds captures in the archive too.** On a project with its own channels tree (a `.shadow-channels`), `umtool posts attach` and `posts repeats` looked for a post's capture only there, so media captured into the real archive's `channels/<slug>/posts-media/<id>/` was not seen. They now look in the project's tree first and then the archive's, as the other readers do. The archive is only read: the files are copied into the project as before. `--dry-run` prints which tree each file would come from. - **umtool: an entry's chapter name is set from a terminal.** An entry's `chapter` names it in the chapter list (the YouTube text, `umtool export --format chapters`) in place of its on-screen title, and it could only be written by editing the manifest by hand. `umtool set <p> <entry> chapter='The weigh-in'` writes it for any entry (a clip, a post item, a still), `chapter=` clears it, and `--take <t>` writes it on that take alone. One line, at most 100 characters. - **umtool: a windowed take preview no longer fails on an effect that names a clip outside the window.** `umtool take <p> --id <t> --preview --at S --dur S` on a cut with `render.chrome.fx.glitch.clips` or `fx.thenNow.pairs` was refused with "names k06, which is not a clip of the cut". The window's manifest now keeps only the named clips inside it (a glitch's only when a clip stands right before it in the window, a then/now pair only with both ends), as it already did for markers and claim checks; an effect left naming no clip is off in that window. The same for `fx.kineticQuote.clips` and `fx.redact.clips`. - **umtool: `quote-check` works on a project whose `out/` is on the media drive.** The check asked the editor to write its word files under `<project>/out/quote-check/`; when `out/` is a link onto a media drive, that is inside the corpus and the editor refuses to write there, so every clip failed. The work files now go to `<project>/.quote-check/`, and if the editor refuses that too (the project itself is inside the corpus) to `<reports>/.umtool/quote-check/<project>/`, then `~/.cache/umtool/quote-check/<project>/`. The rows are still the project's `quote-check.json`; the editor's refusal is unchanged. diff --git a/umtool/docs/cli.md b/umtool/docs/cli.md @@ -147,7 +147,7 @@ Inbox cannot disagree about what is wrong with one. | `posts context <project> [--dry-run] [--json]` | every **post item's context from its capture** (`postContext.mjs`): the post it quotes and the post it answers, as its page showed them (`capture.json`'s `context`, read by the editor's `capture-posts` -- `"contextOnly": true` reads it alone), filled where the archive row lacks them -- `quoted` where the entry has none (or a named one with no words, the same post), `parents` where it has none (a thread shot stays on the entry; the card draws the parents). An x.com/twitter.com **status link** in its words (or its row's links) is a quote: the post it names, from any channel's archive, fills `quoted` (`via: "link"`) when it has none; the row's `threadId` is snapshotted as the item's `conversation` (the thread walk reads it). What the archive gave is never replaced. ONE write for every entry (`setPostItemsContext`: one undo point, refused whole in the build's words); a re-run with nothing new writes nothing. A post whose capture read no context is listed with the call that reads it (`pnpm ops capture-posts --json '{"slug":…,"ids":[…],"contextOnly":true}' --wait`). The card's blur of other authors is unchanged ([report-video.md](report-video.md#post-items-a-post-as-an-entry-of-the-cut)) | | `posts picture-reply <project> [on=on\|off] [image=<s>] [min=<s>] [max=<s>] [maxSound=<s>] [--in-take <take>] [--json]` | the cut's **PICTURE-ONLY RULE** ([knobs.md](knobs.md#picture-only-posts-a-reply-that-is-its-picture)): `render.posts.pictureReply` (`updatePostPictureReplyRender`, one undo point) -- `on` the rule at all; a beat's length: an image `image` s (2), a GIF's or a silent video's own length clamped to `min`–`max` (1.5–4 s), a video with its sound its whole length up to `maxSound` (8 s). `k=` the default again; none: the rule as it stands. `--in-take` writes it into a take's patch. Refused in the build's words (**exit 1**) | | `posts repeats <project> [--match id\|file\|audio] [--json]` | the **combo counter**'s repeats ([report-video.md](report-video.md#the-combo-counter)): every attachment the cut's post items play more than once -- the same X media id (the capture's url), else the same file (the capture's sha256 when its bytes agree, else hashed; cached by path, size and mtime), else (`--match audio`) the same sound (fpcalc, else a coarse ffmpeg hash) -- its posts in the cut's ORDER with their dates, the tier that matched and the badge each draws (`×2` from the second use, `(×n)` counted but not drawn); a post whose CAPTURE holds the same file but whose entry carries no attachment is listed too, `NOT ATTACHED`, with the `posts attach` that brings it in. Reads only | -| `posts attach <project> [<item> … \| --all] [--dry-run] [--json]` | a post item with **no attachment whose capture holds one** (captured after it went in -- `posts repeats` marks them `NOT ATTACHED`): the capture's media (its own channel's `posts-media/<postId>/`, else any channel the cut's posts come from) copied into the project's `posts-media/<slug>/<postId>/` and measured, set as the entry's `media` as `posts reel` would have made it -- nothing else of the entry changes (its paraphrases, narration, knobs kept); an item that has an attachment is never touched. ONE write (one undo point: `timeline <p> undo`), refused whole in the build's words | +| `posts attach <project> [<item> … \| --all] [--dry-run] [--json]` | a post item with **no attachment whose capture holds one** (captured after it went in -- `posts repeats` marks them `NOT ATTACHED`): the capture's media (its own channel's `posts-media/<postId>/`, else any channel the cut's posts come from -- looked for in the project's channels tree first, a `.shadow-channels` or `provenance.channelsDir`, then the archive's `CHANNELS_DIR` behind it, read only; `--dry-run` says which tree each file comes from) copied into the project's `posts-media/<slug>/<postId>/` and measured, set as the entry's `media` as `posts reel` would have made it -- nothing else of the entry changes (its paraphrases, narration, knobs kept); an item that has an attachment is never touched. ONE write (one undo point: `timeline <p> undo`), refused whole in the build's words | | `posts combo <project> [on=on\|off] [label=L] [position=top-right\|top-left\|bottom-right\|bottom-left\|center] [color=#rrggbb] [scale=0.4-2.5] [sfx=off\|hit\|coin] [minCount=2-20] [match=id\|file\|audio] [--json]` · `posts combo <project> <item> off\|on\|auto\|label=…\|position=…\|color=…\|scale=…\|sfx=… [--json]` | the **combo badge's knobs** ([knobs.md](knobs.md#the-combo-counter)): the cut's (`render.posts.combo`, `updatePostComboRender`; no knobs prints them; `k=` the default again) or one post item's (`combo`, `updatePostCombo`): `off` draws no badge on it -- it still counts -- `on`/`auto` the cut's again. Refused in the build's words (**exit 1**) | | `candidates <project> [ls] [--all] [--json]` · `candidates <project> import <sweep.md> [--dry-run] [--json]` · `candidates <project> add <json\|@file> [--json]` | the **candidates inbox** (`<project>/candidates.json`): proposals only — `import` reads a sweep's bullets (`- [verdict] [title @ time](link) (date) "quote" — why`, under their headings; a Top N section marks what it restates; a bullet with no verdict or link is skipped and said), `add` an agent's (`{channel?, video, t, quote?, why?, verdict?, score?, section?}` or `{link, …}`); the same moment again changes nothing it holds. Insert and Not this are the Cut tab's Candidates panel's ([knobs.md](knobs.md#the-candidates-inbox-proposed-clips-picked-by-a-press)) | | `ingredient <channel>/<video> [--window <from>-<to>] [--used-in] [--json]` | **one recording's life cycle**, the twin of `/ingredients/<channel>/<video>` ([knobs.md](knobs.md#an-ingredients-life-cycle-the-rail)): nine stages — found, downloaded, transcribed, clock, windows, used in, checked, rendered, published — each **✓**, a count, **!** or **—**, and its line, then every project clip that cuts from it (the draft and each saved version, from the usage index `<REPORTS_ROOT>/.umtool/usage-index.json`). A Rumble recording answers to its folder slug or its embed id; both are printed. `--window`: one clip window, the stages after it narrowed to the clips it plays. `--used-in`: the clips alone. `--json`: the page's object. Read-only over the corpus. **Exit 0 · 1 failed · 2 usage** | diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -1751,7 +1751,7 @@ in the build's words (`validatePostCombos`). `k=` (empty) takes the default (the | | In umtool | From a terminal | Route | |---|---|---|---| | the repeats: each attachment played more than once, its posts in the cut's order with their dates, the tier that matched (`X media id`, `same file`, `same sound`) and the badge each draws; a post whose capture holds the same file but whose entry carries none, marked | the post bench's **combo** block (this item's group) | `umtool posts repeats <p> [--match id\|file\|audio] [--json]` | `GET /api/report/post-combo?project` | -| attach what a capture holds to a post item that carries none (captured after it went in): its media copied in and set, nothing else of the entry changed; then it plays and counts | — | `umtool posts attach <p> <item>… \| --all [--dry-run]` | — | +| attach what a capture holds to a post item that carries none (captured after it went in): its media copied in and set, nothing else of the entry changed; then it plays and counts. The capture is looked for in the project's channels tree (a `.shadow-channels`, `provenance.channelsDir`), then the archive's behind it -- read only, the files are copied into the project; `--dry-run` says which tree each file comes from | — | `umtool posts attach <p> <item>… \| --all [--dry-run]` | — | | the badge on the item's clock | Play the cut, the post bench (the player) | the build: `segments/<id>.mp4` (the plain one `<id>.plain.mp4`, the record `<id>.combo.json`) | — | ## Media scenes (one attachment, several messages) diff --git a/umtool/lib/cli/groups.mjs b/umtool/lib/cli/groups.mjs @@ -1057,7 +1057,7 @@ export const GROUPS = [ ["`posts repeats <project> [--match id\\|file\\|audio] [--json]`", "the **combo counter**'s repeats ([report-video.md](report-video.md#the-combo-counter)): every attachment the cut's post items play more than once -- the same X media id (the capture's url), else the same file (the capture's sha256 when its bytes agree, else hashed; cached by path, size and mtime), else (`--match audio`) the same sound (fpcalc, else a coarse ffmpeg hash) -- its posts in the cut's ORDER with their dates, the tier that matched and the badge each draws (`×2` from the second use, `(×n)` counted but not drawn); a post whose CAPTURE holds the same file but whose entry carries no attachment is listed too, `NOT ATTACHED`, with the `posts attach` that brings it in. Reads only"], ["`posts attach <project> [<item> … \\| --all] [--dry-run] [--json]`", - "a post item with **no attachment whose capture holds one** (captured after it went in -- `posts repeats` marks them `NOT ATTACHED`): the capture's media (its own channel's `posts-media/<postId>/`, else any channel the cut's posts come from) copied into the project's `posts-media/<slug>/<postId>/` and measured, set as the entry's `media` as `posts reel` would have made it -- nothing else of the entry changes (its paraphrases, narration, knobs kept); an item that has an attachment is never touched. ONE write (one undo point: `timeline <p> undo`), refused whole in the build's words"], + "a post item with **no attachment whose capture holds one** (captured after it went in -- `posts repeats` marks them `NOT ATTACHED`): the capture's media (its own channel's `posts-media/<postId>/`, else any channel the cut's posts come from -- looked for in the project's channels tree first, a `.shadow-channels` or `provenance.channelsDir`, then the archive's `CHANNELS_DIR` behind it, read only; `--dry-run` says which tree each file comes from) copied into the project's `posts-media/<slug>/<postId>/` and measured, set as the entry's `media` as `posts reel` would have made it -- nothing else of the entry changes (its paraphrases, narration, knobs kept); an item that has an attachment is never touched. ONE write (one undo point: `timeline <p> undo`), refused whole in the build's words"], ["`posts combo <project> [on=on\\|off] [label=L] [position=top-right\\|top-left\\|bottom-right\\|bottom-left\\|center] [color=#rrggbb] [scale=0.4-2.5] [sfx=off\\|hit\\|coin] [minCount=2-20] [match=id\\|file\\|audio] [--json]` · `posts combo <project> <item> off\\|on\\|auto\\|label=…\\|position=…\\|color=…\\|scale=…\\|sfx=… [--json]`", "the **combo badge's knobs** ([knobs.md](knobs.md#the-combo-counter)): the cut's (`render.posts.combo`, `updatePostComboRender`; no knobs prints them; `k=` the default again) or one post item's (`combo`, `updatePostCombo`): `off` draws no badge on it -- it still counts -- `on`/`auto` the cut's again. Refused in the build's words (**exit 1**)"], ], diff --git a/umtool/lib/report/postComboCli.mjs b/umtool/lib/report/postComboCli.mjs @@ -16,7 +16,7 @@ // Plain ESM: the CLI runs it under bare node. import { COMBO_DEFAULTS, COMBO_ITEM_KEYS, comboKnobs, repeatGroups } from "umtool-report-to-video/post-combo"; import { captureOnlyMedia, projectCombos } from "umtool-report-to-video/post-combo-prints"; -import { channelsDirFor, readManifest } from "../projects/report.mjs"; +import { channelsDirFor, channelsLayersFor, hasShadowChannels, readManifest } from "../projects/report.mjs"; import { withEditNotes } from "./edit-guard.mjs"; import { copyFile, mkdir, realpath, stat } from "node:fs/promises"; import path from "node:path"; @@ -45,6 +45,8 @@ export const REPEATS_USAGE = [ " umtool posts attach <project> [<item> … | --all] [--dry-run] [--json]", " a post item with no attachment whose capture holds one (captured after it went in): its media copied in and", " set, as posts reel would have made it -- nothing else of the entry changes. One write (one undo point).", + " The capture is looked for in the project's channels tree, then the archive's (read only: the files are", + " copied into the project); --dry-run prints the tree each file would come from.", ].join("\n"); const OFF = new Set(["off", "no", "false", "0"]); @@ -95,7 +97,7 @@ export async function repeatsView(project, { match = null, cacheDir = undefined, const opts = { channelsDir: corpus, ...(match ? { match } : {}), ...(cacheDir !== undefined ? { cacheDir } : {}) }; const cut = await projectCombos(project.dir, manifest, opts); // The posts whose capture has a file their entry does not carry: in the cut's order, as if they played it. - const captured = await captureOnlyMedia(manifest, { channelsDir: corpus }); + const captured = await captureOnlyMedia(manifest, { channelsDirs: await captureTrees(project, manifest, channelsDir) }); const tl = (manifest.timeline ?? []).map((e) => (captured[e?.id] ? { ...e, media: captured[e.id].map((m) => ({ src: `@capture/${m.slug}/${m.name}`, kind: "capture" })) } : e)); const prints = (id, i) => (captured[id] ? { mediaId: captured[id][i]?.mediaId ?? null, sha256: captured[id][i]?.sha256 ?? null } : cut.prints[`${id}:${i}`]); const all = repeatGroups(tl, prints, { match: cut.match }); @@ -160,20 +162,40 @@ async function copyIn(projectDir, from, rel) { } /** + * THE CHANNELS TREES A CAPTURE IS LOOKED FOR IN (12 Nov: a project with a `.shadow-channels` tree saw only that, and + * the captures in the real archive's `channels/<slug>/posts-media/<id>/` were invisible): the project's own tree + * first, then the archive behind it -- as the other readers resolve them (projects/report.mjs channelsLayersFor; + * `provenance.channelsFallback: false` or CHANNELS_FALLBACK=0 keeps it to the project's). READ ONLY toward both: + * attach copies into the project. + * @returns {Promise<string[]>} + */ +async function captureTrees(project, manifest, channelsDir = null, channelsDirs = null) { + if (Array.isArray(channelsDirs) && channelsDirs.length) return channelsDirs; + if (channelsDir) return [channelsDir]; + return channelsLayersFor(project.dir, manifest, { shadowExists: await hasShadowChannels(project.dir) }); +} + +/** A tree in words: the first is the project's own, any after it the archive's. */ +const treeKindOf = (trees, tree) => (trees.indexOf(tree) <= 0 ? "project" : "archive"); + +/** * ATTACH WHAT THE CAPTURES HOLD (`umtool posts attach`): each post item with no * attachment whose capture has one (captured after it went in) gets its media * as `posts reel` would have made it -- the files copied into the project's * posts-media/, measured -- and nothing else of the entry changes (its * paraphrases, narration, knobs kept). One write. `ids` narrows it. + * A capture is looked for in the project's channels tree, then the archive's (captureTrees); each planned item + * says which it came from (`tree`, `treeKind`: project | archive), and `--dry-run` prints it per file. * * @param {{ id: string, dir: string }} project - * @param {{ ids?: string[] | null, dryRun?: boolean, channelsDir?: string | null }} [o] + * @param {{ ids?: string[] | null, dryRun?: boolean, channelsDir?: string | null, channelsDirs?: string[] | null }} [o] + * `channelsDirs`: the trees to look in, in order (default: the project's, then the archive's) */ -export async function attachFromCaptures(project, { ids = null, dryRun = false, channelsDir = null } = {}) { +export async function attachFromCaptures(project, { ids = null, dryRun = false, channelsDir = null, channelsDirs = null } = {}) { const manifest = await readManifest(project.dir); if (!manifest) throw new ComboError(`${project.id} has no manifest`); - const corpus = channelsDir ?? channelsDirFor(project.dir, manifest); - const captured = await captureOnlyMedia(manifest, { channelsDir: corpus }); + const trees = await captureTrees(project, manifest, channelsDir, channelsDirs); + const captured = await captureOnlyMedia(manifest, { channelsDirs: trees }); const tl = Array.isArray(manifest.timeline) ? manifest.timeline : []; const want = ids ? ids.map((r) => tl.find((e) => e?.type === "post" && (e.id === r || String(e.post ?? "").split("/")[1] === r))?.id ?? r) : null; if (want) for (const id of want) if (!tl.some((e) => e?.id === id && e.type === "post")) throw new ComboError(`no post item ${id} in ${project.id}`); @@ -184,7 +206,7 @@ export async function attachFromCaptures(project, { ids = null, dryRun = false, const postId = String(tl.find((e) => e?.id === id)?.post ?? "").split("/")[1]; const media = []; for (const m of list) { - const from = path.join(corpus, m.slug, "posts-media", postId, m.name); + const from = path.join(m.tree, m.slug, "posts-media", postId, m.name); if (!(await stat(from).catch(() => null))) continue; const rel = `posts-media/${m.slug}/${postId}/${m.name}`; const probe = await probeMediaFile(from); @@ -202,7 +224,7 @@ export async function attachFromCaptures(project, { ids = null, dryRun = false, } if (!media.length) continue; patches[id] = media.map((x) => x.item); - plan.push({ id, media: media.map((x) => ({ src: x.item.src, kind: x.item.kind, from: x.from })) }); + plan.push({ id, tree: list[0].tree, treeKind: treeKindOf(trees, list[0].tree), media: media.map((x) => ({ src: x.item.src, kind: x.item.kind, from: x.from })) }); } if (dryRun || !plan.length) return { dryRun, attached: plan, result: null, editNotes: null }; for (const p of plan) for (const m of p.media) await copyIn(project.dir, m.from, m.src); @@ -210,6 +232,19 @@ export async function attachFromCaptures(project, { ids = null, dryRun = false, return { dryRun, attached: plan.filter((p) => result.ids.includes(p.id)), result, editNotes }; } +/** What `posts attach` prints: each item's media, and the channels tree each file is read from (a dry run: per file). */ +export function attachLines(r, projectId) { + const out = [`${r.dryRun ? "would attach" : "attached"} the capture's media to ${r.attached.length} post item(s) in ${projectId}`]; + for (const a of r.attached) { + const whose = a.treeKind === "archive" ? "the archive's" : "the project's"; + out.push(` ${a.id} ${a.media.map((m) => `${m.kind} ${m.src}`).join(", ")}`); + if (r.dryRun) for (const m of a.media) out.push(` from ${whose} channels tree: ${m.from}`); + else out.push(` from ${whose} channels tree (${a.tree})`); + } + if (r.result?.snapshot?.rel && !r.result.snapshot.skipped) out.push(` undo point: ${r.result.snapshot.rel} (umtool timeline ${projectId} undo)`); + return out; +} + /** The repeats view as lines. */ export function repeatsLines(v) { const out = []; @@ -262,9 +297,7 @@ async function comboRun(verb, words, flags, { root, json, out, err }) { const r = await attachFromCaptures(project, { ids: items.length ? items : null, dryRun: flags.has("--dry-run") }); if (json) out(JSON.stringify({ ok: true, ...r, result: r.result ? { ids: r.result.ids, snapshot: r.result.snapshot, token: r.result.token } : null }, null, 2)); else { - out(`${r.dryRun ? "would attach" : "attached"} the capture's media to ${r.attached.length} post item(s) in ${project.id}`); - for (const a of r.attached) out(` ${a.id} ${a.media.map((m) => `${m.kind} ${m.src}`).join(", ")}`); - if (r.result?.snapshot?.rel && !r.result.snapshot.skipped) out(` undo point: ${r.result.snapshot.rel} (umtool timeline ${project.id} undo)`); + for (const l of attachLines(r, project.id)) out(l); } return 0; } diff --git a/umtool/lib/report/postComboCli.test.mjs b/umtool/lib/report/postComboCli.test.mjs @@ -8,7 +8,7 @@ import { tmpdir } from "node:os"; import path from "node:path"; import { after, test } from "node:test"; import { postsCommand } from "./postsCli.mjs"; -import { repeatsView } from "./postComboCli.mjs"; +import { attachFromCaptures, attachLines, repeatsView } from "./postComboCli.mjs"; const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-post-combo-")); after(() => rm(ROOT, { recursive: true, force: true })); @@ -125,3 +125,53 @@ test("posts attach: the capture's media onto the item that carries none, nothing assert.deepEqual(v.groups[0].members.map((m) => `${m.id}:${m.attached ? m.badge : "-"}`), ["p-1:1", "p-2:2", "p-3:3", "p-5:4"]); assert.equal((await run(["attach", "att"])).code, 2, "names the items, or --all"); }); + +test("posts attach reads every channels tree: the project's first, then the archive's -- read only; a dry run says which tree each file came from", async () => { + const { execFileSync } = await import("node:child_process"); + const { readdir, stat } = await import("node:fs/promises"); + const p = await project("trees"); + // The project's own tree (a .shadow-channels) holds no capture of post 3; the ARCHIVE's does. + const shadow = path.join(p.dir, ".shadow-channels"); + await mkdir(path.join(shadow, "obv-x"), { recursive: true }); + const archive = path.join(ROOT, "archive-channels"); + const capDir = path.join(archive, "obv-x", "posts-media", "3"); + await mkdir(capDir, { recursive: true }); + const gif = path.join(capDir, "3_1.mp4"); + execFileSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "testsrc=size=160x90:rate=10:duration=1", "-c:v", "libx264", "-pix_fmt", "yuv420p", "-an", gif]); + await writeFile(path.join(capDir, "capture.json"), JSON.stringify({ media: [{ name: "3_1.mp4", url: "https://video.twimg.com/tweet_video/C.mp4" }] })); + const listing = async () => (await readdir(archive, { recursive: true })).sort().join("\n"); + const archiveBefore = await listing(); + const mtimeBefore = (await stat(gif)).mtimeMs; + + // Only the project's tree, as before: nothing to attach. + assert.deepEqual((await attachFromCaptures(p, { channelsDirs: [shadow], dryRun: true })).attached, []); + // Both: found in the archive, and said so. + const dry = await attachFromCaptures(p, { channelsDirs: [shadow, archive], dryRun: true }); + assert.deepEqual(dry.attached.map((a) => [a.id, a.treeKind, a.tree]), [["p-3", "archive", archive]]); + assert.equal(dry.attached[0].media[0].from, gif); + const lines = attachLines(dry, "trees"); + assert.match(lines[0], /would attach the capture's media to 1 post item\(s\) in trees/); + assert.ok(lines.includes(` from the archive's channels tree: ${gif}`), lines.join("\n")); + assert.equal((await manifest(p)).timeline.find((e) => e.id === "p-3").media, undefined, "a dry run writes nothing"); + + // The project's own capture wins when both hold one. + const own = path.join(shadow, "obv-x", "posts-media", "3"); + await mkdir(own, { recursive: true }); + execFileSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "testsrc=size=160x90:rate=10:duration=1", "-c:v", "libx264", "-pix_fmt", "yuv420p", "-an", path.join(own, "3_9.mp4")]); + await writeFile(path.join(own, "capture.json"), JSON.stringify({ media: [{ name: "3_9.mp4", url: "https://video.twimg.com/tweet_video/D.mp4" }] })); + const both = await attachFromCaptures(p, { channelsDirs: [shadow, archive], dryRun: true }); + assert.deepEqual(both.attached.map((a) => [a.treeKind, a.media[0].src]), [["project", "posts-media/obv-x/3/3_9.mp4"]]); + assert.ok(attachLines(both, "trees").some((l) => l.startsWith(" from the project's channels tree: "))); + await rm(own, { recursive: true, force: true }); + + // The write: copied INTO the project; the archive is exactly as it was. + const done = await attachFromCaptures(p, { channelsDirs: [shadow, archive] }); + assert.deepEqual(done.attached.map((a) => a.id), ["p-3"]); + assert.ok(attachLines(done, "trees").includes(` from the archive's channels tree (${archive})`)); + const e = (await manifest(p)).timeline.find((x) => x.id === "p-3"); + assert.equal(e.media[0].src, "posts-media/obv-x/3/3_1.mp4"); + const copied = await stat(path.join(p.dir, "posts-media", "obv-x", "3", "3_1.mp4")); + assert.ok(copied.isFile() && !copied.isSymbolicLink()); + assert.equal(await listing(), archiveBefore, "nothing added to the archive"); + assert.equal((await stat(gif)).mtimeMs, mtimeBefore, "its file untouched"); +}); diff --git a/umtool/report-to-video/post-combo-prints.mjs b/umtool/report-to-video/post-combo-prints.mjs @@ -198,13 +198,18 @@ export async function projectCombos(dir, manifest, o = {}) { * the cut whose capture holds one (captured after the item went in -- its * media was never copied). Its capture is looked for under its own channel, * then every channel the cut's posts come from (a reply captured under the - * replies channel). `{ <itemId>: [{ name, slug, mediaId, sha256, url }] }`. + * replies channel). `{ <itemId>: [{ name, slug, tree, mediaId, sha256, url }] }`. + * + * `channelsDirs`: the channels trees to look in, in order (the project's own first, then the archive behind it: + * sources.mjs channelsLayersFor) -- the first tree that holds the post's capture wins, and each file says which + * (`tree`). Read only: nothing is written into any of them. * * @param {Record<string, any>} manifest - * @param {{ channelsDir?: string|null }} [o] + * @param {{ channelsDir?: string|null, channelsDirs?: string[]|null }} [o] */ -export async function captureOnlyMedia(manifest, { channelsDir = null } = {}) { - if (!channelsDir) return {}; +export async function captureOnlyMedia(manifest, { channelsDir = null, channelsDirs = null } = {}) { + const trees = (Array.isArray(channelsDirs) && channelsDirs.length ? channelsDirs : [channelsDir]).filter((d) => typeof d === "string" && d); + if (!trees.length) return {}; const tl = Array.isArray(manifest?.timeline) ? manifest.timeline : []; const channels = [...new Set(tl.filter((e) => e?.type === "post" && typeof e.post === "string").map((e) => e.post.split("/")[0]).filter(Boolean))]; const out = {}; @@ -212,13 +217,15 @@ export async function captureOnlyMedia(manifest, { channelsDir = null } = {}) { if (e?.type !== "post" || typeof e.post !== "string" || (Array.isArray(e.media) && e.media.length)) continue; const [own, postId] = e.post.split("/"); if (!own || !postId) continue; - for (const slug of [own, ...channels.filter((c) => c !== own)]) { - const dirOf = path.join(channelsDir, slug, "posts-media", postId); - const cap = await readFile(path.join(dirOf, "capture.json"), "utf8").then((t) => JSON.parse(t), () => null); - const media = Array.isArray(cap?.media) ? cap.media.filter((m) => typeof m?.name === "string") : []; - if (!media.length) continue; - out[e.id] = media.map((m) => ({ name: m.name, slug, mediaId: xMediaIdOf(m.url), sha256: typeof m.sha256 === "string" ? m.sha256 : null, url: typeof m.url === "string" ? m.url : null })); - break; + found: for (const tree of trees) { + for (const slug of [own, ...channels.filter((c) => c !== own)]) { + const dirOf = path.join(tree, slug, "posts-media", postId); + const cap = await readFile(path.join(dirOf, "capture.json"), "utf8").then((t) => JSON.parse(t), () => null); + const media = Array.isArray(cap?.media) ? cap.media.filter((m) => typeof m?.name === "string") : []; + if (!media.length) continue; + out[e.id] = media.map((m) => ({ name: m.name, slug, tree, mediaId: xMediaIdOf(m.url), sha256: typeof m.sha256 === "string" ? m.sha256 : null, url: typeof m.url === "string" ? m.url : null })); + break found; + } } } return out;