jhj0517 commited on
Commit
2d3dbbe
·
unverified ·
2 Parent(s): 4380a92 f57fb14

Merge pull request #305 from jhj0517/fix/youtube-pipeline

Browse files
modules/utils/youtube_manager.py CHANGED
@@ -1,4 +1,5 @@
1
  from pytubefix import YouTube
 
2
  import os
3
 
4
 
@@ -12,4 +13,21 @@ def get_ytmetas(link):
12
 
13
 
14
  def get_ytaudio(ytdata: YouTube):
15
- return ytdata.streams.get_audio_only().download(filename=os.path.join("modules", "yt_tmp.wav"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from pytubefix import YouTube
2
+ import subprocess
3
  import os
4
 
5
 
 
13
 
14
 
15
  def get_ytaudio(ytdata: YouTube):
16
+ # Somehow the audio is corrupted so need to convert to valid audio file.
17
+ # Fix for : https://github.com/jhj0517/Whisper-WebUI/issues/304
18
+
19
+ audio_path = ytdata.streams.get_audio_only().download(filename=os.path.join("modules", "yt_tmp.wav"))
20
+ temp_audio_path = os.path.join("modules", "yt_tmp_fixed.wav")
21
+
22
+ try:
23
+ subprocess.run([
24
+ 'ffmpeg', '-y',
25
+ '-i', audio_path,
26
+ temp_audio_path
27
+ ], check=True)
28
+
29
+ os.replace(temp_audio_path, audio_path)
30
+ return audio_path
31
+ except subprocess.CalledProcessError as e:
32
+ print(f"Error during ffmpeg conversion: {e}")
33
+ return None
modules/whisper/whisper_base.py CHANGED
@@ -356,6 +356,9 @@ class WhisperBase(ABC):
356
  )
357
  result_str = f"Done in {self.format_time(time_for_task)}! Subtitle file is in the outputs folder.\n\n{subtitle}"
358
 
 
 
 
359
  return [result_str, result_file_path]
360
 
361
  except Exception as e:
 
356
  )
357
  result_str = f"Done in {self.format_time(time_for_task)}! Subtitle file is in the outputs folder.\n\n{subtitle}"
358
 
359
+ if os.path.exists(audio):
360
+ os.remove(audio)
361
+
362
  return [result_str, result_file_path]
363
 
364
  except Exception as e: