@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/LICENSE +340 -0
- package/README.md +134 -0
- package/dist/adapter-CFsiiEpM.cjs +83 -0
- package/dist/adapter-tSleX8Cr.mjs +59 -0
- package/dist/dl-ins.mjs +5129 -0
- package/dist/index.cjs +40 -0
- package/dist/{sdk-B9fRyc1e.d.mts → index.d.cts} +139 -270
- package/dist/index.d.mts +470 -51
- package/dist/index.mjs +2 -40
- package/dist/node.cjs +43 -0
- package/dist/node.d.cts +47 -0
- package/dist/node.d.mts +47 -0
- package/dist/node.mjs +42 -0
- package/dist/{extractors-Byw-2lPL.mjs → sdk-Bn0VCUIT.mjs} +291 -215
- package/dist/sdk-CK9x5wFL.d.cts +259 -0
- package/dist/sdk-CK9x5wFL.d.mts +259 -0
- package/dist/sdk-nzhAxf1O.cjs +2246 -0
- package/dist/storage-77hqz5Fi.mjs +24 -0
- package/dist/storage-BwGaT6XO.cjs +24 -0
- package/package.json +32 -25
- package/cli/adapter.ts +0 -284
- package/cli/cookies.ts +0 -59
- package/cli/index.ts +0 -337
- package/config.ts +0 -80
- package/core/extractor.ts +0 -217
- package/core/job.ts +0 -581
- package/dist/adapter-Bt86eL1R.mjs +0 -189
- package/dist/cli/index.d.mts +0 -1
- package/dist/cli/index.mjs +0 -3160
- package/dist/sdk.d.mts +0 -2
- package/dist/sdk.mjs +0 -93
- package/index.ts +0 -159
- package/instagram/api.ts +0 -531
- package/instagram/base.ts +0 -275
- package/instagram/extractors.ts +0 -521
- package/instagram/index.ts +0 -43
- package/instagram/parsers.ts +0 -583
- package/instagram/types.ts +0 -244
- package/message.ts +0 -31
- package/types.ts +0 -115
- package/utils/id-codec.ts +0 -39
- package/utils/text.ts +0 -178
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
//#region src/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> {
|
|
22
|
+
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 src/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;
|
|
99
|
+
/**
|
|
100
|
+
* Interpolate a config key through a hierarchy of paths.
|
|
101
|
+
*/
|
|
102
|
+
interpolate(cfgPath: readonly string[], key: string, defaultVal?: ConfigValue): ConfigValue | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* Mutate the config at a given dot-path.
|
|
105
|
+
*/
|
|
106
|
+
set(path: string, value: unknown): void;
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/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 src/sdk.d.ts
|
|
199
|
+
interface SDKOptions {
|
|
200
|
+
/** Custom HttpClient implementation (required). */
|
|
201
|
+
http: HttpClient;
|
|
202
|
+
/**
|
|
203
|
+
* Custom Storage implementation for file output.
|
|
204
|
+
* Only needed if you plan to call ``download()``.
|
|
205
|
+
*/
|
|
206
|
+
storage?: Storage;
|
|
207
|
+
/** Logger instance. Defaults to a silent no-op logger. */
|
|
208
|
+
log?: Logger;
|
|
209
|
+
/** Pre-extracted CSRF token (optional). */
|
|
210
|
+
csrfToken?: string;
|
|
211
|
+
}
|
|
212
|
+
interface ExtractOptions {
|
|
213
|
+
/** Max posts to extract (for user/tag feeds). */
|
|
214
|
+
maxPosts?: number;
|
|
215
|
+
/** Download videos (default: true). */
|
|
216
|
+
videos?: boolean;
|
|
217
|
+
/** Max posts to extract (for user/tag feeds). */
|
|
218
|
+
limit?: number;
|
|
219
|
+
}
|
|
220
|
+
declare class InstagramSDK {
|
|
221
|
+
readonly http: HttpClient;
|
|
222
|
+
readonly storage: Storage;
|
|
223
|
+
readonly log: Logger;
|
|
224
|
+
readonly config: ConfigManager;
|
|
225
|
+
private readonly _csrfToken;
|
|
226
|
+
constructor(opts: {
|
|
227
|
+
http: HttpClient;
|
|
228
|
+
storage?: Storage;
|
|
229
|
+
log?: Logger;
|
|
230
|
+
csrfToken?: string;
|
|
231
|
+
});
|
|
232
|
+
/**
|
|
233
|
+
* Extract messages from an Instagram URL without downloading.
|
|
234
|
+
*
|
|
235
|
+
* Returns an async generator yielding Directory / Url / Queue messages.
|
|
236
|
+
* Each ``url`` message includes full metadata (post_id, username, dimensions, etc.).
|
|
237
|
+
*/
|
|
238
|
+
extract(url: string): MessageIter;
|
|
239
|
+
/**
|
|
240
|
+
* Download all media from an Instagram URL.
|
|
241
|
+
*
|
|
242
|
+
* Uses the built-in DownloadJob + Storage to save files to disk.
|
|
243
|
+
* Requires ``storage`` to be set in constructor options.
|
|
244
|
+
*
|
|
245
|
+
* ```ts
|
|
246
|
+
* const stats = await ig.download('https://www.instagram.com/p/.../', './my-downloads')
|
|
247
|
+
* // → { posts: 1, files: 9, bytes: 4500000 }
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
download(url: string, outputDir?: string): Promise<{
|
|
251
|
+
posts: number;
|
|
252
|
+
files: number;
|
|
253
|
+
bytes: number;
|
|
254
|
+
}>;
|
|
255
|
+
/** Resolve a URL to an Extractor instance via pattern matching. */
|
|
256
|
+
private _resolve;
|
|
257
|
+
}
|
|
258
|
+
//#endregion
|
|
259
|
+
export { Metadata as _, ExtractorOptions as a, Storage as b, ConfigManager as c, DirectoryMsg as d, ExtractorClass as f, MessageIter as g, Message as h, Extractor as i, Config as l, HttpResponse as m, InstagramSDK as n, Logger as o, HttpClient as p, SDKOptions as r, noopLogger as s, ExtractOptions as t, ConfigValue as u, QueueMsg as v, UrlMsg as x, RequestConfig as y };
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
//#region src/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> {
|
|
22
|
+
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 src/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;
|
|
99
|
+
/**
|
|
100
|
+
* Interpolate a config key through a hierarchy of paths.
|
|
101
|
+
*/
|
|
102
|
+
interpolate(cfgPath: readonly string[], key: string, defaultVal?: ConfigValue): ConfigValue | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* Mutate the config at a given dot-path.
|
|
105
|
+
*/
|
|
106
|
+
set(path: string, value: unknown): void;
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/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 src/sdk.d.ts
|
|
199
|
+
interface SDKOptions {
|
|
200
|
+
/** Custom HttpClient implementation (required). */
|
|
201
|
+
http: HttpClient;
|
|
202
|
+
/**
|
|
203
|
+
* Custom Storage implementation for file output.
|
|
204
|
+
* Only needed if you plan to call ``download()``.
|
|
205
|
+
*/
|
|
206
|
+
storage?: Storage;
|
|
207
|
+
/** Logger instance. Defaults to a silent no-op logger. */
|
|
208
|
+
log?: Logger;
|
|
209
|
+
/** Pre-extracted CSRF token (optional). */
|
|
210
|
+
csrfToken?: string;
|
|
211
|
+
}
|
|
212
|
+
interface ExtractOptions {
|
|
213
|
+
/** Max posts to extract (for user/tag feeds). */
|
|
214
|
+
maxPosts?: number;
|
|
215
|
+
/** Download videos (default: true). */
|
|
216
|
+
videos?: boolean;
|
|
217
|
+
/** Max posts to extract (for user/tag feeds). */
|
|
218
|
+
limit?: number;
|
|
219
|
+
}
|
|
220
|
+
declare class InstagramSDK {
|
|
221
|
+
readonly http: HttpClient;
|
|
222
|
+
readonly storage: Storage;
|
|
223
|
+
readonly log: Logger;
|
|
224
|
+
readonly config: ConfigManager;
|
|
225
|
+
private readonly _csrfToken;
|
|
226
|
+
constructor(opts: {
|
|
227
|
+
http: HttpClient;
|
|
228
|
+
storage?: Storage;
|
|
229
|
+
log?: Logger;
|
|
230
|
+
csrfToken?: string;
|
|
231
|
+
});
|
|
232
|
+
/**
|
|
233
|
+
* Extract messages from an Instagram URL without downloading.
|
|
234
|
+
*
|
|
235
|
+
* Returns an async generator yielding Directory / Url / Queue messages.
|
|
236
|
+
* Each ``url`` message includes full metadata (post_id, username, dimensions, etc.).
|
|
237
|
+
*/
|
|
238
|
+
extract(url: string): MessageIter;
|
|
239
|
+
/**
|
|
240
|
+
* Download all media from an Instagram URL.
|
|
241
|
+
*
|
|
242
|
+
* Uses the built-in DownloadJob + Storage to save files to disk.
|
|
243
|
+
* Requires ``storage`` to be set in constructor options.
|
|
244
|
+
*
|
|
245
|
+
* ```ts
|
|
246
|
+
* const stats = await ig.download('https://www.instagram.com/p/.../', './my-downloads')
|
|
247
|
+
* // → { posts: 1, files: 9, bytes: 4500000 }
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
download(url: string, outputDir?: string): Promise<{
|
|
251
|
+
posts: number;
|
|
252
|
+
files: number;
|
|
253
|
+
bytes: number;
|
|
254
|
+
}>;
|
|
255
|
+
/** Resolve a URL to an Extractor instance via pattern matching. */
|
|
256
|
+
private _resolve;
|
|
257
|
+
}
|
|
258
|
+
//#endregion
|
|
259
|
+
export { Metadata as _, ExtractorOptions as a, Storage as b, ConfigManager as c, DirectoryMsg as d, ExtractorClass as f, MessageIter as g, Message as h, Extractor as i, Config as l, HttpResponse as m, InstagramSDK as n, Logger as o, HttpClient as p, SDKOptions as r, noopLogger as s, ExtractOptions as t, ConfigValue as u, QueueMsg as v, UrlMsg as x, RequestConfig as y };
|