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
57 lines (47 loc) • 1.89 kB
JavaScript
const fetch = require('node-fetch');
async function ytshort(url) {
if (!url.match(/youtu\.be|youtube\.com/i)) return { error: 'URL YouTube tidak valid' };
const isShorts = /youtube\.com\/shorts\//.test(url);
if (!isShorts) return { error: 'Harap masukkan URL YouTube Shorts yang valid' };
try {
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 });
const init = await initial.json();
const id = url.match(/(?:youtu\.be\/|youtube\.com\/(?:shorts\/|.*v=|.*\/|.*embed\/))([^&?/]+)/)?.[1];
if (!id) throw new Error('Gagal mendapatkan ID video');
const convertURL = init.convertURL + `&v=${id}&f=mp4&_=${Math.random()}`;
const converts = await fetch(convertURL, { headers });
const convert = await converts.json();
let info = {};
for (let i = 0; i < 5; i++) {
await new Promise(resolve => setTimeout(resolve, 2000));
const progressRes = await fetch(convert.progressURL, { headers });
info = await progressRes.json();
if (info.progress === 3) break;
}
if (!info.title || !convert.downloadURL) throw new Error('Konversi gagal');
return {
author: "Herza",
status: 200,
data: {
videoUrl: convert.downloadURL,
title: info.title
}
};
} catch (error) {
console.error(error);
return { error: error.message };
}
}
module.exports = { ytshort }