@chilfish/gallery-dl-instagram 0.1.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.
@@ -0,0 +1,187 @@
1
+ import { A as Extractor, B as HttpResponse, C as InstagramUser, D as ParserConfig, E as ParsedPost, F as Config, G as RequestConfig, H as MessageIter, I as ConfigValue, K as Storage, L as DirectoryMsg, M as Logger, N as noopLogger, O as TaggedUser, P as ConfigManager, R as ExtractorClass, S as InstagramPost, T as ParsedMedia, U as Metadata, V as Message, W as QueueMsg, _ as InstagramRestAPI, a as InstagramHighlightsExtractor, b as InstagramCarouselItem, c as InstagramPostsExtractor, d as InstagramStoriesExtractor, f as InstagramTagExtractor, g as InstagramExtractorOptions, h as InstagramExtractor, i as InstagramAvatarExtractor, j as ExtractorOptions, k as VideoVersion, l as InstagramReelsExtractor, m as InstagramUserExtractor, n as InstagramSDK, o as InstagramInfoExtractor, p as InstagramTaggedExtractor, q as UrlMsg, r as SDKOptions, s as InstagramPostExtractor, t as ExtractOptions, u as InstagramSavedExtractor, v as Coauthor, w as MusicSticker, x as InstagramLocation, y as ImageCandidate, z as HttpClient } from "./sdk-B9fRyc1e.mjs";
2
+
3
+ //#region core/job.d.ts
4
+ declare abstract class Job {
5
+ readonly extractor: Extractor;
6
+ status: number;
7
+ constructor(extractor: Extractor);
8
+ /**
9
+ * Main entry point. Calls ``extractor[Symbol.asyncIterator]()`` and
10
+ * dispatches every yielded message.
11
+ */
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;
28
+ /**
29
+ * Registry of per-category "archive formats" — the key is formed
30
+ * by interpolating this format string over the metadata.
31
+ */
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;
68
+ }
69
+ //#endregion
70
+ //#region instagram/parsers.d.ts
71
+ /** Main entry — REST */
72
+ declare function parsePostRest(post: InstagramPost, cfg: ParserConfig): ParsedPost;
73
+ /** Tagged users */
74
+ declare function extractTaggedUsers(src: Record<string, unknown>, dest: ParsedMedia): void;
75
+ /** Audio / music extraction */
76
+ declare function extractAudio(src: Record<string, unknown>, dest: Record<string, unknown>, sticker: MusicSticker, cfg: ParserConfig): ParsedMedia | null;
77
+ /** GraphQL parser */
78
+ declare function parsePostGraphql(post: Record<string, unknown>, cfg: ParserConfig): ParsedPost;
79
+ //#endregion
80
+ //#region message.d.ts
81
+ declare function directory(metadata?: Metadata): DirectoryMsg;
82
+ declare function url(u: string, metadata?: Metadata): UrlMsg;
83
+ declare function queue(u: string, metadata?: Metadata & {
84
+ _extractor?: ExtractorClass;
85
+ }): QueueMsg;
86
+ //#endregion
87
+ //#region utils/id-codec.d.ts
88
+ /**
89
+ * Instagram-style Base64-variant ID ↔ shortcode conversion.
90
+ */
91
+ /**
92
+ * Decode an Instagram shortcode into its numeric post ID.
93
+ */
94
+ declare function idFromShortcode(shortcode: string): string;
95
+ /**
96
+ * Encode a numeric post ID into an Instagram shortcode.
97
+ */
98
+ declare function shortcodeFromId(postId: string | number): string;
99
+ //#endregion
100
+ //#region utils/text.d.ts
101
+ /**
102
+ * Text utilities ported from gallery-dl's ``text`` module.
103
+ *
104
+ * All functions are pure and environment-agnostic.
105
+ */
106
+ /** String extraction */
107
+ /**
108
+ * Extract the substring between ``begin`` and ``end`` from ``txt``.
109
+ * Returns the substring or ``null`` if either delimiter is missing.
110
+ */
111
+ declare function extract(txt: string, begin: string, end: string): string | null;
112
+ /**
113
+ * Shorthand: same as ``extract`` but returns ``default_`` on failure.
114
+ * Mirrors the Python ``extr()`` function.
115
+ */
116
+ declare function extr(txt: string, begin: string, end: string, default_?: string): string;
117
+ /** Unicode / HTML */
118
+ /**
119
+ * Decode ``\\uXXXX`` escape sequences in a string.
120
+ */
121
+ declare function parseUnicodeEscapes(text: string): string;
122
+ declare function unescape(text: string): string;
123
+ /** URL helpers */
124
+ /**
125
+ * URL-decode a string.
126
+ */
127
+ declare function unquote(text: string): string;
128
+ /**
129
+ * Ensure a URL starts with ``https://`` (or ``http://``).
130
+ */
131
+ declare function ensureHttpScheme(url: string, scheme?: string): string;
132
+ /**
133
+ * Extract filename + extension from a URL and write into ``meta``.
134
+ */
135
+ declare function nameExtFromURL(url: string, meta: Record<string, unknown>): void;
136
+ /**
137
+ * Parse an integer from a possibly-null value. Returns ``default_`` on failure.
138
+ */
139
+ declare function parseInt(value: string | number | null | undefined, default_?: number): number;
140
+ /** Pre-configured hashtag regex. */
141
+ declare const findTags: (text: string) => string[];
142
+ //#endregion
143
+ //#region index.d.ts
144
+ /** Options for the Node.js convenience factory. */
145
+ interface CreateSDKOptions {
146
+ /**
147
+ * Full browser Cookie header string.
148
+ * Copy from DevTools → Network → Request Headers → Cookie.
149
+ * Auto-extracts csrftoken for X-CSRFToken header.
150
+ *
151
+ * Either ``cookies`` or ``http`` must be provided.
152
+ */
153
+ cookies?: string;
154
+ /**
155
+ * Custom HttpClient implementation.
156
+ * If omitted, a Node.js axios-based client is created from ``cookies``.
157
+ */
158
+ http?: HttpClient;
159
+ /**
160
+ * Custom Storage implementation for file output.
161
+ * Defaults to Node.js fs/promises-based storage.
162
+ */
163
+ storage?: Storage;
164
+ /**
165
+ * Logger instance. Defaults to a silent no-op logger.
166
+ */
167
+ log?: Logger;
168
+ }
169
+ /**
170
+ * Create an SDK instance with Node.js defaults.
171
+ *
172
+ * When ``cookies`` is provided, auto-creates an axios-based HttpClient
173
+ * with CSRF token extraction. Pass ``http`` directly for custom adapters.
174
+ *
175
+ * ```ts
176
+ * import { createSDK } from '@chilfish/gallery-dl-instagram'
177
+ *
178
+ * // Node.js with cookies
179
+ * const ig = await createSDK({ cookies: 'ds_user_id=...; sessionid=...' })
180
+ *
181
+ * // Custom http adapter (browser / Deno / Edge)
182
+ * const ig = await createSDK({ http: myHttpClient, storage: myStorage })
183
+ * ```
184
+ */
185
+ declare function createSDK(opts?: CreateSDKOptions): Promise<InstagramSDK>;
186
+ //#endregion
187
+ export { type Coauthor, type Config, ConfigManager, type ConfigValue, CreateSDKOptions, 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, createSDK, directory, ensureHttpScheme, extr, extract, extractAudio, extractTaggedUsers, findTags, idFromShortcode, nameExtFromURL, noopLogger, parseInt, parsePostGraphql, parsePostRest, parseUnicodeEscapes, queue, shortcodeFromId, unescape, unquote, url };
package/dist/index.mjs ADDED
@@ -0,0 +1,40 @@
1
+ import { a as extractCsrfFromCookies, r as createStorage, t as createHttpClient } from "./adapter-Bt86eL1R.mjs";
2
+ import { A as idFromShortcode, C as parseUnicodeEscapes, D as queue, E as directory, F as ConfigManager, I as Extractor, L as noopLogger, M as DownloadJob, N as Job, O as url, P as PrintJob, S as parseInt, T as unquote, _ as ensureHttpScheme, a as InstagramPostsExtractor, b as findTags, c as InstagramStoriesExtractor, d as InstagramUserExtractor, f as InstagramExtractor, g as parsePostRest, h as parsePostGraphql, i as InstagramPostExtractor, j as shortcodeFromId, k as InstagramRestAPI, l as InstagramTagExtractor, m as extractTaggedUsers, n as InstagramHighlightsExtractor, o as InstagramReelsExtractor, p as extractAudio, r as InstagramInfoExtractor, s as InstagramSavedExtractor, t as InstagramAvatarExtractor, u as InstagramTaggedExtractor, v as extr, w as unescape, x as nameExtFromURL, y as extract } from "./extractors-Byw-2lPL.mjs";
3
+ import { InstagramSDK } from "./sdk.mjs";
4
+ //#region index.ts
5
+ /**
6
+ * Create an SDK instance with Node.js defaults.
7
+ *
8
+ * When ``cookies`` is provided, auto-creates an axios-based HttpClient
9
+ * with CSRF token extraction. Pass ``http`` directly for custom adapters.
10
+ *
11
+ * ```ts
12
+ * import { createSDK } from '@chilfish/gallery-dl-instagram'
13
+ *
14
+ * // Node.js with cookies
15
+ * const ig = await createSDK({ cookies: 'ds_user_id=...; sessionid=...' })
16
+ *
17
+ * // Custom http adapter (browser / Deno / Edge)
18
+ * const ig = await createSDK({ http: myHttpClient, storage: myStorage })
19
+ * ```
20
+ */
21
+ async function createSDK(opts = {}) {
22
+ const { InstagramSDK } = await import("./sdk.mjs");
23
+ const log = opts.log ?? noopLogger;
24
+ const storage = opts.storage ?? createStorage();
25
+ let http;
26
+ let csrfToken = "";
27
+ if (opts.http) http = opts.http;
28
+ else if (opts.cookies) {
29
+ csrfToken = extractCsrfFromCookies(opts.cookies);
30
+ http = createHttpClient(void 0, opts.cookies, log);
31
+ } else throw new Error("Either \"cookies\" or \"http\" must be provided. Get cookies from browser DevTools → Application → Cookies → instagram.com");
32
+ return new InstagramSDK({
33
+ http,
34
+ storage,
35
+ log,
36
+ csrfToken
37
+ });
38
+ }
39
+ //#endregion
40
+ export { ConfigManager, DownloadJob, Extractor, InstagramAvatarExtractor, InstagramExtractor, InstagramHighlightsExtractor, InstagramInfoExtractor, InstagramPostExtractor, InstagramPostsExtractor, InstagramReelsExtractor, InstagramRestAPI, InstagramSDK, InstagramSavedExtractor, InstagramStoriesExtractor, InstagramTagExtractor, InstagramTaggedExtractor, InstagramUserExtractor, Job, PrintJob, createSDK, directory, ensureHttpScheme, extr, extract, extractAudio, extractTaggedUsers, findTags, idFromShortcode, nameExtFromURL, noopLogger, parseInt, parsePostGraphql, parsePostRest, parseUnicodeEscapes, queue, shortcodeFromId, unescape, unquote, url };