Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -76,35 +76,35 @@ def prepare_media(source_path_or_url: os.PathLike,
|
|
76 |
# os.remove(mp4_file)
|
77 |
# except Exception as e:
|
78 |
# try:
|
79 |
-
try:
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
except Exception as e:
|
106 |
-
|
107 |
-
|
108 |
else:
|
109 |
raise ValueError(source_type)
|
110 |
|
|
|
76 |
# os.remove(mp4_file)
|
77 |
# except Exception as e:
|
78 |
# try:
|
79 |
+
# try:
|
80 |
+
with open(log_file, 'w') as lf:
|
81 |
+
# Try alternative
|
82 |
+
print(f"Failed with PyTube, error: {e}. Trying yt-dlp...")
|
83 |
+
audio_file = './downloaded/yt_audio'
|
84 |
+
# subprocess.run(['yt-dlp', '-x', source_path_or_url, '-f', 'bestaudio',
|
85 |
+
# '-o', audio_file, '--audio-format', 'mp3', '--restrict-filenames',
|
86 |
+
# '--force-overwrites', '--cookies', 'amt/src/extras/c.txt'])
|
87 |
+
# subprocess.run(['yt-dlp', '-x', source_path_or_url, '-f', 'bestaudio',
|
88 |
+
# '-o', audio_file, '--audio-format', 'mp3', '--restrict-filenames',
|
89 |
+
# '--force-overwrites', '--cookies', 'amt/src/extras/c.txt'])
|
90 |
+
command = ['yt-dlp', '-x', source_path_or_url, '-f', 'bestaudio',
|
91 |
+
'-o', audio_file, '--audio-format', 'mp3', '--restrict-filenames',
|
92 |
+
'--force-overwrites', '--username', 'oauth2', '--password', '', '-v']
|
93 |
+
if simulate:
|
94 |
+
command = command + ['-s']
|
95 |
+
process = subprocess.Popen(command,
|
96 |
+
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
97 |
+
|
98 |
+
for line in iter(process.stdout.readline, ''):
|
99 |
+
lf.write(line)
|
100 |
+
lf.flush()
|
101 |
+
process.stdout.close()
|
102 |
+
process.wait()
|
103 |
+
|
104 |
+
audio_file += '.mp3'
|
105 |
+
# except Exception as e:
|
106 |
+
# print(f"Alternative downloader failed, error: {e}. Please try again later!")
|
107 |
+
# return None
|
108 |
else:
|
109 |
raise ValueError(source_type)
|
110 |
|