@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.
- package/cli/adapter.ts +284 -0
- package/cli/cookies.ts +59 -0
- package/cli/index.ts +337 -0
- package/config.ts +80 -0
- package/core/extractor.ts +217 -0
- package/core/job.ts +581 -0
- package/dist/adapter-Bt86eL1R.mjs +189 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +3160 -0
- package/dist/extractors-Byw-2lPL.mjs +1943 -0
- package/dist/index.d.mts +187 -0
- package/dist/index.mjs +40 -0
- package/dist/sdk-B9fRyc1e.d.mts +737 -0
- package/dist/sdk.d.mts +2 -0
- package/dist/sdk.mjs +93 -0
- package/index.ts +159 -0
- package/instagram/api.ts +531 -0
- package/instagram/base.ts +275 -0
- package/instagram/extractors.ts +521 -0
- package/instagram/index.ts +43 -0
- package/instagram/parsers.ts +583 -0
- package/instagram/types.ts +244 -0
- package/message.ts +31 -0
- package/package.json +68 -0
- package/types.ts +115 -0
- package/utils/id-codec.ts +39 -0
- package/utils/text.ts +178 -0
package/dist/sdk.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as InstagramHighlightsExtractor, c as InstagramPostsExtractor, d as InstagramStoriesExtractor, f as InstagramTagExtractor, i as InstagramAvatarExtractor, l as InstagramReelsExtractor, m as InstagramUserExtractor, n as InstagramSDK, o as InstagramInfoExtractor, p as InstagramTaggedExtractor, r as SDKOptions, s as InstagramPostExtractor, t as ExtractOptions, u as InstagramSavedExtractor } from "./sdk-B9fRyc1e.mjs";
|
|
2
|
+
export { ExtractOptions, InstagramAvatarExtractor, InstagramHighlightsExtractor, InstagramInfoExtractor, InstagramPostExtractor, InstagramPostsExtractor, InstagramReelsExtractor, InstagramSDK, InstagramSavedExtractor, InstagramStoriesExtractor, InstagramTagExtractor, InstagramTaggedExtractor, InstagramUserExtractor, SDKOptions };
|
package/dist/sdk.mjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { F as ConfigManager, L as noopLogger, M as DownloadJob, a as InstagramPostsExtractor, c as InstagramStoriesExtractor, d as InstagramUserExtractor, i as InstagramPostExtractor, l as InstagramTagExtractor, n as InstagramHighlightsExtractor, o as InstagramReelsExtractor, r as InstagramInfoExtractor, s as InstagramSavedExtractor, t as InstagramAvatarExtractor, u as InstagramTaggedExtractor } from "./extractors-Byw-2lPL.mjs";
|
|
2
|
+
//#region sdk.ts
|
|
3
|
+
var InstagramSDK = class {
|
|
4
|
+
http;
|
|
5
|
+
storage;
|
|
6
|
+
log;
|
|
7
|
+
config;
|
|
8
|
+
_csrfToken;
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
this.http = opts.http;
|
|
11
|
+
this.storage = opts.storage ?? void 0;
|
|
12
|
+
this.log = opts.log ?? noopLogger;
|
|
13
|
+
this.config = new ConfigManager();
|
|
14
|
+
this._csrfToken = opts.csrfToken ?? "";
|
|
15
|
+
}
|
|
16
|
+
/** High-level API */
|
|
17
|
+
/**
|
|
18
|
+
* Extract messages from an Instagram URL without downloading.
|
|
19
|
+
*
|
|
20
|
+
* Returns an async generator yielding Directory / Url / Queue messages.
|
|
21
|
+
* Each ``url`` message includes full metadata (post_id, username, dimensions, etc.).
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* for await (const msg of instagram.extract('https://www.instagram.com/p/.../')) {
|
|
25
|
+
* if (msg.type === 'url') {
|
|
26
|
+
* console.log(msg.url, msg.metadata.media_id)
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
async *extract(url) {
|
|
32
|
+
const extractor = this._resolve(url);
|
|
33
|
+
await extractor.initialize();
|
|
34
|
+
yield* extractor;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Download all media from an Instagram URL.
|
|
38
|
+
*
|
|
39
|
+
* Uses the built-in DownloadJob + Storage to save files to disk.
|
|
40
|
+
* Requires ``storage`` to be set in constructor options.
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* const stats = await instagram.download(
|
|
44
|
+
* 'https://www.instagram.com/p/.../',
|
|
45
|
+
* './my-downloads',
|
|
46
|
+
* )
|
|
47
|
+
* // → { posts: 1, files: 9, bytes: 4500000 }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
async download(url, outputDir = "./data") {
|
|
51
|
+
const job = new DownloadJob(this._resolve(url));
|
|
52
|
+
job.basePath = outputDir;
|
|
53
|
+
await job.run();
|
|
54
|
+
return {
|
|
55
|
+
posts: job._postCount ?? 0,
|
|
56
|
+
files: job._fileCount ?? 0,
|
|
57
|
+
bytes: job._downloadedBytes ?? 0
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Internal */
|
|
61
|
+
/**
|
|
62
|
+
* Resolve a URL to an Extractor instance via pattern matching.
|
|
63
|
+
*/
|
|
64
|
+
_resolve(url) {
|
|
65
|
+
for (const Cls of [
|
|
66
|
+
InstagramPostExtractor,
|
|
67
|
+
InstagramStoriesExtractor,
|
|
68
|
+
InstagramHighlightsExtractor,
|
|
69
|
+
InstagramTagExtractor,
|
|
70
|
+
InstagramSavedExtractor,
|
|
71
|
+
InstagramPostsExtractor,
|
|
72
|
+
InstagramReelsExtractor,
|
|
73
|
+
InstagramTaggedExtractor,
|
|
74
|
+
InstagramInfoExtractor,
|
|
75
|
+
InstagramAvatarExtractor,
|
|
76
|
+
InstagramUserExtractor
|
|
77
|
+
]) {
|
|
78
|
+
const match = Cls.pattern.exec(url);
|
|
79
|
+
if (match) return Reflect.construct(Cls, [{
|
|
80
|
+
url,
|
|
81
|
+
match,
|
|
82
|
+
config: this.config,
|
|
83
|
+
http: this.http,
|
|
84
|
+
storage: this.storage,
|
|
85
|
+
log: this.log,
|
|
86
|
+
csrfToken: this._csrfToken
|
|
87
|
+
}]);
|
|
88
|
+
}
|
|
89
|
+
throw new Error(`No extractor matched URL: ${url}. Supported: /p/, /reel/, /{user}/, /stories/, /highlights/, /explore/tags/, /saved/`);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
//#endregion
|
|
93
|
+
export { InstagramAvatarExtractor, InstagramHighlightsExtractor, InstagramInfoExtractor, InstagramPostExtractor, InstagramPostsExtractor, InstagramReelsExtractor, InstagramSDK, InstagramSavedExtractor, InstagramStoriesExtractor, InstagramTagExtractor, InstagramTaggedExtractor, InstagramUserExtractor };
|
package/index.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gallery-dl TypeScript port — public API.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { DownloadJob, InstagramPostExtractor, ConfigManager } from './ts/index';
|
|
8
|
+
*
|
|
9
|
+
* const config = new ConfigManager({
|
|
10
|
+
* extractor: {
|
|
11
|
+
* instagram: {
|
|
12
|
+
* videos: false,
|
|
13
|
+
* 'max-posts': 10,
|
|
14
|
+
* },
|
|
15
|
+
* },
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* const opts = {
|
|
19
|
+
* url: 'https://www.instagram.com/p/CxAbCdEfGh/',
|
|
20
|
+
* match: InstagramPostExtractor.pattern.exec('https://www.instagram.com/p/CxAbCdEfGh/')!,
|
|
21
|
+
* config,
|
|
22
|
+
* http, // your HttpClient implementation
|
|
23
|
+
* storage, // your Storage implementation
|
|
24
|
+
* log: console, // or custom Logger
|
|
25
|
+
* };
|
|
26
|
+
*
|
|
27
|
+
* const extractor = new InstagramPostExtractor(opts);
|
|
28
|
+
* const job = new DownloadJob(extractor);
|
|
29
|
+
* const status = await job.run();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import type { Logger } from './core/extractor'
|
|
34
|
+
import type { HttpClient, Storage } from './types'
|
|
35
|
+
import { createHttpClient, createStorage, extractCsrfFromCookies } from './cli/adapter'
|
|
36
|
+
import { noopLogger } from './core/extractor'
|
|
37
|
+
|
|
38
|
+
// Config
|
|
39
|
+
export { ConfigManager } from './config'
|
|
40
|
+
// Core
|
|
41
|
+
export { Extractor } from './core/extractor'
|
|
42
|
+
export type {
|
|
43
|
+
ExtractorOptions,
|
|
44
|
+
Logger,
|
|
45
|
+
} from './core/extractor'
|
|
46
|
+
export { noopLogger } from './core/extractor'
|
|
47
|
+
|
|
48
|
+
export { DownloadJob, Job, PrintJob } from './core/job'
|
|
49
|
+
|
|
50
|
+
// Instagram
|
|
51
|
+
export * from './instagram/index'
|
|
52
|
+
// Message
|
|
53
|
+
export { directory, queue, url } from './message'
|
|
54
|
+
|
|
55
|
+
export type { MessageIter } from './message'
|
|
56
|
+
|
|
57
|
+
// SDK (high-level) — platform-agnostic class
|
|
58
|
+
export { InstagramSDK } from './sdk'
|
|
59
|
+
|
|
60
|
+
export type { ExtractOptions, SDKOptions } from './sdk'
|
|
61
|
+
// Types
|
|
62
|
+
export type {
|
|
63
|
+
Config,
|
|
64
|
+
ConfigValue,
|
|
65
|
+
DirectoryMsg,
|
|
66
|
+
ExtractorClass,
|
|
67
|
+
HttpClient,
|
|
68
|
+
HttpResponse,
|
|
69
|
+
Message,
|
|
70
|
+
Metadata,
|
|
71
|
+
QueueMsg,
|
|
72
|
+
RequestConfig,
|
|
73
|
+
Storage,
|
|
74
|
+
UrlMsg,
|
|
75
|
+
} from './types'
|
|
76
|
+
|
|
77
|
+
// Utils
|
|
78
|
+
export { idFromShortcode, shortcodeFromId } from './utils/id-codec'
|
|
79
|
+
export {
|
|
80
|
+
ensureHttpScheme,
|
|
81
|
+
extr,
|
|
82
|
+
extract,
|
|
83
|
+
findTags,
|
|
84
|
+
nameExtFromURL,
|
|
85
|
+
parseInt,
|
|
86
|
+
parseUnicodeEscapes,
|
|
87
|
+
unescape,
|
|
88
|
+
unquote,
|
|
89
|
+
} from './utils/text'
|
|
90
|
+
|
|
91
|
+
/** Options for the Node.js convenience factory. */
|
|
92
|
+
export interface CreateSDKOptions {
|
|
93
|
+
/**
|
|
94
|
+
* Full browser Cookie header string.
|
|
95
|
+
* Copy from DevTools → Network → Request Headers → Cookie.
|
|
96
|
+
* Auto-extracts csrftoken for X-CSRFToken header.
|
|
97
|
+
*
|
|
98
|
+
* Either ``cookies`` or ``http`` must be provided.
|
|
99
|
+
*/
|
|
100
|
+
cookies?: string
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Custom HttpClient implementation.
|
|
104
|
+
* If omitted, a Node.js axios-based client is created from ``cookies``.
|
|
105
|
+
*/
|
|
106
|
+
http?: HttpClient
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Custom Storage implementation for file output.
|
|
110
|
+
* Defaults to Node.js fs/promises-based storage.
|
|
111
|
+
*/
|
|
112
|
+
storage?: Storage
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Logger instance. Defaults to a silent no-op logger.
|
|
116
|
+
*/
|
|
117
|
+
log?: Logger
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Create an SDK instance with Node.js defaults.
|
|
122
|
+
*
|
|
123
|
+
* When ``cookies`` is provided, auto-creates an axios-based HttpClient
|
|
124
|
+
* with CSRF token extraction. Pass ``http`` directly for custom adapters.
|
|
125
|
+
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { createSDK } from '@chilfish/gallery-dl-instagram'
|
|
128
|
+
*
|
|
129
|
+
* // Node.js with cookies
|
|
130
|
+
* const ig = await createSDK({ cookies: 'ds_user_id=...; sessionid=...' })
|
|
131
|
+
*
|
|
132
|
+
* // Custom http adapter (browser / Deno / Edge)
|
|
133
|
+
* const ig = await createSDK({ http: myHttpClient, storage: myStorage })
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export async function createSDK(opts: CreateSDKOptions = {}): Promise<import('./sdk').InstagramSDK> {
|
|
137
|
+
const { InstagramSDK } = await import('./sdk')
|
|
138
|
+
const log = opts.log ?? noopLogger
|
|
139
|
+
const storage = opts.storage ?? createStorage()
|
|
140
|
+
|
|
141
|
+
let http: HttpClient
|
|
142
|
+
let csrfToken = ''
|
|
143
|
+
|
|
144
|
+
if (opts.http) {
|
|
145
|
+
http = opts.http
|
|
146
|
+
}
|
|
147
|
+
else if (opts.cookies) {
|
|
148
|
+
csrfToken = extractCsrfFromCookies(opts.cookies)
|
|
149
|
+
http = createHttpClient(undefined, opts.cookies, log)
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
throw new Error(
|
|
153
|
+
'Either "cookies" or "http" must be provided. '
|
|
154
|
+
+ 'Get cookies from browser DevTools → Application → Cookies → instagram.com',
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return new InstagramSDK({ http, storage, log, csrfToken })
|
|
159
|
+
}
|