@chilfish/gallery-dl-instagram 0.2.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,2 +1,154 @@
1
- import { A as directory, C as nameExtFromURL, D as unquote, E as unescape, F as PrintJob, I as Extractor, L as noopLogger, M as url, N as DownloadJob, O as idFromShortcode, P as Job, R as ConfigManager, S as findTags, T as parseUnicodeEscapes, _ as parsePostRest, a as InstagramPostExtractor, b as extr, c as InstagramSavedExtractor, d as InstagramTaggedExtractor, f as InstagramUserExtractor, g as parsePostGraphql, h as extractTaggedUsers, i as InstagramInfoExtractor, j as queue, k as shortcodeFromId, l as InstagramStoriesExtractor, m as extractAudio, n as InstagramAvatarExtractor, o as InstagramPostsExtractor, p as InstagramExtractor, r as InstagramHighlightsExtractor, s as InstagramReelsExtractor, t as InstagramSDK, u as InstagramTagExtractor, v as InstagramRestAPI, w as parseInt, x as extract, y as ensureHttpScheme } from "./sdk-Bn0VCUIT.mjs";
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
+ };
153
+ //#endregion
2
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 CHANGED
@@ -1,10 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_sdk = require("./sdk-nzhAxf1O.cjs");
2
+ const require_sdk = require("./sdk-BClg0Kv2.cjs");
3
3
  //#region src/node-factory.ts
4
4
  /**
5
5
  * Create an SDK instance with Node.js defaults.
6
6
  *
7
- * When ``cookies`` is provided, auto-creates an axios-based HttpClient
7
+ * When ``cookies`` is provided, auto-creates a native-fetch HttpClient
8
8
  * with CSRF token extraction. Pass ``http`` directly for custom adapters.
9
9
  *
10
10
  * ```ts
@@ -19,19 +19,17 @@ const require_sdk = require("./sdk-nzhAxf1O.cjs");
19
19
  */
20
20
  async function createSDK(opts = {}) {
21
21
  const log = opts.log ?? require_sdk.noopLogger;
22
- let http;
22
+ let http = opts.http;
23
23
  let storage = opts.storage;
24
24
  let csrfToken = "";
25
- if (opts.http) http = opts.http;
26
- else if (opts.cookies) {
27
- const { createHttpClient, extractCsrfFromCookies } = await Promise.resolve().then(() => require("./adapter-CFsiiEpM.cjs"));
28
- csrfToken = extractCsrfFromCookies(opts.cookies);
29
- http = createHttpClient(void 0, opts.cookies, log);
25
+ if (!http && opts.cookies) {
26
+ csrfToken = require_sdk.extractCsrf(opts.cookies);
27
+ http = require_sdk.createFetchHttpClient({ cookie: opts.cookies });
30
28
  if (!storage) {
31
29
  const { createStorage } = await Promise.resolve().then(() => require("./storage-BwGaT6XO.cjs"));
32
30
  storage = createStorage();
33
31
  }
34
- } else throw new Error("Either \"cookies\" or \"http\" must be provided. Get cookies from browser DevTools → Application → Cookies → instagram.com");
32
+ }
35
33
  return new require_sdk.InstagramSDK({
36
34
  http,
37
35
  storage,
package/dist/node.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { b as Storage, n as InstagramSDK, o as Logger, p as HttpClient } from "./sdk-CK9x5wFL.cjs";
1
+ import { b as Storage, n as InstagramSDK, o as Logger, p as HttpClient } from "./sdk-DyZz22bT.cjs";
2
2
 
3
3
  //#region src/node-factory.d.ts
4
4
  /** Options for the Node.js convenience factory. */
@@ -13,7 +13,7 @@ interface CreateSDKOptions {
13
13
  cookies?: string;
14
14
  /**
15
15
  * Custom HttpClient implementation.
16
- * If omitted, a Node.js axios-based client is created from ``cookies``.
16
+ * If omitted, a Node.js native-fetch client is created from ``cookies``.
17
17
  */
18
18
  http?: HttpClient;
19
19
  /**
@@ -29,7 +29,7 @@ interface CreateSDKOptions {
29
29
  /**
30
30
  * Create an SDK instance with Node.js defaults.
31
31
  *
32
- * When ``cookies`` is provided, auto-creates an axios-based HttpClient
32
+ * When ``cookies`` is provided, auto-creates a native-fetch HttpClient
33
33
  * with CSRF token extraction. Pass ``http`` directly for custom adapters.
34
34
  *
35
35
  * ```ts
package/dist/node.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { b as Storage, n as InstagramSDK, o as Logger, p as HttpClient } from "./sdk-CK9x5wFL.mjs";
1
+ import { b as Storage, n as InstagramSDK, o as Logger, p as HttpClient } from "./sdk-DyZz22bT.mjs";
2
2
 
3
3
  //#region src/node-factory.d.ts
4
4
  /** Options for the Node.js convenience factory. */
@@ -13,7 +13,7 @@ interface CreateSDKOptions {
13
13
  cookies?: string;
14
14
  /**
15
15
  * Custom HttpClient implementation.
16
- * If omitted, a Node.js axios-based client is created from ``cookies``.
16
+ * If omitted, a Node.js native-fetch client is created from ``cookies``.
17
17
  */
18
18
  http?: HttpClient;
19
19
  /**
@@ -29,7 +29,7 @@ interface CreateSDKOptions {
29
29
  /**
30
30
  * Create an SDK instance with Node.js defaults.
31
31
  *
32
- * When ``cookies`` is provided, auto-creates an axios-based HttpClient
32
+ * When ``cookies`` is provided, auto-creates a native-fetch HttpClient
33
33
  * with CSRF token extraction. Pass ``http`` directly for custom adapters.
34
34
  *
35
35
  * ```ts
package/dist/node.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import { L as noopLogger, t as InstagramSDK } from "./sdk-Bn0VCUIT.mjs";
1
+ import { I as noopLogger, n as createFetchHttpClient, r as extractCsrf, t as InstagramSDK } from "./sdk-CovBsEps.mjs";
2
2
  //#region src/node-factory.ts
3
3
  /**
4
4
  * Create an SDK instance with Node.js defaults.
5
5
  *
6
- * When ``cookies`` is provided, auto-creates an axios-based HttpClient
6
+ * When ``cookies`` is provided, auto-creates a native-fetch HttpClient
7
7
  * with CSRF token extraction. Pass ``http`` directly for custom adapters.
8
8
  *
9
9
  * ```ts
@@ -18,19 +18,17 @@ import { L as noopLogger, t as InstagramSDK } from "./sdk-Bn0VCUIT.mjs";
18
18
  */
19
19
  async function createSDK(opts = {}) {
20
20
  const log = opts.log ?? noopLogger;
21
- let http;
21
+ let http = opts.http;
22
22
  let storage = opts.storage;
23
23
  let csrfToken = "";
24
- if (opts.http) http = opts.http;
25
- else if (opts.cookies) {
26
- const { createHttpClient, extractCsrfFromCookies } = await import("./adapter-tSleX8Cr.mjs");
27
- csrfToken = extractCsrfFromCookies(opts.cookies);
28
- http = createHttpClient(void 0, opts.cookies, log);
24
+ if (!http && opts.cookies) {
25
+ csrfToken = extractCsrf(opts.cookies);
26
+ http = createFetchHttpClient({ cookie: opts.cookies });
29
27
  if (!storage) {
30
28
  const { createStorage } = await import("./storage-77hqz5Fi.mjs");
31
29
  storage = createStorage();
32
30
  }
33
- } else throw new Error("Either \"cookies\" or \"http\" must be provided. Get cookies from browser DevTools → Application → Cookies → instagram.com");
31
+ }
34
32
  return new InstagramSDK({
35
33
  http,
36
34
  storage,