Nymbo's picture
Update app.py
9340a56 verified
raw
history blame
6.55 kB
import gradio as gr
import subprocess
import os
# Function to run yt-dlp commands
def run_yt_dlp(command, url, output_path, bitrate=None, start_time=None, end_time=None, playlist_items=None, archive_file=None):
base_command = ["yt-dlp", "-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "-o", output_path]
if command == "list_formats":
base_command = ["yt-dlp", "-F", url]
elif command == "download_mp3_max_quality":
base_command.extend(["--postprocessor-args", "-b:a 320k", url])
elif command == "basic_high_quality_mp3":
base_command.append(url)
elif command == "custom_bitrate":
base_command.extend(["--postprocessor-args", f"-b:a {bitrate}k", url])
elif command == "add_metadata_tags":
base_command.extend(["--embed-metadata", url])
elif command == "download_playlist":
base_command.append(url)
elif command == "download_playlist_range":
base_command.extend(["--playlist-items", playlist_items, url])
elif command == "download_hq_soundcloud":
base_command.extend(["-o", "P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s", url])
elif command == "embed_album_art":
base_command.extend(["--embed-thumbnail", url])
elif command == "download_opus":
base_command.extend(["--audio-format", "opus", url])
elif command == "skip_downloaded_files":
base_command.extend(["--download-archive", archive_file, url])
elif command == "download_multiple_files":
base_command.extend(url.split())
elif command == "download_split_chapters":
base_command.extend(["--split-chapters", url])
elif command == "extract_portion":
base_command.extend(["-f", "bestvideo+bestaudio", "--external-downloader", "ffmpeg", "--external-downloader-args", f"ffmpeg_i:-ss {start_time} -to {end_time}", url])
elif command == "update_metadata":
base_command.extend(["--download-archive", archive_file, "--skip-download", "--embed-metadata", "--embed-thumbnail", url])
elif command == "auto_rename":
base_command.extend(["--force-overwrites", url])
elif command == "download_url_list":
base_command.extend(["-a", url])
elif command == "limit_speed":
base_command.extend(["--rate-limit", "1M", url])
elif command == "download_vimeo":
base_command.extend(["-o", "P:/Local Music/Vimeo/%(uploader)s - %(title)s.%(ext)s", url])
elif command == "download_facebook":
base_command.extend(["-o", "P:/Local Music/Facebook/%(uploader)s - %(title)s.%(ext)s", url])
elif command == "download_instagram":
base_command.extend(["-o", "P:/Local Music/Instagram/%(uploader)s - %(title)s.%(ext)s", url])
elif command == "download_twitter":
base_command.extend(["-o", "P:/Local Music/Twitter/%(uploader)s - %(title)s.%(ext)s", url])
elif command == "download_tiktok":
base_command.extend(["-o", "P:/Local Music/TikTok/%(uploader)s - %(title)s.%(ext)s", url])
elif command == "download_reddit":
base_command.extend(["-o", "P:/Local Music/Reddit/%(uploader)s - %(title)s.%(ext)s", url])
elif command == "download_dailymotion":
base_command.extend(["-o", "P:/Local Music/Dailymotion/%(uploader)s - %(title)s.%(ext)s", url])
elif command == "download_transcript_text":
base_command.extend(["--write-auto-subs", "--sub-lang", "en", "--skip-download", url])
elif command == "download_transcript_markdown":
base_command.extend(["--write-auto-subs", "--sub-lang", "en", "--skip-download", "--convert-subs", "srt", "-o", "P:/Local Music/%(title)s.md", url])
elif command == "download_video_info":
base_command.extend(["--write-info-json", "--skip-download", "-o", "P:/Local Music/%(title)s.json", url])
elif command == "list_formats_no_download":
base_command = ["yt-dlp", "-F", url]
elif command == "download_age_restricted":
base_command.extend(["--username", "YOUR_YOUTUBE_EMAIL", "--password", "YOUR_PASSWORD", "-f", "bestvideo+bestaudio", url])
try:
result = subprocess.run(base_command, capture_output=True, text=True)
return result.stdout
except Exception as e:
return str(e)
# Gradio Interface
with gr.Blocks() as demo:
gr.Markdown("# yt-dlp Command Executor")
with gr.Row():
command = gr.Dropdown(choices=[
"list_formats",
"download_mp3_max_quality",
"basic_high_quality_mp3",
"custom_bitrate",
"add_metadata_tags",
"download_playlist",
"download_playlist_range",
"download_hq_soundcloud",
"embed_album_art",
"download_opus",
"skip_downloaded_files",
"download_multiple_files",
"download_split_chapters",
"extract_portion",
"update_metadata",
"auto_rename",
"download_url_list",
"limit_speed",
"download_vimeo",
"download_facebook",
"download_instagram",
"download_twitter",
"download_tiktok",
"download_reddit",
"download_dailymotion",
"download_transcript_text",
"download_transcript_markdown",
"download_video_info",
"list_formats_no_download",
"download_age_restricted"
], label="Command")
url = gr.Textbox(label="URL", placeholder="Enter the URL here")
with gr.Row():
output_path = gr.Textbox(label="Output Path", placeholder="Enter the output path here")
bitrate = gr.Textbox(label="Bitrate (for custom bitrate)", placeholder="Enter bitrate in kbps, e.g., 192")
start_time = gr.Textbox(label="Start Time (HH:MM:SS)", placeholder="Enter start time, e.g., 00:01:00")
end_time = gr.Textbox(label="End Time (HH:MM:SS)", placeholder="Enter end time, e.g., 00:05:00")
playlist_items = gr.Textbox(label="Playlist Items (e.g., 1-5)", placeholder="Enter range of items, e.g., 1-5")
archive_file = gr.Textbox(label="Archive File", placeholder="Enter path to archive file, e.g., P:/Local Music/downloaded.txt")
execute_button = gr.Button("Execute Command")
output = gr.Textbox(label="Output", lines=10)
execute_button.click(
fn=run_yt_dlp,
inputs=[command, url, output_path, bitrate, start_time, end_time, playlist_items, archive_file],
outputs=output
)
demo.launch()