Update index.js
Browse files
index.js
CHANGED
|
@@ -229,13 +229,11 @@ async function fby2mate(url) {
|
|
| 229 |
}
|
| 230 |
|
| 231 |
//YTDL-CORE
|
| 232 |
-
async function
|
| 233 |
return new Promise(async (resolve, reject) => {
|
| 234 |
try {
|
| 235 |
-
let { fileTypeFromBuffer } = await import('file-type');
|
| 236 |
-
let mime = await fileTypeFromBuffer(media);
|
| 237 |
let form = new FormData();
|
| 238 |
-
form.append("files[]",
|
| 239 |
|
| 240 |
let urls = ["https://pomf.lain.la/upload.php", "https://up1.fileditch.com/upload.php"];
|
| 241 |
for (let url of urls) {
|
|
@@ -261,7 +259,7 @@ async function uploadBuffer(media) {
|
|
| 261 |
}
|
| 262 |
});
|
| 263 |
}
|
| 264 |
-
async function streamToBuffer(stream) {
|
| 265 |
const chunks = [];
|
| 266 |
const captureChunks = new Writable({
|
| 267 |
write(chunk, encoding, callback) {
|
|
@@ -273,7 +271,7 @@ callback();
|
|
| 273 |
await util.promisify(pipeline)(stream, captureChunks);
|
| 274 |
|
| 275 |
return Buffer.concat(chunks);
|
| 276 |
-
}
|
| 277 |
function formatViews(viewCount) {
|
| 278 |
if (viewCount >= 1000000000) {
|
| 279 |
return (viewCount / 1000000000).toFixed(1) + 'B';
|
|
@@ -324,14 +322,14 @@ u < units.length - 1
|
|
| 324 |
return `${bytes.toFixed(dp)} ${units[u]}`;
|
| 325 |
}
|
| 326 |
|
| 327 |
-
|
| 328 |
try {
|
| 329 |
const ID = ytdl.getVideoID(url),
|
| 330 |
data = await ytdl.getInfo('https://www.youtube.com/watch?v=' + ID);
|
| 331 |
-
|
| 332 |
//let buffer = await streamToBuffer(videoStream);
|
| 333 |
-
|
| 334 |
-
|
| 335 |
let format = ytdl.chooseFormat(data.formats, { filter: format => format.hasVideo && format.hasAudio, quality: quality });
|
| 336 |
|
| 337 |
|
|
@@ -347,7 +345,7 @@ if (format) {
|
|
| 347 |
quality: format.qualityLabel,
|
| 348 |
thumb: data.videoDetails.thumbnails[0].url,
|
| 349 |
dl_url: format.url,
|
| 350 |
-
|
| 351 |
};
|
| 352 |
} else {
|
| 353 |
throw new Error('No suitable format found');
|
|
@@ -366,49 +364,48 @@ const audioStream = await ytdl(ID, { filter: 'audioonly', quality: bitrate });
|
|
| 366 |
//let buffer = await streamToBuffer(audioStream);
|
| 367 |
|
| 368 |
|
| 369 |
-
async function convertToAudio(
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
|
|
|
| 397 |
});
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
throw e;
|
| 407 |
}
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
//let urel = upload != null ? { url_v2: upload } : null;
|
| 412 |
let format = ytdl.chooseFormat(data.formats, { filter: 'audioonly', quality: bitrate });
|
| 413 |
|
| 414 |
if (format) {
|
|
@@ -423,7 +420,7 @@ if (format) {
|
|
| 423 |
quality: format.audioQuality,
|
| 424 |
thumb: data.videoDetails.thumbnails[0].url,
|
| 425 |
dl_url: format.url,
|
| 426 |
-
|
| 427 |
};
|
| 428 |
} else {
|
| 429 |
throw new Error('No suitable format found');
|
|
@@ -432,9 +429,9 @@ if (format) {
|
|
| 432 |
console.error('Error occurred:', error);
|
| 433 |
return error;
|
| 434 |
}
|
| 435 |
-
}
|
| 436 |
|
| 437 |
-
async function ytmp4(url, quality = 'highestvideo') {
|
| 438 |
try {
|
| 439 |
const ID = ytdl.getVideoID(url);
|
| 440 |
const data = await ytdl.getInfo(ID);
|
|
@@ -490,7 +487,7 @@ async function ytmp3(url, bitrate = 'highestaudio') {
|
|
| 490 |
console.error('Error occurred:', error.message);
|
| 491 |
return { error: error.message };
|
| 492 |
}
|
| 493 |
-
}
|
| 494 |
|
| 495 |
|
| 496 |
// Fungsi untuk mengkonversi video dari YouTube
|
|
|
|
| 229 |
}
|
| 230 |
|
| 231 |
//YTDL-CORE
|
| 232 |
+
async function uploadStream(stream) {
|
| 233 |
return new Promise(async (resolve, reject) => {
|
| 234 |
try {
|
|
|
|
|
|
|
| 235 |
let form = new FormData();
|
| 236 |
+
form.append("files[]", fs.createReadStream(stream));
|
| 237 |
|
| 238 |
let urls = ["https://pomf.lain.la/upload.php", "https://up1.fileditch.com/upload.php"];
|
| 239 |
for (let url of urls) {
|
|
|
|
| 259 |
}
|
| 260 |
});
|
| 261 |
}
|
| 262 |
+
/*async function streamToBuffer(stream) {
|
| 263 |
const chunks = [];
|
| 264 |
const captureChunks = new Writable({
|
| 265 |
write(chunk, encoding, callback) {
|
|
|
|
| 271 |
await util.promisify(pipeline)(stream, captureChunks);
|
| 272 |
|
| 273 |
return Buffer.concat(chunks);
|
| 274 |
+
}*/
|
| 275 |
function formatViews(viewCount) {
|
| 276 |
if (viewCount >= 1000000000) {
|
| 277 |
return (viewCount / 1000000000).toFixed(1) + 'B';
|
|
|
|
| 322 |
return `${bytes.toFixed(dp)} ${units[u]}`;
|
| 323 |
}
|
| 324 |
|
| 325 |
+
async function ytmp4(url, quality = 'highestvideo') {
|
| 326 |
try {
|
| 327 |
const ID = ytdl.getVideoID(url),
|
| 328 |
data = await ytdl.getInfo('https://www.youtube.com/watch?v=' + ID);
|
| 329 |
+
const videoStream = await ytdl(ID, { filter: format => format.hasVideo && format.hasAudio, quality: quality });
|
| 330 |
//let buffer = await streamToBuffer(videoStream);
|
| 331 |
+
let upload = await uploadStream(videoStream);
|
| 332 |
+
let urel = upload != null ? { url_v2: upload } : null;
|
| 333 |
let format = ytdl.chooseFormat(data.formats, { filter: format => format.hasVideo && format.hasAudio, quality: quality });
|
| 334 |
|
| 335 |
|
|
|
|
| 345 |
quality: format.qualityLabel,
|
| 346 |
thumb: data.videoDetails.thumbnails[0].url,
|
| 347 |
dl_url: format.url,
|
| 348 |
+
...urel,
|
| 349 |
};
|
| 350 |
} else {
|
| 351 |
throw new Error('No suitable format found');
|
|
|
|
| 364 |
//let buffer = await streamToBuffer(audioStream);
|
| 365 |
|
| 366 |
|
| 367 |
+
async function convertToAudio(inputStream, ext) {
|
| 368 |
+
try {
|
| 369 |
+
const out = path.join(os.tmpdir(), `${+new Date()}.mp3`);
|
| 370 |
+
|
| 371 |
+
const ffmpegProcess = cp.spawn('ffmpeg', [
|
| 372 |
+
'-y',
|
| 373 |
+
'-i', 'pipe:0',
|
| 374 |
+
'-vn',
|
| 375 |
+
'-ac', '2',
|
| 376 |
+
'-b:a', '128k',
|
| 377 |
+
'-ar', '44100',
|
| 378 |
+
'-f', 'mp3',
|
| 379 |
+
out
|
| 380 |
+
]);
|
| 381 |
+
|
| 382 |
+
inputStream.pipe(ffmpegProcess.stdin);
|
| 383 |
+
|
| 384 |
+
await new Promise((resolve, reject) => {
|
| 385 |
+
ffmpegProcess.on('error', (err) => {
|
| 386 |
+
console.error(err);
|
| 387 |
+
reject(err);
|
| 388 |
+
});
|
| 389 |
+
ffmpegProcess.on('close', (code) => {
|
| 390 |
+
if (code !== 0) {
|
| 391 |
+
reject(`ffmpeg process closed with code: ${code}`);
|
| 392 |
+
} else {
|
| 393 |
+
resolve();
|
| 394 |
+
}
|
| 395 |
+
});
|
| 396 |
});
|
| 397 |
+
|
| 398 |
+
const result = await fs.promises.readFile(out);
|
| 399 |
+
await fs.promises.unlink(out);
|
| 400 |
+
return result;
|
| 401 |
+
} catch (e) {
|
| 402 |
+
console.error(e);
|
| 403 |
+
throw e;
|
| 404 |
+
}
|
|
|
|
| 405 |
}
|
| 406 |
+
let konver = await convertToAudio(audioStream, "mp4");
|
| 407 |
+
let upload = await uploadStream(konver);
|
| 408 |
+
let urel = upload != null ? { url_v2: upload } : null;
|
|
|
|
| 409 |
let format = ytdl.chooseFormat(data.formats, { filter: 'audioonly', quality: bitrate });
|
| 410 |
|
| 411 |
if (format) {
|
|
|
|
| 420 |
quality: format.audioQuality,
|
| 421 |
thumb: data.videoDetails.thumbnails[0].url,
|
| 422 |
dl_url: format.url,
|
| 423 |
+
...urel,
|
| 424 |
};
|
| 425 |
} else {
|
| 426 |
throw new Error('No suitable format found');
|
|
|
|
| 429 |
console.error('Error occurred:', error);
|
| 430 |
return error;
|
| 431 |
}
|
| 432 |
+
}
|
| 433 |
|
| 434 |
+
/*async function ytmp4(url, quality = 'highestvideo') {
|
| 435 |
try {
|
| 436 |
const ID = ytdl.getVideoID(url);
|
| 437 |
const data = await ytdl.getInfo(ID);
|
|
|
|
| 487 |
console.error('Error occurred:', error.message);
|
| 488 |
return { error: error.message };
|
| 489 |
}
|
| 490 |
+
}*/
|
| 491 |
|
| 492 |
|
| 493 |
// Fungsi untuk mengkonversi video dari YouTube
|