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

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +14 -1
index.js CHANGED
@@ -353,15 +353,27 @@ async function getAudioMP3Url(videoUrl) {
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
@@ -407,6 +419,7 @@ async function getAudioMP3Url(videoUrl) {
407
 
408
 
409
 
 
410
  app.get('/ytmp3', async (req, res) => {
411
  try {
412
  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 valid
357
  if (!fs.existsSync(path_audio)) {
358
  throw new Error('File audio tidak ditemukan setelah diunduh.');
359
  }
360
+ if (fs.statSync(path_audio).size === 0) {
361
+ throw new Error('File audio kosong atau rusak.');
362
+ }
363
+
364
+ // Debugging tambahan: coba cek format file
365
+ console.log(`File audio diunduh: ${path_audio}, size: ${fs.statSync(path_audio).size} bytes`);
366
 
367
  // Tambahkan metadata ke file yang diunduh
368
  await new Promise((resolve, reject) => {
369
  ffmpeg(path_audio)
370
  .outputOptions(['-acodec libmp3lame', '-ab 128k', '-ar 44100'])
371
+ .on('start', (commandLine) => {
372
+ console.log('FFmpeg command:', commandLine); // Log perintah FFmpeg
373
+ })
374
+ .on('stderr', (stderrLine) => {
375
+ console.error('FFmpeg stderr:', stderrLine); // Log error FFmpeg
376
+ })
377
  .on('end', async () => {
378
  try {
379
  // Tambahkan metadata
 
419
 
420
 
421
 
422
+
423
  app.get('/ytmp3', async (req, res) => {
424
  try {
425
  const { url } = req.query;