Update index.js
Browse files
index.js
CHANGED
|
@@ -291,7 +291,7 @@ u < units.length - 1
|
|
| 291 |
return `${bytes.toFixed(dp)} ${units[u]}`;
|
| 292 |
}
|
| 293 |
|
| 294 |
-
async function ytmp4(url, quality = 'highestvideo') {
|
| 295 |
try {
|
| 296 |
const ID = ytdl.getVideoID(url),
|
| 297 |
data = await ytdl.getInfo('https://www.youtube.com/watch?v=' + ID);
|
|
@@ -333,7 +333,7 @@ const audioStream = await ytdl(ID, { filter: 'audioonly', quality: bitrate });
|
|
| 333 |
//let buffer = await streamToBuffer(audioStream);
|
| 334 |
|
| 335 |
|
| 336 |
-
|
| 337 |
try {
|
| 338 |
const tmp = path.join(os.tmpdir(), `${+new Date()}.${ext}`);
|
| 339 |
const out = `${tmp}.mp3`;
|
|
@@ -374,6 +374,64 @@ const audioStream = await ytdl(ID, { filter: 'audioonly', quality: bitrate });
|
|
| 374 |
}
|
| 375 |
}*/
|
| 376 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
//let konver = await convertToAudio(buffer, "mp4");
|
| 378 |
//let upload = await uploadBuffer(konver);
|
| 379 |
//let urel = upload != null ? { url_v2: upload } : null;
|
|
|
|
| 291 |
return `${bytes.toFixed(dp)} ${units[u]}`;
|
| 292 |
}
|
| 293 |
|
| 294 |
+
/*async function ytmp4(url, quality = 'highestvideo') {
|
| 295 |
try {
|
| 296 |
const ID = ytdl.getVideoID(url),
|
| 297 |
data = await ytdl.getInfo('https://www.youtube.com/watch?v=' + ID);
|
|
|
|
| 333 |
//let buffer = await streamToBuffer(audioStream);
|
| 334 |
|
| 335 |
|
| 336 |
+
async function convertToAudio(buffer, ext) {
|
| 337 |
try {
|
| 338 |
const tmp = path.join(os.tmpdir(), `${+new Date()}.${ext}`);
|
| 339 |
const out = `${tmp}.mp3`;
|
|
|
|
| 374 |
}
|
| 375 |
}*/
|
| 376 |
|
| 377 |
+
async function ytmp4(url, quality = 'highestvideo') {
|
| 378 |
+
try {
|
| 379 |
+
const ID = ytdl.getVideoID(url);
|
| 380 |
+
const data = await ytdl.getInfo(ID);
|
| 381 |
+
|
| 382 |
+
let format = ytdl.chooseFormat(data.formats, { filter: format => format.hasVideo && format.hasAudio, quality });
|
| 383 |
+
|
| 384 |
+
if (format) {
|
| 385 |
+
return {
|
| 386 |
+
title: data.videoDetails.title,
|
| 387 |
+
description: data.videoDetails.description,
|
| 388 |
+
channel: data.videoDetails.ownerChannelName,
|
| 389 |
+
views: formatViews(data.videoDetails.viewCount),
|
| 390 |
+
publish: data.videoDetails.publishDate,
|
| 391 |
+
duration: formatDuration(data.videoDetails.lengthSeconds),
|
| 392 |
+
size: format.contentLength ? formatSize(format.contentLength) : 0,
|
| 393 |
+
quality: format.qualityLabel,
|
| 394 |
+
thumb: data.videoDetails.thumbnails[0].url,
|
| 395 |
+
dl_url: format.url,
|
| 396 |
+
};
|
| 397 |
+
} else {
|
| 398 |
+
throw new Error('No suitable format found');
|
| 399 |
+
}
|
| 400 |
+
} catch (error) {
|
| 401 |
+
console.error('Error occurred:', error.message);
|
| 402 |
+
return { error: error.message };
|
| 403 |
+
}
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
async function ytmp3(url, bitrate = 'highestaudio') {
|
| 407 |
+
try {
|
| 408 |
+
const ID = ytdl.getVideoID(url);
|
| 409 |
+
const data = await ytdl.getInfo(ID);
|
| 410 |
+
|
| 411 |
+
let format = ytdl.chooseFormat(data.formats, { filter: 'audioonly', quality: bitrate });
|
| 412 |
+
|
| 413 |
+
if (format) {
|
| 414 |
+
return {
|
| 415 |
+
title: data.videoDetails.title,
|
| 416 |
+
description: data.videoDetails.description,
|
| 417 |
+
channel: data.videoDetails.ownerChannelName,
|
| 418 |
+
views: formatViews(data.videoDetails.viewCount),
|
| 419 |
+
publish: data.videoDetails.publishDate,
|
| 420 |
+
duration: formatDuration(data.videoDetails.lengthSeconds),
|
| 421 |
+
size: format.contentLength ? formatSize(format.contentLength) : 0,
|
| 422 |
+
quality: format.audioQuality,
|
| 423 |
+
thumb: data.videoDetails.thumbnails[0].url,
|
| 424 |
+
dl_url: format.url,
|
| 425 |
+
};
|
| 426 |
+
} else {
|
| 427 |
+
throw new Error('No suitable format found');
|
| 428 |
+
}
|
| 429 |
+
} catch (error) {
|
| 430 |
+
console.error('Error occurred:', error.message);
|
| 431 |
+
return { error: error.message };
|
| 432 |
+
}
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
//let konver = await convertToAudio(buffer, "mp4");
|
| 436 |
//let upload = await uploadBuffer(konver);
|
| 437 |
//let urel = upload != null ? { url_v2: upload } : null;
|