commit f127a94fc1f29734a6966bdb0e0dcf77c7fd2fa2
parent a3d823bb1f7e53cd7983800a19ffcd7807765364
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 18 Nov 2026 01:25:31 -0500
x-trending: capture-posts captures a library one directory down
An X trending library's posts are under trending/, so capturePosts roots a library's archive check, its captures (trending/posts-media/<id>/) and its availability sidecar there, by the marker alone, and takes X's fetcher for a channel with no account URL. The editor's capture action checks the library's own archive.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
3 files changed, 65 insertions(+), 6 deletions(-)
diff --git a/common/controller/capturePosts.test.ts b/common/controller/capturePosts.test.ts
@@ -484,3 +484,32 @@ test("context (X): read by default with each post's archived parent and quoted i
assert.equal(calls.length, 0);
answer = { outcomes: [] };
});
+
+// Lane x-trending-2: an X trending library is captured one directory down.
+test("an X trending library: its posts, captures and availability are under trending/, never in the channel's own", async () => {
+ const root = path.join(channelsDir, "demo-library");
+ await mkdir(path.join(root, "trending"), { recursive: true });
+ await writeFile(
+ path.join(root, "config.json"),
+ JSON.stringify({ handling: "transcribe", sourceKind: "social", platform: "twitter", postFetcher: "test-capture-x", name: "Library", xTrending: {} }),
+ );
+ await writeFile(path.join(root, "trending", "posts-archive"), "twitter 7001\ntwitter 7002\n");
+ // An id in the channel's OWN archive is not the library's: refused as stray.
+ await writeFile(path.join(root, "posts-archive"), "twitter 7999\n");
+ calls = [];
+ answer = { outcomes: [] };
+ const stray = await run("demo-library", ["7999"]);
+ assert.equal(stray.ok, false);
+ assert.match(stray.error ?? "", /1 id\(s\) not in demo-library's posts archive: 7999/);
+ assert.equal(calls.length, 0);
+
+ answer = { outcomes: [{ id: "7001", state: "deleted", availability: "deleted", files: 0 }] };
+ const res = await run("demo-library", ["7001", "7002"], { articles: false, context: false });
+ assert.equal(res.ok, true, res.error);
+ assert.equal(calls.length, 1);
+ assert.equal(calls[0].outDir, path.join(root, "trending", "posts-media"));
+ // A library has no account: its slug stands for the handle, as a search channel's does.
+ assert.equal(calls[0].handle, "demo-library");
+ assert.equal((await readPostAvailability(path.join(root, "trending")))["7001"]?.availability, "deleted");
+ assert.deepEqual(await readPostAvailability(root), {});
+});
diff --git a/common/controller/capturePosts.ts b/common/controller/capturePosts.ts
@@ -14,6 +14,13 @@
// archived text and links go to the fetcher with it, so a post that is an X
// Article's link is known as one before its page is opened.
//
+// AN X TRENDING LIBRARY (lane x-trending-2) is captured through this same
+// job, one directory down: its posts are under `channels/<lib>/trending/`
+// (lib/xTrending/store.ts xTrendingPostsRoot says why), so its captures land
+// in `trending/posts-media/<id>/` and its availability in
+// `trending/posts-availability.json`. The marker alone decides — no caller
+// can capture a library into the channel's own `posts-media/`.
+//
// X also keeps the posts' AUTHORS' AVATARS, read off the page the shot loads,
// in `posts-media/_avatars/` (social/xAvatars.ts has the store): on by
// default (`avatars: false` turns it off), and `avatarsOnly` loads one page
@@ -27,6 +34,8 @@
import path from "node:path";
import { isXSearchChannel } from "../lib/xSearch/config";
+import { isXTrendingChannel } from "../lib/xTrending/config";
+import { xTrendingPostsRoot } from "../lib/xTrending/store";
import { readChannelConfig } from "./channels";
import type { Paths } from "../lib/paths";
import type { Post, PostAvailability } from "../lib/posts";
@@ -44,6 +53,7 @@ import {
writePostAvailability,
} from "../lib/posts-server";
import {
+ getSocialFetcher,
handleFromAccountUrl,
resolveSocialFetcher,
type PostCaptureOutcome,
@@ -193,13 +203,16 @@ export function strayIdsRefusal(slug: string, stray: string[]): string {
return `${stray.length} id(s) not in ${slug}'s posts archive: ${stray.join(", ")}`;
}
+// The fetcher that captures an X trending library's posts.
+export const X_LIBRARY_FETCHER = "x-gallery-dl";
+
export async function capturePosts(
opts: CapturePostsOptions,
): Promise<CapturePostsResult> {
const { paths, slug, settings, onLog } = opts;
const log = (line: string) => onLog?.(line);
const fail = (error: string): CapturePostsResult => ({ ok: false, outcomes: [], error });
- const channelRoot = path.join(paths.channelsDir, slug);
+ const channelDir = path.join(paths.channelsDir, slug);
const ids = [...new Set(opts.ids)];
if (nothingToCapture(opts)) return fail(NOTHING_TO_CAPTURE);
@@ -214,11 +227,19 @@ export async function capturePosts(
if (isWaybackPagesChannel(config)) {
if (opts.avatarsOnly) return fail(avatarsOnlyProblem(undefined, "a Wayback pages channel")!);
if (opts.contextOnly) return fail(contextOnlyProblem(undefined, "a Wayback pages channel", opts)!);
- return captureChannelPageRecords(opts, channelRoot, ids);
+ return captureChannelPageRecords(opts, channelDir, ids);
}
+ // WHERE THIS CHANNEL'S POSTS, CAPTURES AND AVAILABILITY LIVE: the channel's
+ // own directory — or, for an X trending library, its trending/ directory.
+ const library = isXTrendingChannel(config);
+ const channelRoot = library ? xTrendingPostsRoot(channelDir) : channelDir;
+
const accountUrl = config.url ?? "";
- const fetcher = resolveSocialFetcher(config.postFetcher, accountUrl);
+ // A library has no account URL to tell its fetcher by: X's own.
+ const fetcher = library
+ ? (getSocialFetcher(config.postFetcher) ?? getSocialFetcher(X_LIBRARY_FETCHER))
+ : resolveSocialFetcher(config.postFetcher, accountUrl);
const problem = capturePostsProblem(fetcher);
if (problem || !fetcher?.captureByIds) return fail(problem ?? "This channel has no post fetcher.");
const avatarsOnly = opts.avatarsOnly === true;
@@ -239,7 +260,7 @@ export async function capturePosts(
// The thread shot: X only, the run's word or the channel's default.
const thread = fetcher.platform === "twitter" ? (opts.thread ?? config.postCaptureThread ?? false) : false;
if (opts.thread && fetcher.platform !== "twitter") log(`Thread shots are X's only; ${fetcher.label} takes none.`);
- const handle = config.socialHandle ?? handleFromAccountUrl(accountUrl) ?? (isXSearchChannel(config) ? slug : "");
+ const handle = config.socialHandle ?? handleFromAccountUrl(accountUrl) ?? (isXSearchChannel(config) || library ? slug : "");
if (!handle) return fail(`Could not determine an account handle for ${slug}`);
const stray = strayCaptureIds(ids, await readSeenPostIds(channelRoot));
diff --git a/editor/app/channels/[slug]/socialActions.ts b/editor/app/channels/[slug]/socialActions.ts
@@ -23,6 +23,7 @@ import { isSocialChannel } from "yt-dlp-transcript-common/lib/channelConfig";
import { isWaybackPagesChannel } from "yt-dlp-transcript-common/lib/waybackPages/config";
import { isXSearchChannel } from "yt-dlp-transcript-common/lib/xSearch/config";
import { isXTrendingChannel, X_TRENDING_NOT_FETCHED } from "yt-dlp-transcript-common/lib/xTrending/config";
+import { readXTrendingPostIds } from "yt-dlp-transcript-common/lib/xTrending/store";
import { X_SEARCH_OLDER_REFUSAL } from "yt-dlp-transcript-common/controller/fetchXSearch";
import { WAYBACK_PAGES_NOT_FETCHED } from "yt-dlp-transcript-common/controller/fetchPosts";
import { WAYBACK_PAGES_QUEUE } from "yt-dlp-transcript-common/controller/importPage";
@@ -55,6 +56,7 @@ import {
capturePosts,
contextOnlyProblem,
capturePostsProblem,
+ X_LIBRARY_FETCHER,
NOTHING_TO_CAPTURE,
nothingToCapture,
parseThreadRedact,
@@ -375,9 +377,14 @@ export async function capturePostsAction(
const pages = isWaybackPagesChannel(config);
if (pages && avatarsOnly) return { ok: false, error: avatarsOnlyProblem(undefined, "a Wayback pages channel")! };
if (pages && contextOnly) return { ok: false, error: contextOnlyProblem(undefined, "a Wayback pages channel", { avatarsOnly })! };
+ // An X trending library is captured one directory down, by X's fetcher
+ // (controller/capturePosts.ts says why).
+ const library = isXTrendingChannel(config);
if (!pages) {
await registerBuiltinSocialFetchers();
- const fetcher = resolveSocialFetcher(config.postFetcher, config.url);
+ const fetcher = library
+ ? (getSocialFetcher(config.postFetcher) ?? getSocialFetcher(X_LIBRARY_FETCHER))
+ : resolveSocialFetcher(config.postFetcher, config.url);
const problem = capturePostsProblem(fetcher);
if (problem) return { ok: false, error: problem };
const nope = avatarsOnly ? avatarsOnlyProblem(fetcher?.platform, fetcher?.label ?? "") : null;
@@ -387,7 +394,9 @@ export async function capturePostsAction(
}
const stray = strayCaptureIds(
wanted,
- await readSeenPostIds(path.join(paths.channelsDir, slug)),
+ library
+ ? await readXTrendingPostIds(path.join(paths.channelsDir, slug))
+ : await readSeenPostIds(path.join(paths.channelsDir, slug)),
);
if (stray) return { ok: false, error: strayIdsRefusal(slug, stray) };