Closure-RI commited on
Commit
28134e3
·
verified ·
1 Parent(s): f038e00

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +11 -6
index.js CHANGED
@@ -353,21 +353,25 @@ async function getAudioMP3Url(videoUrl) {
353
  const response = await axios.get(video.url, { responseType: 'arraybuffer' });
354
  fs.writeFileSync(path_audio, response.data);
355
 
 
 
 
 
 
356
  // Tambahkan metadata ke file yang diunduh
357
  await new Promise((resolve, reject) => {
358
  ffmpeg(path_audio)
359
- .outputOptions('-acodec', 'libmp3lame', '-ab', '128k', '-ar', '44100')
360
  .on('end', async () => {
361
  try {
362
  // Tambahkan metadata
363
- const buffer = fs.readFileSync(path_audio);
364
  const edited = await addAudioTags(buffer, infoVids.title, infoVids.channelTitle, 2024, infoVids.thumbnail);
365
 
366
  // Ganti file lama dengan file yang sudah diedit
367
  const buffer2 = fs.readFileSync(edited.path);
368
- fs.writeFileSync(path_audio_edit, buffer2);
369
- fs.unlinkSync(path_audio); // Hapus file lama
370
- fs.renameSync(path_audio_edit, path_audio); // Rename menjadi file asli
371
 
372
  resolve();
373
  } catch (error) {
@@ -394,7 +398,7 @@ async function getAudioMP3Url(videoUrl) {
394
  };
395
  } catch (error) {
396
  console.error('Error:', error);
397
- throw new Error('Failed to process audio URL :\n\n' + error);
398
  }
399
  }
400
 
@@ -402,6 +406,7 @@ async function getAudioMP3Url(videoUrl) {
402
 
403
 
404
 
 
405
  app.get('/ytmp3', async (req, res) => {
406
  try {
407
  const { url } = req.query;
 
353
  const response = await axios.get(video.url, { responseType: 'arraybuffer' });
354
  fs.writeFileSync(path_audio, response.data);
355
 
356
+ // Periksa apakah file input ada
357
+ if (!fs.existsSync(path_audio)) {
358
+ throw new Error('File audio tidak ditemukan setelah diunduh.');
359
+ }
360
+
361
  // Tambahkan metadata ke file yang diunduh
362
  await new Promise((resolve, reject) => {
363
  ffmpeg(path_audio)
364
+ .outputOptions(['-acodec libmp3lame', '-ab 128k', '-ar 44100'])
365
  .on('end', async () => {
366
  try {
367
  // Tambahkan metadata
368
+ const buffer = fs.readFileSync(path_audio_edit); // Ambil file hasil edit
369
  const edited = await addAudioTags(buffer, infoVids.title, infoVids.channelTitle, 2024, infoVids.thumbnail);
370
 
371
  // Ganti file lama dengan file yang sudah diedit
372
  const buffer2 = fs.readFileSync(edited.path);
373
+ fs.writeFileSync(path_audio, buffer2);
374
+ fs.unlinkSync(path_audio_edit); // Hapus file sementara
 
375
 
376
  resolve();
377
  } catch (error) {
 
398
  };
399
  } catch (error) {
400
  console.error('Error:', error);
401
+ throw new Error('Failed to process audio URL');
402
  }
403
  }
404
 
 
406
 
407
 
408
 
409
+
410
  app.get('/ytmp3', async (req, res) => {
411
  try {
412
  const { url } = req.query;