@chilfish/gallery-dl-instagram 0.1.0 → 0.2.2

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.mjs CHANGED
@@ -1,40 +1,154 @@
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
- }
1
+ import { A as directory, B as _YELLOW, C as extract, D as parseUnicodeEscapes, E as parseInt, F as Extractor, G as pad, H as c, I as noopLogger, K as ConfigManager, L as DownloadJob, M as url, N as idFromShortcode, O as unescape, P as shortcodeFromId, R as Job, S as extr, T as nameExtFromURL, U as dim, V as b, W as g, _ as extractAudio, a as InstagramTaggedExtractor, b as InstagramRestAPI, c as InstagramSavedExtractor, d as InstagramPostExtractor, f as InstagramInfoExtractor, g as parsePostGraphql, h as InstagramExtractor, i as InstagramUserExtractor, j as queue, k as unquote, l as InstagramReelsExtractor, m as InstagramAvatarExtractor, o as InstagramTagExtractor, p as InstagramHighlightsExtractor, s as InstagramStoriesExtractor, t as InstagramSDK, u as InstagramPostsExtractor, v as extractTaggedUsers, w as findTags, x as ensureHttpScheme, y as parsePostRest, z as _RESET } from "./sdk-CovBsEps.mjs";
2
+ //#region src/core/print-job.ts
3
+ var PrintJob = class PrintJob extends Job {
4
+ _currentDir = {};
5
+ _files = [];
6
+ _postCount = 0;
7
+ _fileCount = 0;
8
+ _width;
9
+ constructor(extractor) {
10
+ super(extractor);
11
+ this._width = Math.min(process.stdout.columns ?? 80, 100);
12
+ }
13
+ async handleDirectory(msg) {
14
+ if (this._postCount > 0) this._flushPost();
15
+ this._currentDir = { ...msg.metadata };
16
+ this._postCount++;
17
+ this._files = [];
18
+ }
19
+ async handleUrl(msg) {
20
+ const meta = {
21
+ ...this._currentDir,
22
+ ...msg.metadata
23
+ };
24
+ this._fileCount++;
25
+ const ext = meta.extension ?? "jpg";
26
+ const mid = meta.media_id ?? "?";
27
+ this._files.push({
28
+ num: meta.num ?? this._files.length + 1,
29
+ filename: `${mid}.${ext}`,
30
+ width: meta.width ?? 0,
31
+ height: meta.height ?? 0,
32
+ videoUrl: meta.video_url ?? null,
33
+ audioUrl: meta.audio_url ?? null
34
+ });
35
+ }
36
+ async handleQueue(msg) {
37
+ if (this._files.length > 0 || this._postCount > 0) this._flushPost();
38
+ this._postCount = 0;
39
+ this._files = [];
40
+ const extrClass = {
41
+ ...this._currentDir,
42
+ ...msg.metadata
43
+ }._extractor;
44
+ if (!extrClass || typeof extrClass !== "object") return;
45
+ const cls = extrClass;
46
+ const match = cls.pattern.exec(msg.url);
47
+ if (!match) return;
48
+ const parentExtr = this.extractor;
49
+ const childJob = new PrintJob(Reflect.construct(cls, [{
50
+ url: msg.url,
51
+ match,
52
+ config: parentExtr.config,
53
+ http: parentExtr.http,
54
+ storage: parentExtr.storage,
55
+ log: parentExtr.log
56
+ }]));
57
+ const childStatus = await childJob.run();
58
+ this.status |= childStatus;
59
+ this._postCount += childJob._postCount;
60
+ this._fileCount += childJob._fileCount;
61
+ }
62
+ _flushPost() {
63
+ const m = this._currentDir;
64
+ if (Object.keys(m).length === 0) return;
65
+ const w = this._width;
66
+ const labelW = 14;
67
+ const shortcode = m.post_shortcode ?? "?";
68
+ const header = ` Post #${this._postCount}: ${shortcode} `;
69
+ const padTotal = w - 2 - header.length;
70
+ const padL = Math.floor(padTotal / 2);
71
+ const padR = padTotal - padL;
72
+ process.stdout.write(`\n${dim("┌")}${"─".repeat(padL)}${b(header)}${"─".repeat(padR)}${dim("┐")}\n`);
73
+ const row = (label, value, color) => {
74
+ const colored = typeof color === "function" ? color(value) : color ? `${color}${value}${_RESET}` : value;
75
+ process.stdout.write(` ${dim("│")} ${c(pad(label, labelW))} ${colored}\n`);
76
+ };
77
+ const username = m.username ?? "?";
78
+ const fullname = m.fullname ?? "";
79
+ row("Author:", fullname ? `${username} (${fullname})` : username, g);
80
+ row("Date:", m.date ?? m.post_date ?? "?");
81
+ row("Likes:", `${typeof m.likes === "number" ? m.likes.toLocaleString() : "?"} | Liked: ${m.liked ? "yes" : "no"}`);
82
+ row("Type:", `${m.type ?? "?"} (${this._files.length} files)`);
83
+ row("URL:", m.post_url ?? "?");
84
+ const desc = m.description ?? "";
85
+ if (desc) {
86
+ process.stdout.write(` ${dim("│")}\n`);
87
+ process.stdout.write(` ${dim("│")} ${b("Description:")}\n`);
88
+ for (const line of desc.split("\n")) for (const wl of this._wrap(line, w - 8)) process.stdout.write(` ${dim("│")} ${dim(wl)}\n`);
89
+ }
90
+ const tags = m.tags;
91
+ if (tags && tags.length > 0) {
92
+ process.stdout.write(` ${dim("│")}\n`);
93
+ process.stdout.write(` ${dim("│")} ${b("Tags:")} ${dim(tags.map((t) => `#${t}`).join(" "))}\n`);
94
+ }
95
+ const locName = m.location_slug ?? "";
96
+ const locId = m.location_id ?? "";
97
+ if (locName || locId) row("Location:", locId ? `${locName} (ID: ${locId})` : locName);
98
+ const coauthors = m.coauthors;
99
+ if (coauthors && coauthors.length > 0) row("Co-authors:", coauthors.map((c) => c.full_name ? `${c.username} (${c.full_name})` : c.username).join(", "));
100
+ const pinned = m.pinned;
101
+ if (pinned && pinned.length > 0) row("Pinned:", pinned.join(", "));
102
+ const expires = m.expires;
103
+ if (expires) row("Expires:", expires, _YELLOW);
104
+ const hlTitle = m.highlight_title;
105
+ if (hlTitle) row("Highlight:", hlTitle);
106
+ const taggedUser = m.tagged_username ?? "";
107
+ if (taggedUser) {
108
+ const taggedFull = m.tagged_full_name ?? "";
109
+ row("Tagged by:", taggedFull ? `${taggedUser} (${taggedFull})` : taggedUser);
110
+ }
111
+ if (this._files.length > 0) {
112
+ process.stdout.write(` ${dim("│")}\n`);
113
+ process.stdout.write(` ${dim("│")} ${b(`Media (${this._files.length} files):`)}\n`);
114
+ const maxNumW = String(this._files.length).length;
115
+ const maxFileW = Math.max(...this._files.map((f) => f.filename.length));
116
+ const dimW = Math.min(maxFileW, 40);
117
+ for (const f of this._files) {
118
+ const numStr = `[${String(f.num).padStart(maxNumW)}]`;
119
+ const dimStr = f.filename.length > 40 ? `${f.filename.slice(0, 37)}...` : pad(f.filename, dimW);
120
+ const res = f.width ? `${f.width}x${f.height}` : "?x?";
121
+ const badges = [];
122
+ if (f.videoUrl) badges.push("video");
123
+ if (f.audioUrl) badges.push("audio");
124
+ let line = ` ${dim("│")} ${g(numStr)} ${dimStr} ${res}`;
125
+ if (badges.length > 0) line += ` ${_YELLOW}(${badges.join("+")})${_RESET}`;
126
+ process.stdout.write(`${line}\n`);
127
+ }
128
+ }
129
+ process.stdout.write(` ${dim("└")}${"─".repeat(w - 2)}${dim("┘")}\n`);
130
+ }
131
+ _wrap(text, maxLen) {
132
+ if (text.length <= maxLen) return [text];
133
+ const lines = [];
134
+ let remaining = text;
135
+ while (remaining.length > maxLen) {
136
+ let cut = maxLen;
137
+ while (cut > 0 && remaining[cut] !== " ") cut--;
138
+ if (cut === 0) cut = maxLen;
139
+ lines.push(remaining.slice(0, cut).trimEnd());
140
+ remaining = remaining.slice(cut).trimStart();
141
+ }
142
+ if (remaining) lines.push(remaining);
143
+ return lines;
144
+ }
145
+ _report() {
146
+ this._flushPost();
147
+ process.stdout.write(`\n${dim("──")} ${b("Summary")} ${dim("───")}\n`);
148
+ process.stdout.write(` Posts: ${g(String(this._postCount))}\n`);
149
+ process.stdout.write(` Files: ${g(String(this._fileCount))}\n`);
150
+ process.stdout.write(`\n`);
151
+ }
152
+ };
39
153
  //#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 };
154
+ export { ConfigManager, DownloadJob, Extractor, InstagramAvatarExtractor, InstagramExtractor, InstagramHighlightsExtractor, InstagramInfoExtractor, InstagramPostExtractor, InstagramPostsExtractor, InstagramReelsExtractor, InstagramRestAPI, InstagramSDK, InstagramSavedExtractor, InstagramStoriesExtractor, InstagramTagExtractor, InstagramTaggedExtractor, InstagramUserExtractor, Job, PrintJob, directory, ensureHttpScheme, extr, extract, extractAudio, extractTaggedUsers, findTags, idFromShortcode, nameExtFromURL, noopLogger, parseInt, parsePostGraphql, parsePostRest, parseUnicodeEscapes, queue, shortcodeFromId, unescape, unquote, url };
package/dist/node.cjs ADDED
@@ -0,0 +1,41 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sdk = require("./sdk-BClg0Kv2.cjs");
3
+ //#region src/node-factory.ts
4
+ /**
5
+ * Create an SDK instance with Node.js defaults.
6
+ *
7
+ * When ``cookies`` is provided, auto-creates a native-fetch HttpClient
8
+ * with CSRF token extraction. Pass ``http`` directly for custom adapters.
9
+ *
10
+ * ```ts
11
+ * import { createSDK } from '@chilfish/gallery-dl-instagram/node'
12
+ *
13
+ * // Node.js with cookies
14
+ * const ig = await createSDK({ cookies: 'ds_user_id=...; sessionid=...' })
15
+ *
16
+ * // Custom http adapter (browser / Deno / Edge)
17
+ * const ig = await createSDK({ http: myHttpClient, storage: myStorage })
18
+ * ```
19
+ */
20
+ async function createSDK(opts = {}) {
21
+ const log = opts.log ?? require_sdk.noopLogger;
22
+ let http = opts.http;
23
+ let storage = opts.storage;
24
+ let csrfToken = "";
25
+ if (!http && opts.cookies) {
26
+ csrfToken = require_sdk.extractCsrf(opts.cookies);
27
+ http = require_sdk.createFetchHttpClient({ cookie: opts.cookies });
28
+ if (!storage) {
29
+ const { createStorage } = await Promise.resolve().then(() => require("./storage-BwGaT6XO.cjs"));
30
+ storage = createStorage();
31
+ }
32
+ }
33
+ return new require_sdk.InstagramSDK({
34
+ http,
35
+ storage,
36
+ log,
37
+ csrfToken
38
+ });
39
+ }
40
+ //#endregion
41
+ exports.createSDK = createSDK;
@@ -0,0 +1,47 @@
1
+ import { b as Storage, n as InstagramSDK, o as Logger, p as HttpClient } from "./sdk-DyZz22bT.cjs";
2
+
3
+ //#region src/node-factory.d.ts
4
+ /** Options for the Node.js convenience factory. */
5
+ interface CreateSDKOptions {
6
+ /**
7
+ * Full browser Cookie header string.
8
+ * Copy from DevTools → Network → Request Headers → Cookie.
9
+ * Auto-extracts csrftoken for X-CSRFToken header.
10
+ *
11
+ * Either ``cookies`` or ``http`` must be provided.
12
+ */
13
+ cookies?: string;
14
+ /**
15
+ * Custom HttpClient implementation.
16
+ * If omitted, a Node.js native-fetch client is created from ``cookies``.
17
+ */
18
+ http?: HttpClient;
19
+ /**
20
+ * Custom Storage implementation for file output.
21
+ * Defaults to Node.js fs/promises-based storage.
22
+ */
23
+ storage?: Storage;
24
+ /**
25
+ * Logger instance. Defaults to a silent no-op logger.
26
+ */
27
+ log?: Logger;
28
+ }
29
+ /**
30
+ * Create an SDK instance with Node.js defaults.
31
+ *
32
+ * When ``cookies`` is provided, auto-creates a native-fetch HttpClient
33
+ * with CSRF token extraction. Pass ``http`` directly for custom adapters.
34
+ *
35
+ * ```ts
36
+ * import { createSDK } from '@chilfish/gallery-dl-instagram/node'
37
+ *
38
+ * // Node.js with cookies
39
+ * const ig = await createSDK({ cookies: 'ds_user_id=...; sessionid=...' })
40
+ *
41
+ * // Custom http adapter (browser / Deno / Edge)
42
+ * const ig = await createSDK({ http: myHttpClient, storage: myStorage })
43
+ * ```
44
+ */
45
+ declare function createSDK(opts?: CreateSDKOptions): Promise<InstagramSDK>;
46
+ //#endregion
47
+ export { type CreateSDKOptions, createSDK };
@@ -0,0 +1,47 @@
1
+ import { b as Storage, n as InstagramSDK, o as Logger, p as HttpClient } from "./sdk-DyZz22bT.mjs";
2
+
3
+ //#region src/node-factory.d.ts
4
+ /** Options for the Node.js convenience factory. */
5
+ interface CreateSDKOptions {
6
+ /**
7
+ * Full browser Cookie header string.
8
+ * Copy from DevTools → Network → Request Headers → Cookie.
9
+ * Auto-extracts csrftoken for X-CSRFToken header.
10
+ *
11
+ * Either ``cookies`` or ``http`` must be provided.
12
+ */
13
+ cookies?: string;
14
+ /**
15
+ * Custom HttpClient implementation.
16
+ * If omitted, a Node.js native-fetch client is created from ``cookies``.
17
+ */
18
+ http?: HttpClient;
19
+ /**
20
+ * Custom Storage implementation for file output.
21
+ * Defaults to Node.js fs/promises-based storage.
22
+ */
23
+ storage?: Storage;
24
+ /**
25
+ * Logger instance. Defaults to a silent no-op logger.
26
+ */
27
+ log?: Logger;
28
+ }
29
+ /**
30
+ * Create an SDK instance with Node.js defaults.
31
+ *
32
+ * When ``cookies`` is provided, auto-creates a native-fetch HttpClient
33
+ * with CSRF token extraction. Pass ``http`` directly for custom adapters.
34
+ *
35
+ * ```ts
36
+ * import { createSDK } from '@chilfish/gallery-dl-instagram/node'
37
+ *
38
+ * // Node.js with cookies
39
+ * const ig = await createSDK({ cookies: 'ds_user_id=...; sessionid=...' })
40
+ *
41
+ * // Custom http adapter (browser / Deno / Edge)
42
+ * const ig = await createSDK({ http: myHttpClient, storage: myStorage })
43
+ * ```
44
+ */
45
+ declare function createSDK(opts?: CreateSDKOptions): Promise<InstagramSDK>;
46
+ //#endregion
47
+ export { type CreateSDKOptions, createSDK };
package/dist/node.mjs ADDED
@@ -0,0 +1,40 @@
1
+ import { I as noopLogger, n as createFetchHttpClient, r as extractCsrf, t as InstagramSDK } from "./sdk-CovBsEps.mjs";
2
+ //#region src/node-factory.ts
3
+ /**
4
+ * Create an SDK instance with Node.js defaults.
5
+ *
6
+ * When ``cookies`` is provided, auto-creates a native-fetch HttpClient
7
+ * with CSRF token extraction. Pass ``http`` directly for custom adapters.
8
+ *
9
+ * ```ts
10
+ * import { createSDK } from '@chilfish/gallery-dl-instagram/node'
11
+ *
12
+ * // Node.js with cookies
13
+ * const ig = await createSDK({ cookies: 'ds_user_id=...; sessionid=...' })
14
+ *
15
+ * // Custom http adapter (browser / Deno / Edge)
16
+ * const ig = await createSDK({ http: myHttpClient, storage: myStorage })
17
+ * ```
18
+ */
19
+ async function createSDK(opts = {}) {
20
+ const log = opts.log ?? noopLogger;
21
+ let http = opts.http;
22
+ let storage = opts.storage;
23
+ let csrfToken = "";
24
+ if (!http && opts.cookies) {
25
+ csrfToken = extractCsrf(opts.cookies);
26
+ http = createFetchHttpClient({ cookie: opts.cookies });
27
+ if (!storage) {
28
+ const { createStorage } = await import("./storage-77hqz5Fi.mjs");
29
+ storage = createStorage();
30
+ }
31
+ }
32
+ return new InstagramSDK({
33
+ http,
34
+ storage,
35
+ log,
36
+ csrfToken
37
+ });
38
+ }
39
+ //#endregion
40
+ export { createSDK };