@chilfish/gallery-dl-instagram 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,40 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sdk = require("./sdk-nzhAxf1O.cjs");
3
+ exports.ConfigManager = require_sdk.ConfigManager;
4
+ exports.DownloadJob = require_sdk.DownloadJob;
5
+ exports.Extractor = require_sdk.Extractor;
6
+ exports.InstagramAvatarExtractor = require_sdk.InstagramAvatarExtractor;
7
+ exports.InstagramExtractor = require_sdk.InstagramExtractor;
8
+ exports.InstagramHighlightsExtractor = require_sdk.InstagramHighlightsExtractor;
9
+ exports.InstagramInfoExtractor = require_sdk.InstagramInfoExtractor;
10
+ exports.InstagramPostExtractor = require_sdk.InstagramPostExtractor;
11
+ exports.InstagramPostsExtractor = require_sdk.InstagramPostsExtractor;
12
+ exports.InstagramReelsExtractor = require_sdk.InstagramReelsExtractor;
13
+ exports.InstagramRestAPI = require_sdk.InstagramRestAPI;
14
+ exports.InstagramSDK = require_sdk.InstagramSDK;
15
+ exports.InstagramSavedExtractor = require_sdk.InstagramSavedExtractor;
16
+ exports.InstagramStoriesExtractor = require_sdk.InstagramStoriesExtractor;
17
+ exports.InstagramTagExtractor = require_sdk.InstagramTagExtractor;
18
+ exports.InstagramTaggedExtractor = require_sdk.InstagramTaggedExtractor;
19
+ exports.InstagramUserExtractor = require_sdk.InstagramUserExtractor;
20
+ exports.Job = require_sdk.Job;
21
+ exports.PrintJob = require_sdk.PrintJob;
22
+ exports.directory = require_sdk.directory;
23
+ exports.ensureHttpScheme = require_sdk.ensureHttpScheme;
24
+ exports.extr = require_sdk.extr;
25
+ exports.extract = require_sdk.extract;
26
+ exports.extractAudio = require_sdk.extractAudio;
27
+ exports.extractTaggedUsers = require_sdk.extractTaggedUsers;
28
+ exports.findTags = require_sdk.findTags;
29
+ exports.idFromShortcode = require_sdk.idFromShortcode;
30
+ exports.nameExtFromURL = require_sdk.nameExtFromURL;
31
+ exports.noopLogger = require_sdk.noopLogger;
32
+ exports.parseInt = require_sdk.parseInt;
33
+ exports.parsePostGraphql = require_sdk.parsePostGraphql;
34
+ exports.parsePostRest = require_sdk.parsePostRest;
35
+ exports.parseUnicodeEscapes = require_sdk.parseUnicodeEscapes;
36
+ exports.queue = require_sdk.queue;
37
+ exports.shortcodeFromId = require_sdk.shortcodeFromId;
38
+ exports.unescape = require_sdk.unescape;
39
+ exports.unquote = require_sdk.unquote;
40
+ exports.url = require_sdk.url;
@@ -1,201 +1,73 @@
1
- //#region types.d.ts
2
- /**
3
- * Shared type definitions for the gallery-dl TypeScript port.
4
- *
5
- * Message types form a discriminated union — the `type` tag determines
6
- * which handler a Job should invoke.
7
- */
8
- /** HTTP abstraction */
9
- interface RequestConfig {
10
- headers?: Record<string, string>;
11
- params?: Record<string, string | number | null | undefined>;
12
- method?: string;
13
- data?: unknown;
14
- timeout?: number;
15
- signal?: AbortSignal;
16
- /** WithCredentials / CORS cookie passthrough for browsers */
17
- withCredentials?: boolean;
18
- /** For binary downloads — 'arraybuffer' returns raw bytes */
19
- responseType?: 'arraybuffer' | 'text' | 'json';
20
- }
21
- interface HttpResponse<T = unknown> {
1
+ import { _ as Metadata, a as ExtractorOptions, b as Storage, c as ConfigManager, d as DirectoryMsg, f as ExtractorClass, g as MessageIter, h as Message, i as Extractor, l as Config, m as HttpResponse, n as InstagramSDK, o as Logger, p as HttpClient, r as SDKOptions, s as noopLogger, t as ExtractOptions, u as ConfigValue, v as QueueMsg, x as UrlMsg, y as RequestConfig } from "./sdk-CK9x5wFL.cjs";
2
+
3
+ //#region src/core/job.d.ts
4
+ declare abstract class Job {
5
+ readonly extractor: Extractor;
22
6
  status: number;
23
- data: T;
24
- headers: Record<string, string>;
25
- /** Final URL after redirects */
26
- url: string;
27
- request?: RequestConfig;
28
- }
29
- interface HttpClient {
30
- request: <T = unknown>(config: {
31
- url: string;
32
- method?: string;
33
- headers?: Record<string, string>;
34
- params?: Record<string, string | number | null | undefined>;
35
- data?: unknown;
36
- signal?: AbortSignal;
37
- timeout?: number;
38
- responseType?: 'arraybuffer' | 'text' | 'json';
39
- }) => Promise<HttpResponse<T>>;
40
- }
41
- /** Storage abstraction */
42
- interface Storage {
43
- exists: (path: string) => Promise<boolean>;
44
- write: (path: string, data: Uint8Array | string) => Promise<void>;
45
- mkdir: (path: string) => Promise<void>;
46
- }
47
- type ConfigValue = string | number | boolean | null | ConfigValue[] | {
48
- [key: string]: ConfigValue;
49
- };
50
- interface Config {
51
- [key: string]: ConfigValue;
52
- }
53
- /** Metadata & messages */
54
- /**
55
- * Flat string-keyed metadata dictionary.
56
- * In gallery-dl every kwdict is a plain `{string → value}` map.
57
- */
58
- type Metadata = Record<string, unknown>;
59
- interface DirectoryMsg {
60
- readonly type: 'directory';
61
- readonly metadata: Metadata;
62
- }
63
- interface UrlMsg {
64
- readonly type: 'url';
65
- readonly url: string;
66
- readonly metadata: Metadata;
67
- }
68
- interface QueueMsg {
69
- readonly type: 'queue';
70
- readonly url: string;
71
- readonly metadata: Metadata & {
72
- readonly _extractor?: ExtractorClass;
73
- };
74
- }
75
- type Message = DirectoryMsg | UrlMsg | QueueMsg;
76
- /**
77
- * Async generator that yields Message values.
78
- */
79
- type MessageIter = AsyncGenerator<Message, void, unknown>;
80
- /** Extractor class reference (for Queue dispatch) */
81
- /**
82
- * Minimal shape that every Extractor class must expose so the Dispatch
83
- * logic can re-instantiate from a URL.
84
- */
85
- interface ExtractorClass {
86
- pattern: RegExp;
87
- subcategory: string;
88
- }
89
- //#endregion
90
- //#region config.d.ts
91
- declare class ConfigManager {
92
- private readonly data;
93
- constructor(data?: Config);
94
- /**
95
- * Read a value at a dot-path like ``'extractor.instagram.videos'``.
96
- * Returns ``undefined`` when the path doesn't exist.
97
- */
98
- get(path: string, defaultValue?: ConfigValue): ConfigValue | undefined;
7
+ constructor(extractor: Extractor);
99
8
  /**
100
- * Interpolate a config key through a hierarchy of paths.
9
+ * Main entry point. Calls ``extractor[Symbol.asyncIterator]()`` and
10
+ * dispatches every yielded message.
101
11
  */
102
- interpolate(cfgPath: readonly string[], key: string, defaultVal?: ConfigValue): ConfigValue | undefined;
12
+ run(): Promise<number>;
13
+ /** Override in subclasses to print a summary. */
14
+ protected _report(): void;
15
+ abstract handleDirectory(msg: DirectoryMsg): Promise<void>;
16
+ abstract handleUrl(msg: UrlMsg): Promise<void>;
17
+ abstract handleQueue(msg: QueueMsg): Promise<void>;
18
+ }
19
+ /** An in-memory archive: category → Set<archive-key>. */
20
+ type ArchiveMap = Map<string, Set<string>>;
21
+ declare class DownloadJob extends Job {
22
+ /** Base output directory (prepended to all paths). */
23
+ basePath: string;
24
+ /** Current target directory metadata (set by directory messages). */
25
+ private _currentDir;
26
+ /** In-memory archive keyed by archive format. */
27
+ readonly archive: ArchiveMap;
103
28
  /**
104
- * Mutate the config at a given dot-path.
29
+ * Registry of per-category "archive formats" the key is formed
30
+ * by interpolating this format string over the metadata.
105
31
  */
106
- set(path: string, value: unknown): void;
32
+ private readonly _archiveFmts;
33
+ private _postCount;
34
+ private _fileCount;
35
+ private _downloadedBytes;
36
+ private _skippedCount;
37
+ registerArchive(category: string, format: string): void;
38
+ /** Simple format-string interpolation for archive keys. */
39
+ private _interp;
40
+ /** Check whether this URL has already been downloaded (and skip). */
41
+ private _isArchived;
42
+ /** Mark a post/media as archived. */
43
+ private _archive;
44
+ /** Handlers */
45
+ handleDirectory(msg: DirectoryMsg): Promise<void>;
46
+ handleUrl(msg: UrlMsg): Promise<void>;
47
+ handleQueue(msg: QueueMsg): Promise<void>;
48
+ /** Report */
49
+ protected _report(): void;
50
+ /** Path builders */
51
+ private _buildDirPath;
52
+ private _buildFilename;
53
+ }
54
+ declare class PrintJob extends Job {
55
+ private _currentDir;
56
+ private _files;
57
+ private _postCount;
58
+ private _fileCount;
59
+ private _width;
60
+ constructor(extractor: Extractor);
61
+ handleDirectory(msg: DirectoryMsg): Promise<void>;
62
+ handleUrl(msg: UrlMsg): Promise<void>;
63
+ handleQueue(msg: QueueMsg): Promise<void>;
64
+ /** Output */
65
+ private _flushPost;
66
+ private _wrap;
67
+ protected _report(): void;
107
68
  }
108
69
  //#endregion
109
- //#region core/extractor.d.ts
110
- interface ExtractorOptions {
111
- url: string;
112
- match: RegExpMatchArray;
113
- config: ConfigManager;
114
- http: HttpClient;
115
- storage: Storage;
116
- /** The logger interface — at minimum a debug/info/warn/error contract */
117
- log: Logger;
118
- }
119
- interface Logger {
120
- debug: (message: string, ...args: unknown[]) => void;
121
- info: (message: string, ...args: unknown[]) => void;
122
- warn: (message: string, ...args: unknown[]) => void;
123
- error: (message: string, ...args: unknown[]) => void;
124
- }
125
- /** A no-op logger */
126
- declare const noopLogger: Logger;
127
- declare abstract class Extractor {
128
- /** Human-readable category (e.g. ``'instagram'``) */
129
- abstract readonly category: string;
130
- /** Sub-category (e.g. ``'post'``, ``'posts'``, ``'reels'``) */
131
- abstract readonly subcategory: string;
132
- /** Root URL (e.g. ``'https://www.instagram.com'``) */
133
- abstract readonly root: string;
134
- /** Regex pattern to match against URLs */
135
- static readonly pattern: RegExp;
136
- /** The input URL */
137
- readonly url: string;
138
- /** Regex match groups from ``fromURL`` */
139
- readonly groups: readonly string[];
140
- readonly config: ConfigManager;
141
- /** HTTP client — public so Job can access for downloads */
142
- readonly http: HttpClient;
143
- /** Storage backend — public so Job can access for writes */
144
- readonly storage: Storage;
145
- /** Logger instance — public so Job can access for reporting */
146
- readonly log: Logger;
147
- /** Delay range in seconds — random between [min, max] before each request */
148
- protected requestInterval: [number, number];
149
- private _initialized;
150
- constructor(opts: ExtractorOptions);
151
- /** Initialization */
152
- /**
153
- * One-time async setup (cookies, session, internal state).
154
- * Safe to call multiple times — after the first call it becomes a no-op.
155
- */
156
- initialize(): Promise<void>;
157
- /**
158
- * Subclass hook for one-time setup.
159
- */
160
- protected _init(): Promise<void>;
161
- /** Async iteration */
162
- [Symbol.asyncIterator](): MessageIter;
163
- /**
164
- * The main extraction pipeline. Subclasses *must* implement this.
165
- */
166
- abstract items(): MessageIter;
167
- /** Config helpers */
168
- /**
169
- * Read a config value using the interpolated hierarchy.
170
- */
171
- protected _cfg(key: string, defaultVal?: ConfigValue): ConfigValue | undefined;
172
- /** HTTP */
173
- private _lastRequestTime;
174
- /**
175
- * Rate-limited HTTP request wrapper.
176
- */
177
- request(url: string, cfg?: RequestConfig): Promise<HttpResponse<unknown>>;
178
- /**
179
- * Convenience: request + parse JSON body.
180
- */
181
- requestJSON(url: string, cfg?: RequestConfig): Promise<unknown>;
182
- /** Rate limiting */
183
- /**
184
- * Sleep long enough to keep the minimum interval between requests.
185
- */
186
- private _throttle;
187
- /** Utility */
188
- /**
189
- * Convert a Unix timestamp (seconds or ms) to an ISO-8601 string.
190
- */
191
- parseTimestamp(ts: number | null | undefined): string;
192
- /**
193
- * Generate a random hex token (used for CSRF).
194
- */
195
- static generateToken(size?: number): string;
196
- }
197
- //#endregion
198
- //#region instagram/types.d.ts
70
+ //#region src/instagram/types.d.ts
199
71
  /**
200
72
  * Instagram API & parsed-post type definitions.
201
73
  *
@@ -441,7 +313,7 @@ interface ParserConfig {
441
313
  videosDash: boolean;
442
314
  }
443
315
  //#endregion
444
- //#region instagram/api.d.ts
316
+ //#region src/instagram/api.d.ts
445
317
  declare class InstagramRestAPI {
446
318
  private readonly http;
447
319
  private readonly root;
@@ -519,7 +391,7 @@ declare class InstagramRestAPI {
519
391
  private _parseIntCursor;
520
392
  }
521
393
  //#endregion
522
- //#region instagram/base.d.ts
394
+ //#region src/instagram/base.d.ts
523
395
  interface InstagramExtractorOptions extends ExtractorOptions {
524
396
  sessionId?: string;
525
397
  cookies?: Record<string, string>;
@@ -561,7 +433,7 @@ declare abstract class InstagramExtractor extends Extractor {
561
433
  protected _assignUser(user: InstagramUser): void;
562
434
  }
563
435
  //#endregion
564
- //#region instagram/extractors.d.ts
436
+ //#region src/instagram/extractors.d.ts
565
437
  declare class InstagramPostExtractor extends InstagramExtractor {
566
438
  static readonly subcategory = "post";
567
439
  static pattern: RegExp;
@@ -658,80 +530,77 @@ declare class InstagramSavedExtractor extends InstagramExtractor {
658
530
  posts(): AsyncGenerator<InstagramPost>;
659
531
  }
660
532
  //#endregion
661
- //#region sdk.d.ts
662
- interface SDKOptions {
663
- /** Custom HttpClient implementation (required). */
664
- http: HttpClient;
665
- /**
666
- * Custom Storage implementation for file output.
667
- * Only needed if you plan to call ``download()``.
668
- */
669
- storage?: Storage;
670
- /** Logger instance. Defaults to a silent no-op logger. */
671
- log?: Logger;
672
- /** Pre-extracted CSRF token (optional). */
673
- csrfToken?: string;
674
- }
675
- interface ExtractOptions {
676
- /** Max posts to extract (for user/tag feeds). */
677
- maxPosts?: number;
678
- /** Download videos (default: true). */
679
- videos?: boolean;
680
- /** Max posts to extract (for user/tag feeds). */
681
- limit?: number;
682
- }
683
- declare class InstagramSDK {
684
- readonly http: HttpClient;
685
- readonly storage: Storage;
686
- readonly log: Logger;
687
- readonly config: ConfigManager;
688
- private readonly _csrfToken;
689
- constructor(opts: {
690
- http: HttpClient;
691
- storage?: Storage;
692
- log?: Logger;
693
- csrfToken?: string;
694
- });
695
- /** High-level API */
696
- /**
697
- * Extract messages from an Instagram URL without downloading.
698
- *
699
- * Returns an async generator yielding Directory / Url / Queue messages.
700
- * Each ``url`` message includes full metadata (post_id, username, dimensions, etc.).
701
- *
702
- * ```ts
703
- * for await (const msg of instagram.extract('https://www.instagram.com/p/.../')) {
704
- * if (msg.type === 'url') {
705
- * console.log(msg.url, msg.metadata.media_id)
706
- * }
707
- * }
708
- * ```
709
- */
710
- extract(url: string): MessageIter;
711
- /**
712
- * Download all media from an Instagram URL.
713
- *
714
- * Uses the built-in DownloadJob + Storage to save files to disk.
715
- * Requires ``storage`` to be set in constructor options.
716
- *
717
- * ```ts
718
- * const stats = await instagram.download(
719
- * 'https://www.instagram.com/p/.../',
720
- * './my-downloads',
721
- * )
722
- * // → { posts: 1, files: 9, bytes: 4500000 }
723
- * ```
724
- */
725
- download(url: string, outputDir?: string): Promise<{
726
- posts: number;
727
- files: number;
728
- bytes: number;
729
- }>;
730
- /** Internal */
731
- /**
732
- * Resolve a URL to an Extractor instance via pattern matching.
733
- */
734
- private _resolve;
735
- }
533
+ //#region src/instagram/parsers.d.ts
534
+ /** Main entry — REST */
535
+ declare function parsePostRest(post: InstagramPost, cfg: ParserConfig): ParsedPost;
536
+ /** Tagged users */
537
+ declare function extractTaggedUsers(src: Record<string, unknown>, dest: ParsedMedia): void;
538
+ /** Audio / music extraction */
539
+ declare function extractAudio(src: Record<string, unknown>, dest: Record<string, unknown>, sticker: MusicSticker, cfg: ParserConfig): ParsedMedia | null;
540
+ /** GraphQL parser */
541
+ declare function parsePostGraphql(post: Record<string, unknown>, cfg: ParserConfig): ParsedPost;
542
+ //#endregion
543
+ //#region src/message.d.ts
544
+ declare function directory(metadata?: Metadata): DirectoryMsg;
545
+ declare function url(u: string, metadata?: Metadata): UrlMsg;
546
+ declare function queue(u: string, metadata?: Metadata & {
547
+ _extractor?: ExtractorClass;
548
+ }): QueueMsg;
549
+ //#endregion
550
+ //#region src/utils/id-codec.d.ts
551
+ /**
552
+ * Instagram-style Base64-variant ID shortcode conversion.
553
+ */
554
+ /**
555
+ * Decode an Instagram shortcode into its numeric post ID.
556
+ */
557
+ declare function idFromShortcode(shortcode: string): string;
558
+ /**
559
+ * Encode a numeric post ID into an Instagram shortcode.
560
+ */
561
+ declare function shortcodeFromId(postId: string | number): string;
562
+ //#endregion
563
+ //#region src/utils/text.d.ts
564
+ /**
565
+ * Text utilities ported from gallery-dl's ``text`` module.
566
+ *
567
+ * All functions are pure and environment-agnostic.
568
+ */
569
+ /** String extraction */
570
+ /**
571
+ * Extract the substring between ``begin`` and ``end`` from ``txt``.
572
+ * Returns the substring or ``null`` if either delimiter is missing.
573
+ */
574
+ declare function extract(txt: string, begin: string, end: string): string | null;
575
+ /**
576
+ * Shorthand: same as ``extract`` but returns ``default_`` on failure.
577
+ * Mirrors the Python ``extr()`` function.
578
+ */
579
+ declare function extr(txt: string, begin: string, end: string, default_?: string): string;
580
+ /** Unicode / HTML */
581
+ /**
582
+ * Decode ``\\uXXXX`` escape sequences in a string.
583
+ */
584
+ declare function parseUnicodeEscapes(text: string): string;
585
+ declare function unescape(text: string): string;
586
+ /** URL helpers */
587
+ /**
588
+ * URL-decode a string.
589
+ */
590
+ declare function unquote(text: string): string;
591
+ /**
592
+ * Ensure a URL starts with ``https://`` (or ``http://``).
593
+ */
594
+ declare function ensureHttpScheme(url: string, scheme?: string): string;
595
+ /**
596
+ * Extract filename + extension from a URL and write into ``meta``.
597
+ */
598
+ declare function nameExtFromURL(url: string, meta: Record<string, unknown>): void;
599
+ /**
600
+ * Parse an integer from a possibly-null value. Returns ``default_`` on failure.
601
+ */
602
+ declare function parseInt(value: string | number | null | undefined, default_?: number): number;
603
+ /** Pre-configured hashtag regex. */
604
+ declare const findTags: (text: string) => string[];
736
605
  //#endregion
737
- export { Extractor as A, HttpResponse as B, InstagramUser as C, ParserConfig as D, ParsedPost as E, Config as F, RequestConfig as G, MessageIter as H, ConfigValue as I, Storage as K, DirectoryMsg as L, Logger as M, noopLogger as N, TaggedUser as O, ConfigManager as P, ExtractorClass as R, InstagramPost as S, ParsedMedia as T, Metadata as U, Message as V, QueueMsg as W, InstagramRestAPI as _, InstagramHighlightsExtractor as a, InstagramCarouselItem as b, InstagramPostsExtractor as c, InstagramStoriesExtractor as d, InstagramTagExtractor as f, InstagramExtractorOptions as g, InstagramExtractor as h, InstagramAvatarExtractor as i, ExtractorOptions as j, VideoVersion as k, InstagramReelsExtractor as l, InstagramUserExtractor as m, InstagramSDK as n, InstagramInfoExtractor as o, InstagramTaggedExtractor as p, UrlMsg as q, SDKOptions as r, InstagramPostExtractor as s, ExtractOptions as t, InstagramSavedExtractor as u, Coauthor as v, MusicSticker as w, InstagramLocation as x, ImageCandidate as y, HttpClient as z };
606
+ export { type Coauthor, type Config, ConfigManager, type ConfigValue, type DirectoryMsg, DownloadJob, type ExtractOptions, Extractor, type ExtractorClass, type ExtractorOptions, type HttpClient, type HttpResponse, type ImageCandidate, InstagramAvatarExtractor, type InstagramCarouselItem, InstagramExtractor, type InstagramExtractorOptions, InstagramHighlightsExtractor, InstagramInfoExtractor, type InstagramLocation, type InstagramPost, InstagramPostExtractor, InstagramPostsExtractor, InstagramReelsExtractor, InstagramRestAPI, InstagramSDK, InstagramSavedExtractor, InstagramStoriesExtractor, InstagramTagExtractor, InstagramTaggedExtractor, type InstagramUser, InstagramUserExtractor, Job, type Logger, type Message, type MessageIter, type Metadata, type ParsedMedia, type ParsedPost, type ParserConfig, PrintJob, type QueueMsg, type RequestConfig, type SDKOptions, type Storage, type TaggedUser, type UrlMsg, type VideoVersion, directory, ensureHttpScheme, extr, extract, extractAudio, extractTaggedUsers, findTags, idFromShortcode, nameExtFromURL, noopLogger, parseInt, parsePostGraphql, parsePostRest, parseUnicodeEscapes, queue, shortcodeFromId, unescape, unquote, url };