zyscr
Version:
93 lines (92 loc) • 3.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.instagram = void 0;
const Utils_1 = require("../Utils");
const Constant_1 = require("../Constant");
class Instagrams {
constructor() { }
static async v1(url) {
try {
const { data, headers } = await Utils_1.Axios.request({
url: Constant_1.InstagramDownloadBaseUrl.v1,
method: "POST",
headers: {
["Content-Type"]: "application/x-www-form-urlencoded",
["Upgrade-Insecure-Requests"]: "1",
["Referer"]: Constant_1.InstagramDownloadBaseUrl.v1,
["Referrer-Policy"]: "strict-origin-when-cross-origin",
},
data: new URLSearchParams({ url, submit: "" }),
}).catch((e) => e?.response);
const $ = (0, Utils_1.Cheerio)(data);
const _temp = [];
$("#downloadhere > a[download='']").each((i, e) => {
_temp.push({ url: $(e).attr("href") });
});
if (Array.isArray(_temp) && _temp.length) {
return _temp;
}
else {
throw new Error($(".alert-danger").text() || "v1: Failed to retrieve data.");
}
}
catch (e) {
return {
error: true,
message: String(e?.Error || e),
};
}
}
static async v2(url) {
try {
const { data: _data, headers } = await Utils_1.Axios.request({
baseURL: Constant_1.InstagramDownloadBaseUrl.v2,
method: "GET",
headers: {
["User-Agent"]: "okhttp/4.20.0",
},
}).catch((e) => e?.response);
const _$ = (0, Utils_1.Cheerio)(_data);
const _opts = {
referer: _$("input[name='referer']").attr("value"),
locale: _$("input[name='locale']").attr("value"),
_token: _$("input[name='_token']").attr("value"),
link: url,
};
const { data } = await Utils_1.Axios.request({
baseURL: Constant_1.InstagramDownloadBaseUrl.v2,
url: "/download",
method: "POST",
headers: {
["User-Agent"]: "okhttp/4.20.0",
cookie: headers["set-cookie"],
},
data: new URLSearchParams({ ..._opts }),
}).catch((e) => e?.response);
const $ = (0, Utils_1.Cheerio)(data);
const _temp = [];
$("#result")
.find("a[target='_blank']")
.each((i, e) => {
const url = $(e).attr("href");
_temp.push({ url });
});
if (_temp.length) {
return _temp;
}
else {
throw new Error("Probably wrong url or private post/reel");
}
}
catch (e) {
return {
error: true,
message: String(e),
};
}
}
}
exports.instagram = {
v1: Instagrams.v1,
v2: Instagrams.v2,
};