add download video/audio base

#1
Files changed (1) hide show
  1. app.py +39 -0
app.py CHANGED
@@ -449,6 +449,45 @@ h1{text-align:center}
449
  }
450
  """
451
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
452
 
453
  with gr.Blocks(theme=theme, css=css) as interface:
454
  gr.Markdown(
 
449
  }
450
  """
451
 
452
+ # you can add import yt_dlp manualy
453
+
454
+
455
+
456
+ def yt_download(link, download_video=True):
457
+ if video:
458
+ ydl_opts = {
459
+ 'format': 'bestvideo+bestaudio/best',
460
+ 'outtmpl': '%(title)s.%(ext)s',
461
+ 'nocheckcertificate': True,
462
+ 'ignoreerrors': True,
463
+ 'no_warnings': True,
464
+ 'quiet': True,
465
+ 'postprocessors': [{
466
+ 'key': 'FFmpegVideoConvertor',
467
+ 'preferedformat': 'mp4',
468
+ }]
469
+ }
470
+ else:
471
+ ydl_opts = {
472
+ 'format': 'bestaudio',
473
+ 'outtmpl': '%(title)s.%(ext)s',
474
+ 'nocheckcertificate': True,
475
+ 'ignoreerrors': True,
476
+ 'no_warnings': True,
477
+ 'quiet': True,
478
+ 'postprocessors': [{
479
+ 'key': 'FFmpegExtractAudio',
480
+ 'preferredcodec': 'mp3',
481
+ }]
482
+ }
483
+
484
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
485
+ result = ydl.extract_info(link, download=True)
486
+ download_path = ydl.prepare_filename(result)
487
+
488
+ return download_path
489
+
490
+
491
 
492
  with gr.Blocks(theme=theme, css=css) as interface:
493
  gr.Markdown(