| const axios = require('axios'); |
| const cheerio = require('cheerio'); |
|
|
| async function yt(url, format) { |
| const headers = { |
| "accept": "*/*", |
| "accept-language": "id-ID,id;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": "cross-site", |
| "Referer": "https://id.ytmp3.mobi/", |
| "Referrer-Policy": "strict-origin-when-cross-origin" |
| } |
|
|
| const initial = await fetch(`https://d.ymcdn.org/api/v1/init?p=y&23=1llum1n471&_=${Math.random()}`, {headers}); |
| format = format || 'mp3'; |
| const init = await initial.json(); |
| console.log(init) |
|
|
| const id = url.match(/(?:youtu\.be\/|youtube\.com\/(?:.*v=|.*\/|.*embed\/))([^&?/]+)/)?.[1]; |
| let convertURL = init.convertURL + `&v=${id}&f=${format}&_=${Math.random()}`; |
| |
|
|
| const converts = await fetch(convertURL, {headers}); |
| const convert = await converts.json(); |
| |
|
|
| let info = {}; |
| for (let i = 0; i < 3; i++ ){ |
| let j = await fetch(convert.progressURL, {headers}); |
| info = await j.json(); |
| console.log(info); |
| if (info.progress == 3) break; |
| } |
|
|
| return { url: convert.downloadURL }; |
| }; |
|
|
| async function tiktok(url) { |
| const { data } = await axios.get(`https://www.tikwm.com/api?url=${url}&hd=1`); |
| if(!data.status !== 0) return { status: false, r: 'error' }; |
| return { status: true, url: data.data.play, hd: data.data.hdplay, audio: data.data.music_info.play }; |
| }; |
|
|
| async function instagram(url) { |
| const { data } = await axios.post( |
| 'https://yt1s.io/api/ajaxSearch', |
| new URLSearchParams({ |
| p: 'home', |
| q: url, |
| w: '', |
| lang: 'en' |
| }), |
| { |
| headers: { |
| 'User-Agent': 'Postify/1.0.0', |
| 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', |
| 'Accept': 'application/json, text/plain, */*', |
| 'Origin': 'https://yt1s.io', |
| 'Referer': 'https://yt1s.io/' |
| } |
| } |
| ) |
|
|
| const $ = cheerio.load(data.data) |
| const rres = []; |
| $('a.abutton.is-success.is-fullwidth.btn-premium') |
| .map((_, el) => { |
| rres.push($(el).attr('href')); |
| }) |
| .get() |
| return { url: rres } |
| } |
|
|
| async function threads(url) { |
| try { |
| const apiUrl = `https://snapthreads.net/api/download?url=${encodeURIComponent(url)}`; |
|
|
| const response = await axios.get(apiUrl, { |
| headers: { |
| "User-Agent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Mobile Safari/537.36", |
| "Referer": "https://snapthreads.net/id", |
| "Accept": "*/*", |
| "X-Requested-With": "XMLHttpRequest" |
| } |
| }); |
| if (response.data && response.data.directLink) { |
| return { |
| success: true, |
| url: response.data.directLink |
| }; |
| } else { |
| return { |
| success: false, |
| r: 'cant find download link' |
| }; |
| } |
| } catch (error) { |
| console.error("Error:", error.response ? error.response.data : error.message); |
| return { |
| success: false, |
| r: error.response ? error.response.data : error.message |
| }; |
| } |
| } |
|
|
| async function twitter(url) { |
| try { |
| const formData = new URLSearchParams(); |
| formData.append("q", url); |
| formData.append("lang", "id"); |
| formData.append("cftoken", "JWT.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpcCI6IjE4Mi4xLjEzNS4yMzgiLCJ1cmwiOiJodHRwczovL3guY29tL2dhbGFzYW5zL3N0YXR1cy8xOTAxMTI5MDYyOTU1MDE2Mzk3P3Q9VTgzM0JmSExpUmRYM0NSUDVGOUhrZyZzPTE5IiwibmJmIjoxNzQyMzA0MzI2LCJleHAiOjE3NDIzMDQ2MjYsImlhdCI6MTc0MjMwNDMyNn0.h0GMNpNikiYqJgdhEEA2NN023_5fq5m7Scn31aMqYOo"); |
| const headers = { |
| "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", |
| "Accept": "*/*", |
| "X-Requested-With": "XMLHttpRequest", |
| "User-Agent": |
| "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Mobile Safari/537.36", |
| "Referer": "https://x2twitter.com/id", |
| }; |
| const response = await axios.post( |
| "https://x2twitter.com/api/ajaxSearch", |
| formData, |
| { headers } |
| ); |
| if (response.data.status !== "ok") { |
| throw new Error("Gagal mengambil data dari server."); |
| } |
|
|
| const html = response.data.data; |
| const $ = cheerio?.load(html); |
| let results = []; |
| $(".dl-action a").each((_, el) => { |
| const type = $(el).text().trim(); |
| const downloadUrl = $(el).attr("href"); |
| if (downloadUrl && downloadUrl !== "#") { |
| results.push({ type, url: downloadUrl }); |
| } |
| }); |
|
|
| return { |
| success: results.length > 0, |
| url: results |
| }; |
| } catch (error) { |
| return { success: false, r: error.message }; |
| } |
| } |
|
|
| module.exports = { yt, tiktok, instagram, threads, twitter }; |