Spaces:
Running
Running
Merge branch 'master' of https://github.com/jhj0517/Whisper-WebUI into feature/add-tests
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
@@ -361,6 +361,9 @@ class WhisperBase(ABC):
|
|
| 361 |
)
|
| 362 |
result_str = f"Done in {self.format_time(time_for_task)}! Subtitle file is in the outputs folder.\n\n{subtitle}"
|
| 363 |
|
|
|
|
|
|
|
|
|
|
| 364 |
return [result_str, result_file_path]
|
| 365 |
|
| 366 |
except Exception as e:
|
|
|
|
| 361 |
)
|
| 362 |
result_str = f"Done in {self.format_time(time_for_task)}! Subtitle file is in the outputs folder.\n\n{subtitle}"
|
| 363 |
|
| 364 |
+
if os.path.exists(audio):
|
| 365 |
+
os.remove(audio)
|
| 366 |
+
|
| 367 |
return [result_str, result_file_path]
|
| 368 |
|
| 369 |
except Exception as e:
|