Spaces:
Running
Running
jhj0517
commited on
Commit
·
a2455e3
1
Parent(s):
4380a92
Reformat audio after downloading
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
|