snapsave-media-downloader
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -1,2 +0,2 @@ | ||
export declare const snapsave: (url: string) => Promise<{ | ||
declare const snapsave: (url: string) => Promise<{ | ||
status: boolean; | ||
@@ -10,2 +10,3 @@ data: any[]; | ||
}>; | ||
//# sourceMappingURL=index.d.ts.map | ||
export { snapsave }; |
@@ -1,119 +0,122 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
var __async = (__this, __arguments, generator) => { | ||
return new Promise((resolve, reject) => { | ||
var fulfilled = (value) => { | ||
try { | ||
step(generator.next(value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}; | ||
var rejected = (value) => { | ||
try { | ||
step(generator.throw(value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}; | ||
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); | ||
step((generator = generator.apply(__this, __arguments)).next()); | ||
}); | ||
}; | ||
import { ofetch } from "ofetch"; | ||
// src/index.ts | ||
import { load } from "cheerio"; | ||
export const snapsave = (url) => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const fbRegex = /(https|http):\/\/(?:(?:www\.facebook\.com\/(?:(?:(?:video\.php)||(?:watch\/))\?v=\d+|(?:[0-9a-zA-Z-_.]+\/(?:(?:video|(post))(?:s))\/)(?:[0-9a-zA-Z-_.]+(?:\/\d+)*)))|(?:fb\.watch\/(?:\w|-)+)|(?:www\.facebook\.com\/reel\/\d+)|(?:www\.facebook\.com\/share\/(v|r)\/[a-zA-Z0-9]+\/)\/?)/; | ||
const igRegex = /((?:https?:\/\/)?(?:www\.)?instagram\.com\/(?:p|reel|reels|tv|stories)\/([^/?#&]+)).*/g; | ||
if (!url.match(fbRegex) && !url.match(igRegex)) | ||
return { status: false, msg: "Link Url not valid" }; | ||
function decodeSnapApp(args) { | ||
let [h, u, n, t, e, r] = args; | ||
function decode(d, e, f) { | ||
const g = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/".split(""); | ||
const h = g.slice(0, e); | ||
const i = g.slice(0, f); | ||
let j = d.split("").reverse().reduce(function (a, b, c) { | ||
if (h.indexOf(b) !== -1) | ||
return a += h.indexOf(b) * (Math.pow(e, c)); | ||
}, 0); | ||
let k = ""; | ||
while (j > 0) { | ||
k = i[j % f] + k; | ||
j = (j - (j % f)) / f; | ||
} | ||
return k || "0"; | ||
} | ||
r = ""; | ||
for (let i = 0, len = h.length; i < len; i++) { | ||
let s = ""; | ||
while (h[i] !== n[e]) { | ||
s += h[i]; | ||
i++; | ||
} | ||
for (let j = 0; j < n.length; j++) | ||
s = s.replace(new RegExp(n[j], "g"), j.toString()); | ||
r += String.fromCharCode(decode(s, e, 10) - t); | ||
} | ||
return decodeURIComponent(encodeURIComponent(r)); | ||
var snapsave = (url) => __async(void 0, null, function* () { | ||
try { | ||
let decodeSnapApp = function(args) { | ||
let [h, u, n, t, e, r] = args; | ||
function decode2(d, e2, f) { | ||
const g = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/".split(""); | ||
const h2 = g.slice(0, e2); | ||
const i = g.slice(0, f); | ||
let j = d.split("").reverse().reduce(function(a, b, c) { | ||
if (h2.indexOf(b) !== -1) | ||
return a += h2.indexOf(b) * Math.pow(e2, c); | ||
}, 0); | ||
let k = ""; | ||
while (j > 0) { | ||
k = i[j % f] + k; | ||
j = (j - j % f) / f; | ||
} | ||
function getEncodedSnapApp(data) { | ||
return data.split("decodeURIComponent(escape(r))}(")[1] | ||
.split("))")[0] | ||
.split(",") | ||
.map(v => v.replace(/"/g, "").trim()); | ||
return k || "0"; | ||
} | ||
r = ""; | ||
for (let i = 0, len = h.length; i < len; i++) { | ||
let s = ""; | ||
while (h[i] !== n[e]) { | ||
s += h[i]; | ||
i++; | ||
} | ||
function getDecodedSnapSave(data) { | ||
return data.split("getElementById(\"download-section\").innerHTML = \"")[1] | ||
.split("\"; document.getElementById(\"inputData\").remove(); ")[0] | ||
.replace(/\\(\\)?/g, ""); | ||
for (let j = 0; j < n.length; j++) | ||
s = s.replace(new RegExp(n[j], "g"), j.toString()); | ||
r += String.fromCharCode(decode2(s, e, 10) - t); | ||
} | ||
return decodeURIComponent(encodeURIComponent(r)); | ||
}, getEncodedSnapApp = function(data) { | ||
return data.split("decodeURIComponent(escape(r))}(")[1].split("))")[0].split(",").map((v) => v.replace(/"/g, "").trim()); | ||
}, getDecodedSnapSave = function(data) { | ||
return data.split('getElementById("download-section").innerHTML = "')[1].split('"; document.getElementById("inputData").remove(); ')[0].replace(/\\(\\)?/g, ""); | ||
}, decryptSnapSave = function(data) { | ||
return getDecodedSnapSave(decodeSnapApp(getEncodedSnapApp(data))); | ||
}; | ||
const fbRegex = /(https|http):\/\/(?:(?:www\.facebook\.com\/(?:(?:(?:video\.php)||(?:watch\/))\?v=\d+|(?:[0-9a-zA-Z-_.]+\/(?:(?:video|(post))(?:s))\/)(?:[0-9a-zA-Z-_.]+(?:\/\d+)*)))|(?:fb\.watch\/(?:\w|-)+)|(?:www\.facebook\.com\/reel\/\d+)|(?:www\.facebook\.com\/share\/(v|r)\/[a-zA-Z0-9]+\/)\/?)/; | ||
const igRegex = /((?:https?:\/\/)?(?:www\.)?instagram\.com\/(?:p|reel|reels|tv|stories)\/([^/?#&]+)).*/g; | ||
if (!url.match(fbRegex) && !url.match(igRegex)) return { status: false, msg: "Link Url not valid" }; | ||
const formData = new URLSearchParams(); | ||
formData.append("url", url); | ||
const response = yield fetch("https://snapsave.app/action.php?lang=id", { | ||
method: "POST", | ||
headers: { | ||
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", | ||
"content-type": "application/x-www-form-urlencoded", | ||
"origin": "https://snapsave.app", | ||
"referer": "https://snapsave.app/id", | ||
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" | ||
}, | ||
body: formData | ||
}); | ||
const html = yield response.text(); | ||
const decode = decryptSnapSave(html); | ||
const $ = load(decode); | ||
const results = []; | ||
if ($("table.table").length || $("article.media > figure").length) { | ||
const thumbnail = $("article.media > figure").find("img").attr("src"); | ||
$("tbody > tr").each((_, el) => { | ||
var _a; | ||
const $el = $(el); | ||
const $td = $el.find("td"); | ||
const resolution = $td.eq(0).text(); | ||
let _url = $td.eq(2).find("a").attr("href") || $td.eq(2).find("button").attr("onclick"); | ||
const shouldRender = /get_progressApi/ig.test(_url || ""); | ||
if (shouldRender) { | ||
_url = ((_a = /get_progressApi\('(.*?)'\)/.exec(_url || "")) == null ? void 0 : _a[1]) || _url; | ||
} | ||
function decryptSnapSave(data) { | ||
return getDecodedSnapSave(decodeSnapApp(getEncodedSnapApp(data))); | ||
} | ||
const formData = new URLSearchParams(); | ||
formData.append("url", url); | ||
const html = yield ofetch("https://snapsave.app/action.php?lang=id", { | ||
method: "POST", | ||
headers: { | ||
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", | ||
"content-type": "application/x-www-form-urlencoded", | ||
"origin": "https://snapsave.app", | ||
"referer": "https://snapsave.app/id", | ||
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" | ||
}, | ||
body: formData | ||
}).catch((e) => e); | ||
const decode = decryptSnapSave(html); | ||
const $ = load(decode); | ||
const results = []; | ||
if ($("table.table").length || $("article.media > figure").length) { | ||
const thumbnail = $("article.media > figure").find("img").attr("src"); | ||
$("tbody > tr").each((_, el) => { | ||
var _a; | ||
const $el = $(el); | ||
const $td = $el.find("td"); | ||
const resolution = $td.eq(0).text(); | ||
let _url = $td.eq(2).find("a").attr("href") || $td.eq(2).find("button").attr("onclick"); | ||
const shouldRender = /get_progressApi/ig.test(_url || ""); | ||
if (shouldRender) { | ||
_url = ((_a = /get_progressApi\('(.*?)'\)/.exec(_url || "")) === null || _a === void 0 ? void 0 : _a[1]) || _url; | ||
} | ||
results.push({ | ||
resolution, | ||
thumbnail, | ||
url: _url, | ||
shouldRender | ||
}); | ||
}); | ||
} | ||
else { | ||
$("div.download-items__thumb").each((_, tod) => { | ||
const thumbnail = $(tod).find("img").attr("src"); | ||
$("div.download-items__btn").each((_, ol) => { | ||
let _url = $(ol).find("a").attr("href"); | ||
if (!/https?:\/\//.test(_url || "")) | ||
_url = `https://snapsave.app${_url}`; | ||
results.push({ | ||
thumbnail, | ||
url: _url | ||
}); | ||
}); | ||
}); | ||
} | ||
if (!results.length) | ||
return { status: false, msg: "Blank data" }; | ||
return { status: true, data: results }; | ||
results.push({ | ||
resolution, | ||
thumbnail, | ||
url: _url, | ||
shouldRender | ||
}); | ||
}); | ||
} else { | ||
$("div.download-items__thumb").each((_, tod) => { | ||
const thumbnail = $(tod).find("img").attr("src"); | ||
$("div.download-items__btn").each((_2, ol) => { | ||
let _url = $(ol).find("a").attr("href"); | ||
if (!/https?:\/\//.test(_url || "")) _url = `https://snapsave.app${_url}`; | ||
results.push({ | ||
thumbnail, | ||
url: _url | ||
}); | ||
}); | ||
}); | ||
} | ||
catch (e) { | ||
return { status: false, msg: e.message }; | ||
} | ||
if (!results.length) return { status: false, msg: "Blank data" }; | ||
return { status: true, data: results }; | ||
} catch (e) { | ||
return { status: false, msg: e.message }; | ||
} | ||
}); | ||
export { | ||
snapsave | ||
}; |
{ | ||
"name": "snapsave-media-downloader", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Download Instagram and Facebook Media using snapsave.app downloader", | ||
@@ -40,10 +40,10 @@ "type": "module", | ||
"devDependencies": { | ||
"@stylistic/eslint-plugin": "^2.6.2", | ||
"@types/node": "^22.2.0", | ||
"@typescript-eslint/parser": "^8.0.1", | ||
"@stylistic/eslint-plugin": "^2.7.2", | ||
"@types/node": "^22.5.4", | ||
"@typescript-eslint/parser": "^8.4.0", | ||
"changelogen": "^0.5.5", | ||
"cheerio": "1.0.0", | ||
"eslint": "^9.9.0", | ||
"ofetch": "^1.3.4", | ||
"eslint": "^9.9.1", | ||
"shx": "^0.3.4", | ||
"tsup": "^8.2.4", | ||
"typescript": "^5.5.4" | ||
@@ -53,3 +53,3 @@ }, | ||
"lint": "eslint . --fix", | ||
"build": "shx rm -rf ./dist/* && tsc", | ||
"build": "shx rm -rf ./dist/* && tsup-node src/index.ts --format esm --dts --config tsconfig.json", | ||
"playground": "node playground/index.js", | ||
@@ -56,0 +56,0 @@ "release": "changelogen --release" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132
8148
4
1