Untitled
unknown
plain_text
2 years ago
1.6 kB
5
Indexable
Never
const axios = require('axios'); @param @returns {Promise<Array<{fileExtension: string, directUrl: string}> | string>} async function instagram_Url(instagramUrl) { const api = 'https://instasupersave.com'; // Collect cookie from session. try { const { headers: { 'set-cookie': cookie } } = await axios(api); const session = String(cookie[0].split(';')[0]).replace('XSRF-TOKEN=', '').replace('%3D', ''); // Setup request headers. const requestHeaders = { method: 'POST', url: `${api}/api/convert`, headers: { 'Origin': api, 'Referer': `${api}/pt/`, 'Sec-Fetch-Dest': 'empty', 'Sec-Fetch-Mode': 'cors', 'Sec-Fetch-Site': 'same-origin', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.52', 'X-XSRF-Token': session, 'Content-Type': 'application/json', 'Cookie': `XSRF-TOKEN=${session}; instasupersave_session=${session}` }, data: { url: instagramUrl } }; // Call the API and process the data. const { data } = await axios(requestHeaders); // console.log(data); return Array.isArray(data) ? data.map((item) => { const { ext: fileExtension, url: directUrl } = item.url[0]; return { fileExtension, directUrl: item?.sd?.url || directUrl }; }) : [{ fileExtension: data.url[0].ext, directUrl: data.url[0].url }]; } catch (error) { return (await import('util')).format( '[instagram-direct-url] %s (Status: %s, Status Text: %s)', error?.message || 'An error occurred.', error?.response?.status || 'None', error?.response?.statusText || 'None' ); } }