downloaderjavascript195
Instagram Media & Reels Downloader (Pure Node.js)
Engine scraper Instagram Reels, Video, Foto, dan Carousel (Multiple Slides) berbasis 100% Pure Node.js GraphQL query. Base URL discrape: https://www.instagram.com/graphql/query | Website: https://vamxapi.my.id | Saluran WhatsApp: https://whatsapp.com/channel/0029Vb8n36OGE56uvRAq4y3y
Vamz Spectre29 Sep 2026251 baris kode
Jalankan via Terminal / CLI:
# 1. Download file script
curl -sL "https://code.vamxapi.my.id/snippet/raw/igexport-instagram-downloader" -o igexport-instagram-downloader.js
# 2. Jalankan script
node igexport-instagram-downloader.js
Dependencies npm yang Dibutuhkan:
npm install axiosPanduan Penggunaan:
/**
* Base URL Discrape : https://www.instagram.com/graphql/query
* Official Website : https://vamxapi.my.id
* WhatsApp Channel : https://whatsapp.com/channel/0029Vb8n36OGE56uvRAq4y3y
*/
// Instalasi Dependencies:
npm install axios
// Penggunaan CLI:
node igexport-instagram-downloader.js "https://www.instagram.com/reel/DdL4EZcu7Aw/"
// Penggunaan Modular (Node.js / Express / Next.js):
const { extractInstagramMedia, downloadFile } = require(./igexport-instagram-downloader);
async function main() {
const result = await extractInstagramMedia("https://www.instagram.com/reel/DdL4EZcu7Aw/");
console.log("Metadata:", result.metadata);
console.log("Download URLs:", result.downloadUrl);
}
main();igexport-instagram-downloader.js(251 lines)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/usr/bin/env node
/**
* =====================================================================
* Instagram Media & Reels Downloader (Pure Node.js)
* High-performance direct extractor using native Instagram GraphQL doc_id
* Supports: Reels, Videos, Photos, and Carousels (Sidecars)
*
* Base URL Discrape : https://www.instagram.com/graphql/query
* Official Website : https://vamxapi.my.id
* WhatsApp Channel : https://whatsapp.com/channel/0029Vb8n36OGE56uvRAq4y3y
* Author : Vamz Spectre / Vamx
* =====================================================================
*/
const fs = require("fs");
const path = require("path");
const https = require("https");
const http = require("http");
const axios = require("axios");
let sessionCache = null;
async function getInstagramSession() {
const now = Date.now();
if (sessionCache && sessionCache.expiresAt > now && sessionCache.csrf) {
return { csrf: sessionCache.csrf, cookies: sessionCache.cookies };
}
const userAgent =
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36";
const homeRes = await axios.get("https://www.instagram.com/", {
headers: {
"User-Agent": userAgent,
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.8",
},
timeout: 10000,
validateStatus: () => true,
maxRedirects: 0,
});
const rawCookies = homeRes.headers["set-cookie"] || [];
const cookieStr = rawCookies.map((c) => c.split(";")[0]).join("; ");
const csrfMatch = cookieStr.match(/csrftoken=([^;]+)/);
const csrf = csrfMatch ? csrfMatch[1] : "";
sessionCache = {
csrf,
cookies: cookieStr,
expiresAt: now + 20 * 60 * 1000,
};
return { csrf, cookies: cookieStr };
}
function extractShortcode(url) {
const match = url.match(/(?:p|reel|reels)\/([A-Za-z0-9_-]+)/);
if (match) return match[1];
const parts = url.split("?")[0].replace(/\/+$/, "").split("/");
return parts[parts.length - 1] || null;
}
async function extractInstagramMedia(url) {
try {
const shortcode = extractShortcode(url);
if (!shortcode) {
return { status: false, message: "Shortcode Instagram tidak valid" };
}
let { csrf, cookies } = await getInstagramSession();
const userAgent =
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36";
const fetchItem = async (currentCsrf, currentCookies) => {
const payload = new URLSearchParams({
variables: JSON.stringify({
shortcode,
__relay_internal__pv__PolarisAIGMMediaWebLabelEnabledrelayprovider: false,
}),
doc_id: "27128499623469141",
server_timestamps: "true",
});
return axios.post("https://www.instagram.com/graphql/query", payload.toString(), {
headers: {
"User-Agent": userAgent,
Accept: "*/*",
"Accept-Language": "en-US,en;q=0.8",
"Content-Type": "application/x-www-form-urlencoded",
"X-CSRFToken": currentCsrf,
"X-IG-App-ID": "936619743392459",
Cookie: currentCookies,
Referer: `https://www.instagram.com/p/${shortcode}/`,
},
timeout: 15000,
validateStatus: () => true,
});
};
let res = await fetchItem(csrf, cookies);
if (res.status !== 200 || !res.data?.data) {
sessionCache = null;
const refreshed = await getInstagramSession();
csrf = refreshed.csrf;
cookies = refreshed.cookies;
res = await fetchItem(csrf, cookies);
}
const items = res.data?.data?.xdt_api__v1__media__shortcode__web_info?.items;
if (!items || !items.length) {
return { status: false, message: "Media tidak ditemukan atau akun privat." };
}
const item = items[0];
const downloadUrls = [];
// Carousel (Multiple Media)
if (Array.isArray(item.carousel_media) && item.carousel_media.length > 0) {
for (const sub of item.carousel_media) {
if (sub.video_versions && sub.video_versions.length > 0) {
downloadUrls.push(sub.video_versions[0].url);
} else if (sub.image_versions2?.candidates?.[0]?.url) {
downloadUrls.push(sub.image_versions2.candidates[0].url);
}
}
} else {
if (item.video_versions && item.video_versions.length > 0) {
downloadUrls.push(item.video_versions[0].url);
} else if (item.image_versions2?.candidates?.[0]?.url) {
downloadUrls.push(item.image_versions2.candidates[0].url);
}
}
const uniqueUrls = [...new Set(downloadUrls)];
if (uniqueUrls.length === 0) {
return { status: false, message: "Link download media Instagram tidak ditemukan." };
}
return {
status: true,
creator: "vamxapi",
website: "https://vamxapi.my.id",
channel: "https://whatsapp.com/channel/0029Vb8n36OGE56uvRAq4y3y",
source: "instagram-native",
metadata: {
username: item.user?.username || "-",
full_name: item.user?.full_name || "",
caption: item.caption?.text || "",
thumbnail: item.image_versions2?.candidates?.[0]?.url || null,
likes: item.like_count ?? 0,
comments: item.comment_count ?? 0,
is_video: !!item.video_versions,
},
downloadUrl: uniqueUrls,
};
} catch (err) {
return {
status: false,
message: err.message || "Gagal mengekstrak media Instagram.",
};
}
}
function downloadFile(fileUrl, outputPath) {
return new Promise((resolve, reject) => {
const client = fileUrl.startsWith("https") ? https : http;
const req = client.get(
fileUrl,
{
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
Referer: "https://www.instagram.com/",
},
},
(res) => {
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
return downloadFile(res.headers.location, outputPath).then(resolve).catch(reject);
}
if (res.statusCode !== 200) {
return reject(new Error(`Download gagal dengan status HTTP ${res.statusCode}`));
}
const totalBytes = parseInt(res.headers["content-length"] || "0", 10);
let downloadedBytes = 0;
const fileStream = fs.createWriteStream(outputPath);
res.on("data", (chunk) => {
downloadedBytes += chunk.length;
if (totalBytes > 0) {
const pct = ((downloadedBytes / totalBytes) * 100).toFixed(1);
process.stdout.write(`\r📥 Mengunduh: ${pct}% (${(downloadedBytes / 1024 / 1024).toFixed(2)} MB / ${(totalBytes / 1024 / 1024).toFixed(2)} MB)`);
}
});
res.pipe(fileStream);
fileStream.on("finish", () => {
fileStream.close();
console.log(`\n✅ Media berhasil disimpan ke: ${outputPath}`);
resolve({ path: outputPath, size: downloadedBytes });
});
fileStream.on("error", (err) => {
fs.unlink(outputPath, () => {});
reject(err);
});
}
);
req.on("error", reject);
});
}
async function main() {
const targetUrl = process.argv[2] || "https://www.instagram.com/reel/DdL4EZcu7Aw/";
console.log(`🔍 Memproses Instagram URL: ${targetUrl}`);
const data = await extractInstagramMedia(targetUrl);
console.log("\n[Instagram Extractor] Result:", JSON.stringify(data, null, 2));
if (data.status && Array.isArray(data.downloadUrl) && data.downloadUrl.length > 0) {
const firstUrl = data.downloadUrl[0];
const isVideo = data.metadata?.is_video !== false;
const ext = isVideo ? "mp4" : "jpg";
const outputFile = path.join(process.cwd(), `instagram_${Date.now()}.${ext}`);
console.log(`\n⏳ Mengunduh file media (${ext.toUpperCase()})...`);
try {
await downloadFile(firstUrl, outputFile);
} catch (err) {
console.error("\n❌ Gagal mengunduh file:", err.message);
}
} else {
console.error("\n❌ Tidak ada link download yang dapat diunduh.");
}
}
if (require.main === module) {
main();
}
if (typeof module !== "undefined" && module.exports) {
module.exports = {
extractInstagramMedia,
downloadFile,
};
}