Update index.js
Browse files385 unmodified lines386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470389390391323 unmodified lines7157167178008018027187197207217228058067237247257267277281 unmodified line730731732814733734735736385 unmodified lines}}
async function ytDEEL(url) { const { v4: uuidv4 } = require('uuid'); const theme = encodeURIComponent('system'); const apiUrl = `https://gradio-blocks-youtube-downloader.hf.space/queue/join?__theme=${theme}`; const mp3UploadId = uuidv4(); // Gunakan UUID yang berbeda untuk MP3 const mp4UploadId = Math.random().toString(36).substring(2); // Gunakan UUID yang berbeda untuk MP4 const mp3PostData = { data: [url, false], event_data: null, fn_index: 0, session_hash: mp3UploadId, // Gunakan mp3UploadId untuk MP3 trigger_id: 10 }; const mp4PostData = { data: [url, true], event_data: null, fn_index: 0, session_hash: mp4UploadId, // Gunakan mp4UploadId untuk MP4 trigger_id: 10 }; try { // Kirim permintaan MP3 const mp3Response = await axios.post(apiUrl, mp3PostData, { headers: { 'Content-Type': 'application/json', 'Accept': '*/*' } }); const mp3EventId = mp3Response.data.event_id; // Tunggu respons MP3 let mp3Url; let mp3Completed = false; const mp3StatusUrl = `https://gradio-blocks-youtube-downloader.hf.space/queue/data?session_hash=${mp3UploadId}`; while (!mp3Completed) { const statusResponse = await axios.get(mp3StatusUrl, { headers: { 'Accept': 'text/event-stream' }, responseType: 'text' }); const rawData = statusResponse.data.trim().split('\n').map(line => line.replace(/^data: /, '')); for (const line of rawData) { try { const event = JSON.parse(line); if (event.msg === 'process_completed') { if (event.event_id === mp3EventId && !mp3Completed) { mp3Url = event?.output?.data[1]?.value?.url; mp3Completed = true; } } } catch (e) {} } await new Promise(resolve => setTimeout(resolve, 5000)); } // Kirim permintaan MP4 const mp4Response = await axios.post(apiUrl, mp4PostData, { headers: { 'Content-Type': 'application/json', 'Accept': '*/*' } }); const mp4EventId = mp4Response.data.event_id; // Tunggu respons MP4 let mp4Url; let mp4Completed = false; const mp4StatusUrl = `https://gradio-blocks-youtube-downloader.hf.space/queue/data?session_hash=${mp4UploadId}`; while (!mp4Completed) { const statusResponse = await axios.get(mp4StatusUrl, { headers: { 'Accept': 'text/event-stream' }, responseType: 'text' }); const rawData = statusResponse.data.trim().split('\n').map(line => line.replace(/^data: /, '')); for (const line of rawData) { try { const event = JSON.parse(line); if (event.msg === 'process_completed') { if (event.event_id === mp4EventId && !mp4Completed) { mp4Url = event?.output?.data[0]?.value?.url; mp4Completed = true; } } } catch (e) {} } await new Promise(resolve => setTimeout(resolve, 5000)); } const result = { mp3: mp3Url.replace(/\s/g, '%20'), mp4: mp4Url.replace(/\s/g, '%20') }; return result } catch (error) { throw error; } }
const app = express().set('json spaces', 4)323 unmodified lines let { url } = req.query; if (!ytIdRegex.test(url)) return res.json({ message: 'Invalid URL' });
let data = await ytAPI(url) ? await ytAPI(url) : {} let dataInfo = await ytdl.getVideoID(url) dataInfo = await yts({videoId: dataInfo}) ? await yts({videoId: dataInfo}) : {} let data = await ytAPI(url) || {}; let videoID = ytdl.getVideoID(url); let dataInfo = await yts({ videoId: videoID }) || {};
let response = { ...dataInfo, ...data, dataInfo, mp4_url: data.mp4_url, mp3_url: data.mp3_url };
return res.json(response);1 unmodified line console.log(e); return res.status(500).json({ message: e.message }); }})});.get('/twitter', async (req, res) => {try {let { url } = req.query;index.js+7-88