Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -322,44 +322,40 @@ button:hover {
|
|
| 322 |
}
|
| 323 |
"""
|
| 324 |
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
raise ValueError("Invalid or missing URL.")
|
| 329 |
-
|
| 330 |
-
if os.path.exists(out_dir):
|
| 331 |
-
shutil.rmtree(out_dir)
|
| 332 |
-
os.makedirs(out_dir, exist_ok=True)
|
| 333 |
-
|
| 334 |
ydl_opts = {
|
| 335 |
-
'format': 'bestaudio/best
|
| 336 |
-
'postprocessors': [{
|
| 337 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
|
| 339 |
'geo_bypass': True,
|
| 340 |
'force_ipv4': True,
|
| 341 |
'referer': 'https://www.youtube.com/',
|
| 342 |
'noplaylist': True,
|
| 343 |
-
'cookiefile':
|
| 344 |
'extractor_retries': 5,
|
| 345 |
'ignoreerrors': False,
|
| 346 |
'no_check_certificate': True,
|
| 347 |
'verbose': True,
|
| 348 |
}
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
logger.error(f"Download failed: {e}")
|
| 362 |
-
raise RuntimeError(f"Download failed: {e}")
|
| 363 |
|
| 364 |
@spaces.GPU
|
| 365 |
def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, pitch_shift, model_dir, output_dir, out_format, norm_thresh, amp_thresh, batch_size, exclude_stems="", progress=gr.Progress(track_tqdm=True)):
|
|
|
|
| 322 |
}
|
| 323 |
"""
|
| 324 |
|
| 325 |
+
import yt_dlp
|
| 326 |
+
|
| 327 |
+
def download_audio(url, download_type, cookie_file):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
ydl_opts = {
|
| 329 |
+
'format': 'bestaudio/best',
|
| 330 |
+
'postprocessors': [{
|
| 331 |
+
'key': 'FFmpegExtractAudio',
|
| 332 |
+
'preferredcodec': 'wav',
|
| 333 |
+
'preferredquality': '192',
|
| 334 |
+
}],
|
| 335 |
+
'outtmpl': 'ytdl/%(title)s.%(ext)s',
|
| 336 |
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
|
| 337 |
'geo_bypass': True,
|
| 338 |
'force_ipv4': True,
|
| 339 |
'referer': 'https://www.youtube.com/',
|
| 340 |
'noplaylist': True,
|
| 341 |
+
'cookiefile': cookie_file.name if cookie_file else None,
|
| 342 |
'extractor_retries': 5,
|
| 343 |
'ignoreerrors': False,
|
| 344 |
'no_check_certificate': True,
|
| 345 |
'verbose': True,
|
| 346 |
}
|
| 347 |
+
|
| 348 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 349 |
+
try:
|
| 350 |
+
info_dict = ydl.extract_info(url, download=True)
|
| 351 |
+
file_path = ydl.prepare_filename(info_dict)
|
| 352 |
+
return file_path, "Download successful", None, None, None, None
|
| 353 |
+
except yt_dlp.utils.ExtractorError as e:
|
| 354 |
+
if "Sign in to confirm you’re not a bot" in str(e):
|
| 355 |
+
return None, "Authentication failed. Please upload updated cookies from a logged-in browser session.", None, None, None, None
|
| 356 |
+
return None, f"Download failed: {str(e)}", None, None, None, None
|
| 357 |
+
except Exception as e:
|
| 358 |
+
return None, f"Unexpected error: {str(e)}", None, None, None, None
|
|
|
|
|
|
|
| 359 |
|
| 360 |
@spaces.GPU
|
| 361 |
def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, pitch_shift, model_dir, output_dir, out_format, norm_thresh, amp_thresh, batch_size, exclude_stems="", progress=gr.Progress(track_tqdm=True)):
|