print("please wait...") import gradio as gr import yt_dlp def download_media(url, download_video): if download_video: ydl_opts = { 'format': 'bestvideo+bestaudio/best', 'preferredcodec': 'mp4', 'outtmpl': 'downloads/%(title)s.%(ext)s', } else: ydl_opts = { 'format': 'bestaudio/best', 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': '192', }], 'outtmpl': 'downloads/%(title)s.%(ext)s', } with yt_dlp.YoutubeDL(ydl_opts) as ydl: info_dict = ydl.extract_info(url, download=True) file_title = ydl.prepare_filename(info_dict) if download_video: output_file = file_title else: output_file = file_title.rsplit('.', 1)[0] + '.mp3' return output_file def get_output_component(download_video): if download_video: return gr.Video(label="Downloaded Media") else: return gr.Audio(label="Downloaded Media") # Create the Gradio interface with gr.Blocks(theme=gr.themes.Soft(primary_hue="orange", secondary_hue="orange")) as demo: gr.Markdown(f"#