Update index.js
Browse files
index.js
CHANGED
|
@@ -386,88 +386,6 @@ form.append('lang', 'en');
|
|
| 386 |
}
|
| 387 |
}
|
| 388 |
|
| 389 |
-
async function ytDEEL(url) {
|
| 390 |
-
const { v4: uuidv4 } = require('uuid');
|
| 391 |
-
const theme = encodeURIComponent('system');
|
| 392 |
-
const apiUrl = `https://gradio-blocks-youtube-downloader.hf.space/queue/join?__theme=${theme}`;
|
| 393 |
-
const mp3UploadId = uuidv4(); // Gunakan UUID yang berbeda untuk MP3
|
| 394 |
-
const mp4UploadId = Math.random().toString(36).substring(2); // Gunakan UUID yang berbeda untuk MP4
|
| 395 |
-
|
| 396 |
-
const mp3PostData = {
|
| 397 |
-
data: [url, false],
|
| 398 |
-
event_data: null,
|
| 399 |
-
fn_index: 0,
|
| 400 |
-
session_hash: mp3UploadId, // Gunakan mp3UploadId untuk MP3
|
| 401 |
-
trigger_id: 10
|
| 402 |
-
};
|
| 403 |
-
|
| 404 |
-
const mp4PostData = {
|
| 405 |
-
data: [url, true],
|
| 406 |
-
event_data: null,
|
| 407 |
-
fn_index: 0,
|
| 408 |
-
session_hash: mp4UploadId, // Gunakan mp4UploadId untuk MP4
|
| 409 |
-
trigger_id: 10
|
| 410 |
-
};
|
| 411 |
-
|
| 412 |
-
try {
|
| 413 |
-
// Kirim permintaan MP3
|
| 414 |
-
const mp3Response = await axios.post(apiUrl, mp3PostData, { headers: { 'Content-Type': 'application/json', 'Accept': '*/*' } });
|
| 415 |
-
const mp3EventId = mp3Response.data.event_id;
|
| 416 |
-
|
| 417 |
-
// Tunggu respons MP3
|
| 418 |
-
let mp3Url;
|
| 419 |
-
let mp3Completed = false;
|
| 420 |
-
const mp3StatusUrl = `https://gradio-blocks-youtube-downloader.hf.space/queue/data?session_hash=${mp3UploadId}`;
|
| 421 |
-
while (!mp3Completed) {
|
| 422 |
-
const statusResponse = await axios.get(mp3StatusUrl, { headers: { 'Accept': 'text/event-stream' }, responseType: 'text' });
|
| 423 |
-
const rawData = statusResponse.data.trim().split('\n').map(line => line.replace(/^data: /, ''));
|
| 424 |
-
for (const line of rawData) {
|
| 425 |
-
try {
|
| 426 |
-
const event = JSON.parse(line);
|
| 427 |
-
if (event.msg === 'process_completed') {
|
| 428 |
-
if (event.event_id === mp3EventId && !mp3Completed) {
|
| 429 |
-
mp3Url = event?.output?.data[1]?.value?.url;
|
| 430 |
-
mp3Completed = true;
|
| 431 |
-
}
|
| 432 |
-
}
|
| 433 |
-
} catch (e) {}
|
| 434 |
-
}
|
| 435 |
-
await new Promise(resolve => setTimeout(resolve, 5000));
|
| 436 |
-
}
|
| 437 |
-
|
| 438 |
-
// Kirim permintaan MP4
|
| 439 |
-
const mp4Response = await axios.post(apiUrl, mp4PostData, { headers: { 'Content-Type': 'application/json', 'Accept': '*/*' } });
|
| 440 |
-
const mp4EventId = mp4Response.data.event_id;
|
| 441 |
-
|
| 442 |
-
// Tunggu respons MP4
|
| 443 |
-
let mp4Url;
|
| 444 |
-
let mp4Completed = false;
|
| 445 |
-
const mp4StatusUrl = `https://gradio-blocks-youtube-downloader.hf.space/queue/data?session_hash=${mp4UploadId}`;
|
| 446 |
-
while (!mp4Completed) {
|
| 447 |
-
const statusResponse = await axios.get(mp4StatusUrl, { headers: { 'Accept': 'text/event-stream' }, responseType: 'text' });
|
| 448 |
-
const rawData = statusResponse.data.trim().split('\n').map(line => line.replace(/^data: /, ''));
|
| 449 |
-
for (const line of rawData) {
|
| 450 |
-
try {
|
| 451 |
-
const event = JSON.parse(line);
|
| 452 |
-
if (event.msg === 'process_completed') {
|
| 453 |
-
if (event.event_id === mp4EventId && !mp4Completed) {
|
| 454 |
-
mp4Url = event?.output?.data[0]?.value?.url;
|
| 455 |
-
mp4Completed = true;
|
| 456 |
-
}
|
| 457 |
-
}
|
| 458 |
-
} catch (e) {}
|
| 459 |
-
}
|
| 460 |
-
await new Promise(resolve => setTimeout(resolve, 5000));
|
| 461 |
-
}
|
| 462 |
-
|
| 463 |
-
const result = { mp3: mp3Url.replace(/\s/g, '%20'), mp4: mp4Url.replace(/\s/g, '%20') };
|
| 464 |
-
return result
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
} catch (error) {
|
| 468 |
-
throw error;
|
| 469 |
-
}
|
| 470 |
-
}
|
| 471 |
|
| 472 |
const app = express()
|
| 473 |
.set('json spaces', 4)
|
|
@@ -797,13 +715,14 @@ return res.json({ message: e.message });
|
|
| 797 |
let { url } = req.query;
|
| 798 |
if (!ytIdRegex.test(url)) return res.json({ message: 'Invalid URL' });
|
| 799 |
|
| 800 |
-
let data = await ytAPI(url)
|
| 801 |
-
|
| 802 |
-
|
| 803 |
|
| 804 |
let response = {
|
| 805 |
-
|
| 806 |
-
|
|
|
|
| 807 |
};
|
| 808 |
|
| 809 |
return res.json(response);
|
|
@@ -811,7 +730,7 @@ return res.json({ message: e.message });
|
|
| 811 |
console.log(e);
|
| 812 |
return res.status(500).json({ message: e.message });
|
| 813 |
}
|
| 814 |
-
})
|
| 815 |
.get('/twitter', async (req, res) => {
|
| 816 |
try {
|
| 817 |
let { url } = req.query;
|
|
|
|
| 386 |
}
|
| 387 |
}
|
| 388 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
|
| 390 |
const app = express()
|
| 391 |
.set('json spaces', 4)
|
|
|
|
| 715 |
let { url } = req.query;
|
| 716 |
if (!ytIdRegex.test(url)) return res.json({ message: 'Invalid URL' });
|
| 717 |
|
| 718 |
+
let data = await ytAPI(url) || {};
|
| 719 |
+
let videoID = ytdl.getVideoID(url);
|
| 720 |
+
let dataInfo = await yts({ videoId: videoID }) || {};
|
| 721 |
|
| 722 |
let response = {
|
| 723 |
+
dataInfo,
|
| 724 |
+
mp4_url: data.mp4_url,
|
| 725 |
+
mp3_url: data.mp3_url
|
| 726 |
};
|
| 727 |
|
| 728 |
return res.json(response);
|
|
|
|
| 730 |
console.log(e);
|
| 731 |
return res.status(500).json({ message: e.message });
|
| 732 |
}
|
| 733 |
+
});
|
| 734 |
.get('/twitter', async (req, res) => {
|
| 735 |
try {
|
| 736 |
let { url } = req.query;
|