UNPKG

notmebotz-tools

Version:

Sebuah Tools yang berfungsi untuk mendownload Video atau Foto dari media sosial, serta sebagai tools yang berguna untuk aplikasi kamu seperti untuk BOT

169 lines (152 loc) 4.51 kB
/*** *** ᠁᠁᠁᠁᠁᠁᠁᠁᠁᠁᠁᠁᠁ *** - Dev: FongsiDev *** - Contact: t.me/dashmodz *** - Gmail: fongsiapi@gmail.com & fgsidev@neko2.net *** - Group: chat.whatsapp.com/Ke94ex9fNLjE2h8QzhvEiy *** - Telegram Group: t.me/fongsidev *** - Github: github.com/Fgsi-APIs/RestAPIs/issues/new *** - Huggingface: huggingface.co/fgsi1 *** - Website: fgsi1-restapi.hf.space *** ᠁᠁᠁᠁᠁᠁᠁᠁᠁᠁᠁᠁᠁ ***/ const axios = require("axios"); const amdl = { baseUrl: "https://aaplmusicdownloader.com", userAgent: "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Mobile Safari/537.36", headers: { authority: "aaplmusicdownloader.com", accept: "application/json, text/javascript, */*; q=0.01", "accept-language": "ms-MY,ms;q=0.9,en-US;q=0.8,en;q=0.7", "sec-ch-ua": '"Not A(Brand";v="8", "Chromium";v="132"', "sec-ch-ua-mobile": "?1", "sec-ch-ua-platform": '"Android"', "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-origin", "user-agent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Mobile Safari/537.36", "x-requested-with": "XMLHttpRequest", }, parseUrl(url) { try { let cleanUrl = url.trim(); cleanUrl = cleanUrl.replace(/\s+/g, ''); return encodeURI(cleanUrl); } catch (error) { return url; } }, async search(url) { const parsedUrl = this.parseUrl(url); const response = await axios.get(`${this.baseUrl}/api/applesearch.php`, { params: { url: parsedUrl }, headers: { ...this.headers, referer: `${this.baseUrl}/`, }, timeout: 30000, }); return response.data; }, async getSessionCookie() { const response = await axios.get(this.baseUrl, { headers: { ...this.headers, referer: `${this.baseUrl}/`, }, timeout: 30000, }); const setCookie = response.headers["set-cookie"]?.[0]; if (!setCookie) throw new Error("No Set-Cookie header found"); const cookie = setCookie.split(";")[0]; return cookie; }, async download({ songName, artistName, url, quality = "m4a", zipDownload = false }) { const cookie = await this.getSessionCookie(); const form = new URLSearchParams({ song_name: songName, artist_name: artistName, url, token: "none", zip_download: zipDownload.toString(), quality, }); const response = await axios.post(`${this.baseUrl}/api/composer/swd.php`, form, { headers: { ...this.headers, "content-type": "application/x-www-form-urlencoded; charset=UTF-8", cookie: cookie, origin: this.baseUrl, referer: `${this.baseUrl}/song.php`, }, timeout: 60000, }); return response.data; }, async getFileSize(url) { try { const encodedUrl = encodeURI(url); const response = await axios.head(encodedUrl, { timeout: 10000 }); const contentLength = response.headers['content-length']; if (contentLength) { const bytes = parseInt(contentLength); if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB`; return `${(bytes / (1024 * 1024)).toFixed(2)} MB`; } return "Unknown"; } catch (error) { return "Unknown"; } } }; async function downloads(url, type = "m4a") { try { const searchResult = await amdl.search(url); if (!searchResult || !searchResult.name) { return { author: "Herza", status: 404, data: { url: null, size: null } }; } const downloadResult = await amdl.download({ songName: searchResult.name, artistName: searchResult.artist, url: searchResult.url, quality: type, }); if (!downloadResult || !downloadResult.dlink) { return { author: "Herza", status: 500, data: { url: null, size: null } }; } const fileSize = await amdl.getFileSize(downloadResult.dlink); return { author: "Herza", status: 200, data: { url: encodeURI(downloadResult.dlink), size: fileSize } }; } catch (error) { return { author: "Herza", status: 500, data: { url: null, size: null } }; } } module.exports = { downloads}