// What a gallery-dl stderr line says about X's login (xGalleryDlSignals.ts), // on the messages gallery-dl 1.32's twitter extractor and job runner really // print (extractor/twitter.py, extractor/common.py, exception.py, job.py): // a challenge and a login failure raise X's cookie alert; a rate limit is // pacing; one account's or one media file's refusal is not the login. // // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test social/xGalleryDlSignals.test.ts import test from "node:test"; import assert from "node:assert/strict"; import { classifyXStderrLine, looksLikeXAuthFailure, xBlockKind, xBlockLine, } from "./xGalleryDlSignals"; const CASES: Array<[string, ReturnType]> = [ // Challenges — any level, one is enough. ["[twitter][warning] Cloudflare challenge", "challenge"], ["[twitter][error] ChallengeError: Cloudflare challenge (403 Forbidden) for 'https://x.com/i/api/graphql/abc/UserTweets'", "challenge"], ["[twitter][warning] Cloudflare CAPTCHA", "challenge"], ["[twitter][warning] DDoS-Guard challenge", "challenge"], // The login gone or refused. ["[twitter][error] AuthRequired: authenticated cookies needed to access this timeline", "auth"], ["[twitter][error] AuthenticationError: Invalid login credentials", "auth"], ["[twitter][error] 'Could not authenticate you'", "auth"], ["[twitter][error] HttpError: '401 Unauthorized' for 'https://x.com/i/api/graphql/abc/UserTweets'", "auth"], ["[twitter][error] HTTP redirect to login page (401 Unauthorized)", "auth"], ["[twitter][error] 403 Forbidden (Forbidden)", "auth"], ["[twitter][error] AuthorizationError: Account temporarily locked", "auth"], // Pacing, never cookies. ["[twitter][info] Waiting for 14 minutes until 03:12:44 (rate limit)", "rate-limit"], ["[twitter][info] Waiting for 60 seconds until 03:12:44 (429 Too Many Requests)", "rate-limit"], ["[twitter][error] Rate limit exceeded", "rate-limit"], ["[twitter][error] HttpError: '429 Too Many Requests' for 'https://x.com/i/api/graphql/403abc/UserTweets'", "rate-limit"], // One account, one post, one media file: the login is fine. ["[twitter][error] AuthorizationError: someone's Tweets are protected", "account"], ["[twitter][error] AuthorizationError: someone blocked your account", "account"], ["[twitter][error] AuthRequired: Protected Tweet", "account"], ["[twitter][error] AuthRequired: NSFW Tweet", "account"], ["[twitter][error] NotFoundError: Requested user could not be found", "account"], ["[download][warning] HttpError: '403 Forbidden' for 'https://video.twimg.com/ext_tw_video/1/pu/vid/720x1280/a.mp4'", "account"], // Nothing. ["[twitter][debug] Cursor: DAABCgABG", null], ["[twitter][debug] HttpError: '401 Unauthorized' (debug lines never count)", null], ["[twitter][info] Requesting guest token", null], ["", null], // A login phrase on an untagged line counts only for a failed run's tail. ["401 Unauthorized", null], ]; test("each real gallery-dl line is classified: challenge, auth, rate limit, one account, or nothing", () => { for (const [line, want] of CASES) { assert.equal(classifyXStderrLine(line), want, line); } }); test("xBlockLine stops a run (and raises X's alert) only on a challenge or a login failure", () => { assert.equal(xBlockLine("[twitter][warning] Cloudflare challenge"), true); assert.equal(xBlockLine("[twitter][error] AuthRequired: authenticated cookies needed to access this timeline"), true); assert.equal(xBlockLine("[twitter][info] Waiting for 14 minutes until 03:12:44 (rate limit)"), false); assert.equal(xBlockLine("[twitter][error] HttpError: '429 Too Many Requests' for 'https://x.com/i/api/x'"), false); assert.equal(xBlockLine("[twitter][error] AuthorizationError: someone's Tweets are protected"), false); assert.equal(xBlockLine("[download][warning] HttpError: '403 Forbidden' for 'https://pbs.twimg.com/media/a.jpg'"), false); assert.equal(xBlockKind("[twitter][warning] Cloudflare challenge"), "challenge"); assert.equal(xBlockKind("[twitter][error] 'Could not authenticate you'"), "auth-failure"); }); test("a failed run's tail: a login failure (even untagged) is Needs-cookies; a rate limit or a protected account is not", () => { assert.equal(looksLikeXAuthFailure("some progress\n401 Unauthorized"), true); assert.equal(looksLikeXAuthFailure("[twitter][error] AuthRequired: authenticated cookies needed to access this timeline"), true); assert.equal(looksLikeXAuthFailure("[twitter][error] Rate limit exceeded"), false); assert.equal(looksLikeXAuthFailure("[twitter][error] AuthorizationError: someone's Tweets are protected"), false); assert.equal(looksLikeXAuthFailure("[twitter][error] AbortExtraction: 404 Not Found (GraphQL query id rotated)"), false); });