commit efdc37ed31ce45e085c8cbaf332601413c638f2d
parent 1bce636f1087d67fee7cb0de59024aeb9f039cac
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 2 Nov 2026 22:56:23 -0500
common: the X fetcher keeps quoted posts -- gallery-dl's `quoted` on, each quote the quoting post's `quoted`, never the account's own post
gallery-dl's flat record of a quoting tweet names no quote, and without its
twitter `quoted` option the quoted tweet is dropped: the archive's `quoted`
was always empty for a timeline read. Every read (timeline, search, a status
read) now asks for it; gallery-dl then yields the quoted tweet as a record of
its own right after the quoting one, `quote_id` naming the QUOTER (the reverse
link). xQuoteOf (xNormalize.ts) reads that link; GalleryDlStream turns it into
the quoting post's `quoted` (whichever arrives first) and never archives the
quote as the account's post: not counted, not the search walk's resume point
(an older quote's id would have skipped posts), not a step toward the stop.
normalizeXTweets (the Playwright fallback's batch) links the same way.
gallery-dl's own "previously seen" dedupe goes off (`unique=false`): with
quotes on, the account's OWN older post met first as the quote of a newer one
would otherwise be skipped when the walk reaches it, and never archived; the
stream dedupes by id itself. --post-range counts the quotes too, so a capped
run is told by the tweets gallery-dl yielded (`yielded`), not the posts kept.
On the timeline a quote costs no request (it is inside the page X returned);
the media capture's gallery-dl run is unchanged (it downloads the post's own
media only). The run's log says how many new posts carry their quote.
Tested against a timeline read in gallery-dl 1.32.9's output.jsonl shape as
its extractor writes it (__fixtures__/gallery-dl-timeline-quotes.jsonl, built
to that shape by hand; the suite never contacts X): a quote of Kirsche, a
quote with pictures and their file records, a self-quote, a reply.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
4 files changed, 203 insertions(+), 8 deletions(-)
diff --git a/common/social/__fixtures__/gallery-dl-timeline-quotes.jsonl b/common/social/__fixtures__/gallery-dl-timeline-quotes.jsonl
@@ -0,0 +1,10 @@
+[2, {"tweet_id": 1983300000000000001, "retweet_id": 0, "quote_id": 0, "reply_id": 0, "conversation_id": 1983300000000000001, "source_id": 0, "date": "2026-10-29 14:05:00", "author": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "user": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "lang": "en", "source": "Twitter Web App", "sensitive": false, "sensitive_flags": null, "favorite_count": 7, "quote_count": 1, "reply_count": 2, "retweet_count": 3, "bookmark_count": 0, "view_count": 900, "content": "you called me a Leftist, so here is what you said", "count": 0, "category": "twitter", "subcategory": "timeline"}]
+[2, {"tweet_id": 1983200000000000007, "retweet_id": 0, "quote_id": 1983300000000000001, "reply_id": 0, "conversation_id": 1983200000000000007, "source_id": 0, "date": "2026-10-29 12:00:00", "author": {"id": 2222222222, "name": "Kirsche", "nick": "Kirsche", "location": "", "date": "2019-03-01 10:00:00", "verified": true, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/2222222222/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "user": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "lang": "en", "source": "Twitter Web App", "sensitive": false, "sensitive_flags": null, "favorite_count": 7, "quote_count": 1, "reply_count": 2, "retweet_count": 3, "bookmark_count": 0, "view_count": 900, "content": "Mr. Obvious is a leftist in disguise.", "count": 0, "category": "twitter", "subcategory": "timeline", "quote_by": "ObviousRises"}]
+[2, {"tweet_id": 1983300000000000002, "retweet_id": 0, "quote_id": 0, "reply_id": 0, "conversation_id": 1983300000000000002, "source_id": 0, "date": "2026-10-28 09:00:00", "author": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "user": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "lang": "en", "source": "Twitter Web App", "sensitive": false, "sensitive_flags": null, "favorite_count": 7, "quote_count": 1, "reply_count": 2, "retweet_count": 3, "bookmark_count": 0, "view_count": 900, "content": "the receipt", "count": 1, "category": "twitter", "subcategory": "timeline"}]
+[3, "https://pbs.twimg.com/media/T2pic.jpg?name=orig", {"tweet_id": 1983300000000000002, "retweet_id": 0, "quote_id": 0, "reply_id": 0, "conversation_id": 1983300000000000002, "source_id": 0, "date": "2026-10-28 09:00:00", "author": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "user": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "lang": "en", "source": "Twitter Web App", "sensitive": false, "sensitive_flags": null, "favorite_count": 7, "quote_count": 1, "reply_count": 2, "retweet_count": 3, "bookmark_count": 0, "view_count": 900, "content": "the receipt", "count": 1, "category": "twitter", "subcategory": "timeline", "num": 1, "filename": "T2pic", "extension": "jpg"}]
+[2, {"tweet_id": 1983100000000000003, "retweet_id": 0, "quote_id": 1983300000000000002, "reply_id": 0, "conversation_id": 1983100000000000003, "source_id": 0, "date": "2026-10-27 18:30:00", "author": {"id": 3333333333, "name": "quoted_person", "nick": "Quoted Person", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/3333333333/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "user": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "lang": "en", "source": "Twitter Web App", "sensitive": false, "sensitive_flags": null, "favorite_count": 7, "quote_count": 1, "reply_count": 2, "retweet_count": 3, "bookmark_count": 0, "view_count": 900, "content": "The receipt itself.", "count": 1, "category": "twitter", "subcategory": "timeline", "quote_by": "ObviousRises"}]
+[3, "https://pbs.twimg.com/media/Q2pic.jpg?name=orig", {"tweet_id": 1983100000000000003, "retweet_id": 0, "quote_id": 1983300000000000002, "reply_id": 0, "conversation_id": 1983100000000000003, "source_id": 0, "date": "2026-10-27 18:30:00", "author": {"id": 3333333333, "name": "quoted_person", "nick": "Quoted Person", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/3333333333/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "user": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "lang": "en", "source": "Twitter Web App", "sensitive": false, "sensitive_flags": null, "favorite_count": 7, "quote_count": 1, "reply_count": 2, "retweet_count": 3, "bookmark_count": 0, "view_count": 900, "content": "The receipt itself.", "count": 1, "category": "twitter", "subcategory": "timeline", "quote_by": "ObviousRises", "num": 1, "filename": "Q2pic", "extension": "jpg"}]
+[2, {"tweet_id": 1983300000000000003, "retweet_id": 0, "quote_id": 0, "reply_id": 0, "conversation_id": 1983300000000000003, "source_id": 0, "date": "2026-10-27 08:00:00", "author": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "user": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "lang": "en", "source": "Twitter Web App", "sensitive": false, "sensitive_flags": null, "favorite_count": 7, "quote_count": 1, "reply_count": 2, "retweet_count": 3, "bookmark_count": 0, "view_count": 900, "content": "as I said last week", "count": 0, "category": "twitter", "subcategory": "timeline"}]
+[2, {"tweet_id": 1981000000000000005, "retweet_id": 0, "quote_id": 1983300000000000003, "reply_id": 0, "conversation_id": 1981000000000000005, "source_id": 0, "date": "2026-10-20 08:00:00", "author": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "user": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "lang": "en", "source": "Twitter Web App", "sensitive": false, "sensitive_flags": null, "favorite_count": 7, "quote_count": 1, "reply_count": 2, "retweet_count": 3, "bookmark_count": 0, "view_count": 900, "content": "an older post of my own", "count": 0, "category": "twitter", "subcategory": "timeline", "quote_by": "ObviousRises"}]
+[2, {"tweet_id": 1983300000000000004, "retweet_id": 0, "quote_id": 0, "reply_id": 1983200000000000001, "conversation_id": 1983200000000000001, "source_id": 0, "date": "2026-10-26 08:00:00", "author": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "user": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "lang": "en", "source": "Twitter Web App", "sensitive": false, "sensitive_flags": null, "favorite_count": 7, "quote_count": 1, "reply_count": 2, "retweet_count": 3, "bookmark_count": 0, "view_count": 900, "content": "@Kirsche no", "count": 0, "category": "twitter", "subcategory": "timeline", "reply_to": "Kirsche"}]
+[2, {"tweet_id": 1981000000000000005, "retweet_id": 0, "quote_id": 0, "reply_id": 0, "conversation_id": 1981000000000000005, "source_id": 0, "date": "2026-10-20 08:00:00", "author": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "user": {"id": 1111111111, "name": "ObviousRises", "nick": "Mr. Obvious", "location": "", "date": "2019-03-01 10:00:00", "verified": false, "protected": false, "profile_banner": "", "profile_image": "https://pbs.twimg.com/profile_images/1111111111/x.jpg", "favourites_count": 10, "followers_count": 100, "friends_count": 50, "listed_count": 1, "media_count": 3, "statuses_count": 1000, "description": ""}, "lang": "en", "source": "Twitter Web App", "sensitive": false, "sensitive_flags": null, "favorite_count": 7, "quote_count": 1, "reply_count": 2, "retweet_count": 3, "bookmark_count": 0, "view_count": 900, "content": "an older post of my own", "count": 0, "category": "twitter", "subcategory": "timeline"}]
diff --git a/common/social/xGalleryDlFetcher.test.ts b/common/social/xGalleryDlFetcher.test.ts
@@ -416,3 +416,101 @@ test("the capture's gap before each contact is the reads' 4–10 s, drawn fresh"
assert.equal(xRequestPauseMs(() => 1), 10_000);
assert.equal(xRequestPauseMs(() => 0.5), 7_000);
});
+
+// ---------------------------------------------------------------------------
+// Quoted posts (gallery-dl's twitter `quoted` option)
+// ---------------------------------------------------------------------------
+//
+// __fixtures__/gallery-dl-timeline-quotes.jsonl is a timeline read in
+// gallery-dl 1.32.9's --dump-json/output.jsonl shape, as its twitter
+// extractor writes it (extractor/twitter.py _transform_tweet: bare 64-bit
+// ids, `quote_id` set on the QUOTED tweet's record naming the one quoting it,
+// `quote_by`, a [3, url, kwdict] record per file): built to that shape by
+// hand -- the suite never contacts X. Lines: a post quoting Kirsche and the
+// quote; a post with a picture quoting one with a picture (each with its file
+// record); a post quoting the account's OWN older post, that post met first
+// as the quote; a reply; and the older post again as a post of the timeline
+// (gallery-dl's dedupe is off, so the walk still archives it).
+
+import { readFileSync } from "node:fs";
+import { fileURLToPath } from "node:url";
+import { normalizeXTweets } from "./xNormalize";
+import { parseGalleryDlOutput } from "./xGalleryDlFetcher";
+
+const QUOTES_JSONL = readFileSync(
+ fileURLToPath(new URL("./__fixtures__/gallery-dl-timeline-quotes.jsonl", import.meta.url)),
+ "utf8",
+);
+const T1 = "1983300000000000001"; // quotes Kirsche's Q1
+const Q1 = "1983200000000000007";
+const T2 = "1983300000000000002"; // quotes quoted_person's Q2
+const Q2 = "1983100000000000003";
+const T3 = "1983300000000000003"; // quotes his own T5
+const T5 = "1981000000000000005";
+const T4 = "1983300000000000004"; // a reply
+
+test("every read keeps quoted posts and turns gallery-dl's own dedupe off; the media capture does neither", () => {
+ const timeline = buildGalleryDlArgs({ accountUrl: ACCOUNT, stream: true });
+ const search = buildGalleryDlSearchArgs({ handle: "example_user", position: { since: "2020-12-11", until: "2021-03-11" } });
+ for (const argv of [timeline, search]) {
+ assert.ok(argv.includes("extractor.twitter.quoted=true"));
+ assert.ok(argv.includes("extractor.twitter.unique=false"));
+ }
+ const capture = buildGalleryDlCaptureArgs({ id: "123", dir: "/corpus/x/posts-media/123" });
+ assert.equal(capture.some((a) => a.startsWith("extractor.twitter.quoted=")), false, "a capture downloads the post's own media only");
+});
+
+test("stream: a quoted tweet's record becomes the quoting post's `quoted`, never a post of the account's", () => {
+ const s = newStream({ channelSlug: "ObviousRises-x" });
+ for (const line of QUOTES_JSONL.split("\n")) s.pushStdout(line);
+ const posts = s.finish();
+ assert.deepEqual(posts.map((p) => p.id), [T1, T2, T3, T4, T5]);
+ const by = new Map(posts.map((p) => [p.id, p]));
+ assert.deepEqual(by.get(T1)?.quoted, { platform: "twitter", id: Q1, author: "Kirsche", url: `https://x.com/Kirsche/status/${Q1}` });
+ assert.deepEqual(by.get(T2)?.quoted, { platform: "twitter", id: Q2, author: "quoted_person", url: `https://x.com/quoted_person/status/${Q2}` });
+ // His own older post: the quote of the newer one, and archived as his post when the walk reaches it.
+ assert.equal(by.get(T3)?.quoted?.id, T5);
+ assert.equal(by.get(T3)?.quoted?.author, "ObviousRises");
+ assert.equal(by.get(T5)?.text, "an older post of my own");
+ assert.equal(by.get(T5)?.quoted, undefined);
+ assert.equal(by.get(T4)?.quoted, undefined);
+ assert.equal(by.get(T4)?.replyTo?.author, "Kirsche");
+ assert.equal(by.get(T2)?.mediaCount, 1);
+ // Counted: 5 posts, 3 given their quote; gallery-dl yielded 8 tweets
+ // toward --post-range (each quote, and T5 twice — as a quote and as itself).
+ assert.equal(s.distinct, 5);
+ assert.equal(s.newPosts, 5);
+ assert.equal(s.quotesLinked, 3);
+ assert.equal(s.yielded, 8);
+});
+
+test("stream: a quote is no resume point and no stop — and is linked whichever of the two arrives first", () => {
+ const lines = QUOTES_JSONL.split("\n").filter(Boolean);
+ // T1 then Q1: Q1's id is OLDER than T1's, and must not become the walk's
+ // oldest post (a search window resumes below it).
+ const a = newStream();
+ a.pushStdout(lines[0]);
+ a.pushStdout(lines[1]);
+ assert.equal(a.oldestId, T1);
+ // The quote first.
+ const b = newStream();
+ b.pushStdout(lines[1]);
+ b.pushStdout(lines[0]);
+ const [post] = b.finish();
+ assert.equal(post.quoted?.id, Q1);
+ // A quoting post already archived: not re-written, the quote not a post.
+ const c = newStream({ seenIds: new Set([T1]) });
+ c.pushStdout(lines[0]);
+ c.pushStdout(lines[1]);
+ assert.deepEqual(c.finish(), []);
+ assert.equal(c.known, 1);
+ assert.equal(c.quotesLinked, 0);
+});
+
+test("normalizeXTweets (the Playwright fallback's batch) links quotes the same way", () => {
+ const posts = normalizeXTweets(parseGalleryDlOutput(QUOTES_JSONL), "ObviousRises-x");
+ assert.deepEqual(posts.map((p) => p.id).sort(), [T5, T4, T3, T2, T1].sort());
+ assert.equal(posts.find((p) => p.id === T1)?.quoted?.id, Q1);
+ assert.equal(posts.find((p) => p.id === T3)?.quoted?.id, T5);
+ assert.ok(!posts.some((p) => p.id === Q1 || p.id === Q2));
+});
diff --git a/common/social/xGalleryDlFetcher.ts b/common/social/xGalleryDlFetcher.ts
@@ -33,9 +33,9 @@ import { getPaths } from "../lib/paths";
import { noteXServiceOutcome } from "../lib/serviceCookies-server";
import { looksLikeXAuthFailure, xBlockKind, xBlockLine } from "./xGalleryDlSignals";
import { cookieArgs } from "../lib/cookiePolicy";
-import type { Post } from "../lib/posts";
+import type { Post, PostRef } from "../lib/posts";
import type { OlderBackfillPosition } from "../lib/posts-server";
-import { normalizeXTweet, xCreatedAt, type XTweetRaw } from "./xNormalize";
+import { normalizeXTweet, xCreatedAt, xIdOf, xQuoteOf, type XTweetRaw } from "./xNormalize";
import {
OLDER_MAX_EMPTY_WINDOWS,
OLDER_WINDOW_MONTHS,
@@ -191,6 +191,21 @@ function galleryDlCommonArgs(opts: GalleryDlLoginAndCap): string[] {
"extractor.twitter.retweets=true",
"-o",
"extractor.twitter.replies=true",
+ // QUOTED POSTS: gallery-dl yields the post a tweet quotes as a record of
+ // its own, right after the tweet (its `quote_id` naming the quoting one) --
+ // the only way a read learns what a post quotes, since its flat record of
+ // the quoting tweet names none. The stream (GalleryDlStream) turns it into
+ // the quoting post's `quoted` and never archives it as the account's own.
+ // On the timeline it costs no request: the quote is already inside the
+ // page X returned.
+ "-o",
+ "extractor.twitter.quoted=true",
+ // …and gallery-dl's own "previously seen" dedupe off: with quotes on, the
+ // account's OWN older post, met first as the quote of a newer one, would
+ // otherwise be skipped when the walk reaches it as a post of the timeline,
+ // and never archived. The stream dedupes by id itself.
+ "-o",
+ "extractor.twitter.unique=false",
// Media is counted, not archived.
"-o",
"extractor.twitter.videos=false",
@@ -201,7 +216,9 @@ function galleryDlCommonArgs(opts: GalleryDlLoginAndCap): string[] {
];
// A cap on POSTS. `--range` counts files, and with downloads off most tweets
// yield none, so it never stopped the walk: a 400-post fetch of a new
- // channel read 3,803. `--post-range` counts the tweets themselves.
+ // channel read 3,803. `--post-range` counts the tweets themselves -- the
+ // quoted ones and any repeat among them (GalleryDlStream.yielded is what
+ // a capped run is told by).
if (opts.limit && opts.limit > 0) {
args.push("--post-range", `1-${Math.floor(opts.limit)}`);
}
@@ -583,6 +600,12 @@ export type GalleryDlCheckpoint = { posts: Post[]; cursor: string };
export class GalleryDlStream {
// Every distinct post seen this run, new or not.
distinct = 0;
+ // Every record gallery-dl counted toward --post-range: each tweet it
+ // yielded, quoted ones and repeats included (a tweet's directory record and
+ // its per-URL records are one). What tells a capped run from a finished one.
+ yielded = 0;
+ // Posts read this run that a quoted record gave their `quoted`.
+ quotesLinked = 0;
newPosts = 0;
known = 0;
older = 0;
@@ -600,6 +623,11 @@ export class GalleryDlStream {
private savedCursor?: string;
private pending: Post[] = [];
private ids = new Set<string>();
+ private yieldedKeys = new Set<string>();
+ // The new posts of this run by id, for a quote met after its quoting post.
+ private newById = new Map<string, Post>();
+ // Quoting id → the quoted ref, for a quoting post met after its quote.
+ private quotedBy = new Map<string, PostRef>();
private knownRun = 0;
private tail: string[] = [];
private unparsed: string[] = [];
@@ -697,6 +725,26 @@ export class GalleryDlStream {
}
private addRecord(rec: XTweetRaw): void {
+ const link = xQuoteOf(rec);
+ const rawId = xIdOf(rec);
+ // One tweet's directory record and its per-URL records are one post to
+ // --post-range; the same tweet quoted by two posts is two.
+ const tweetKey = rawId ? `${rawId}:${link?.quoterId ?? ""}` : "";
+ if (tweetKey && !this.yieldedKeys.has(tweetKey)) {
+ this.yieldedKeys.add(tweetKey);
+ this.yielded++;
+ }
+ // A QUOTED tweet's own record: the quote of the post quoting it, never a
+ // post of this account's. Not counted, not a resume point, not a stop.
+ if (link) {
+ if (!this.quotedBy.has(link.quoterId)) this.quotedBy.set(link.quoterId, link.quoted);
+ const quoter = this.newById.get(link.quoterId);
+ if (quoter && !quoter.quoted) {
+ quoter.quoted = link.quoted;
+ this.quotesLinked++;
+ }
+ return;
+ }
const post = normalizeXTweet(rec, this.opts.channelSlug);
// gallery-dl can emit a tweet more than once (a directory record, then one
// per media URL); count it once.
@@ -729,6 +777,12 @@ export class GalleryDlStream {
}
this.knownRun = 0;
this.newPosts++;
+ const quoted = this.quotedBy.get(post.id);
+ if (quoted && !post.quoted) {
+ post.quoted = quoted;
+ this.quotesLinked++;
+ }
+ this.newById.set(post.id, post);
this.pending.push(post);
}
}
@@ -1122,7 +1176,8 @@ async function walkSearchWindows(
}
onLog?.(
`${windowStart.since} – ${windowStart.until}: read ${stream.distinct} post(s), ${stream.newPosts} new` +
- (stream.known ? `, ${stream.known} already archived` : ""),
+ (stream.known ? `, ${stream.known} already archived` : "") +
+ (stream.quotesLinked ? `, ${stream.quotesLinked} with the post it quotes` : ""),
);
if (stream.challengeLine) {
@@ -1148,7 +1203,7 @@ async function walkSearchWindows(
error: `gallery-dl exited ${res.exitCode ?? res.signal ?? "abnormally"}: ${tail || "(no output)"}`,
});
}
- if (remainingLimit !== undefined && stream.distinct >= remainingLimit) {
+ if (remainingLimit !== undefined && stream.yielded >= remainingLimit) {
return stopped(here);
}
@@ -1393,7 +1448,8 @@ export const xGalleryDlFetcher: SocialFetcher = {
onLog?.(
`gallery-dl read ${stream.distinct} post(s): ${stream.newPosts} new` +
(stream.known ? `, ${stream.known} already archived` : "") +
- (stream.older ? `, ${stream.older} older than the watermark` : ""),
+ (stream.older ? `, ${stream.older} older than the watermark` : "") +
+ (stream.quotesLinked ? `, ${stream.quotesLinked} new with the post it quotes` : ""),
);
// Where the next run should pick up when this one did not finish: the last
@@ -1460,7 +1516,7 @@ export const xGalleryDlFetcher: SocialFetcher = {
// A clean exit walked everything it was given: gallery-dl waits out rate
// limits rather than skipping pages. Only a --post-range cap leaves history
// behind — resume from the last page it finished.
- const capped = Boolean(limit && stream.distinct >= limit);
+ const capped = Boolean(limit && stream.yielded >= limit);
return capped
? { posts, complete: false, cursor: resumeAt }
: { posts, complete: true };
diff --git a/common/social/xNormalize.ts b/common/social/xNormalize.ts
@@ -144,6 +144,25 @@ function refFrom(
return ref;
}
+// THE QUOTED TWEET AS gallery-dl YIELDS IT. With its twitter `quoted` option
+// on (every read here turns it on, xGalleryDlFetcher.ts), gallery-dl yields a
+// quoted tweet as a record of its own, right after the tweet quoting it, its
+// `quote_id` naming the QUOTING tweet (and `quote_by` that tweet's author) --
+// the reverse link: X's timeline carries the quote inside the quoting tweet,
+// and gallery-dl's flat record of the quoting tweet names no quote at all.
+// Such a record is not one of the account's posts: it says what ANOTHER post
+// quotes. This is the link it carries -- the quoting tweet's id, and the ref
+// the quoting post's `quoted` should hold -- or null for any other record.
+export function xQuoteOf(rec: XTweetRaw): { quoterId: string; quoted: PostRef } | null {
+ const quoterId = refId(rec.quote_id);
+ if (!quoterId) return null;
+ const id = xIdOf(rec);
+ if (!id || id === quoterId) return null;
+ const handle = xAuthor(rec).handle;
+ const quoted = refFrom(id, handle || undefined);
+ return quoted ? { quoterId, quoted } : null;
+}
+
// Normalize one tweet record into a Post. Returns null when the record has no
// resolvable id or timestamp — a shape we don't understand is skipped rather
// than stored as a corrupt entry.
@@ -244,15 +263,27 @@ export function normalizeXTweet(
}
// Normalize a batch, dropping unparseable records and deduping by id (a
-// timeline page can repeat a tweet across a cursor boundary).
+// timeline page can repeat a tweet across a cursor boundary). A quoted tweet's
+// own record (xQuoteOf) is not a post of the batch: it becomes the `quoted` of
+// the post quoting it, where that post names none.
export function normalizeXTweets(
records: ReadonlyArray<XTweetRaw>,
channelSlug: string,
): Post[] {
const byId = new Map<string, Post>();
+ const quotes = new Map<string, PostRef>();
for (const rec of records) {
+ const link = xQuoteOf(rec);
+ if (link) {
+ if (!quotes.has(link.quoterId)) quotes.set(link.quoterId, link.quoted);
+ continue;
+ }
const post = normalizeXTweet(rec, channelSlug);
if (post && !byId.has(post.id)) byId.set(post.id, post);
}
+ for (const [quoterId, quoted] of quotes) {
+ const post = byId.get(quoterId);
+ if (post && !post.quoted) post.quoted = quoted;
+ }
return [...byId.values()];
}