Spaces:
Paused
Paused
| /* eslint-disable jsdoc/require-jsdoc */ | |
| const axios = require('axios'); | |
| const FormData = require('form-data'); | |
| const cheerio = require('cheerio'); | |
| const fromBuffer = x => import("file-type").then(v => v.fileTypeFromBuffer(x)) | |
| async function igdl(url) { | |
| try { | |
| const formData = new FormData(); | |
| formData.append('url', url); | |
| const { data } = await axios.post('https://snapsave.app/id/action.php?lang=id', formData, { | |
| headers: { | |
| ...formData.getHeaders(), | |
| 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' | |
| } | |
| }); | |
| // eslint-disable-next-line no-unused-vars | |
| const js = await new Promise(r => eval(data.replace('eval', 'r'))); | |
| const raw = js.match(/document\.getElementById\("download-section"\)\.innerHTML\s*=\s*"(.*?)";/s); | |
| const $ = cheerio.load(raw[1].replace(/\\"/g, '"').replace(/\\n/g, '').replace(/\\t/g, '').replace(/\\\\/g, '\\')); | |
| let thumb = ""; | |
| $("img").each((i, img) => { | |
| const src = $(img).attr("src") | |
| thumb = src | |
| }) | |
| let res = { | |
| status: 200, | |
| type: "ig", | |
| title: "", | |
| thumbnail: thumb, | |
| video: [], | |
| image: [] | |
| }; | |
| let sesi = [] | |
| // Cek setiap link yang ada | |
| $('.download-items__btn a').each(async (i, element) => { | |
| const xk = $(element).attr('href'); | |
| sesi.push(xk) | |
| }); | |
| for (const i of sesi) { | |
| const response = await axios.get(i, { responseType: 'arraybuffer' }); | |
| const buffer = Buffer.from(response.data); | |
| const type = await fromBuffer(buffer); | |
| if (type) { | |
| if (type.mime.startsWith('image')) { | |
| res.image.push(i); | |
| if (!res.thumbnail) { | |
| res.thumbnail = i; | |
| } | |
| } | |
| // Jika file adalah video | |
| else if (type.mime.startsWith('video')) { | |
| res.video.push({ resolusi: "HD", url: i, mimetype: type.mime }); | |
| } | |
| } | |
| } | |
| return res; | |
| } catch (err) { | |
| console.error("[ERROR IG]\n\n", e); | |
| return { status: 500, message: err.message}; | |
| } | |
| } | |
| module.exports = igdl; |