Nymbo's picture
Update app.py
6d5750d verified
raw
history blame
4.94 kB
import gradio as gr
import subprocess
# Command execution function
def run_command(command, url):
try:
# Replace placeholders like VIDEO_URL, PLAYLIST_URL, etc. with the actual URL
command = command.replace("VIDEO_URL", url).replace("SOUNDCLOUD_TRACK_URL", url).replace("PLAYLIST_URL", url)
result = subprocess.run(command, shell=True, capture_output=True, text=True)
return result.stdout + "\n" + result.stderr
except Exception as e:
return str(e)
# Function to handle commands
def yt_dlp_handler(command, url):
return run_command(command, url)
# Available commands dictionary
commands = {
"List Available Formats": "yt-dlp -F VIDEO_URL",
"Download MP3 at Max Quality": "yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --postprocessor-args \"-b:a 320k\" -o \"P:/Local Music/%(title)s.%(ext)s\" VIDEO_URL",
"Download High-Quality MP3": "yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o \"P:/Local Music/%(title)s.%(ext)s\" VIDEO_URL",
"Download Custom Bitrate": "yt-dlp -f bestaudio --extract-audio --audio-format mp3 --postprocessor-args \"-b:a 192k\" -o \"P:/Local Music/%(title)s.%(ext)s\" VIDEO_URL",
"Download and add Metadata Tags": "yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --embed-metadata -o \"P:/Local Music/%(title)s.%(ext)s\" VIDEO_URL",
"Download Entire Playlist": "yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o \"P:/Local Music/%(playlist_title)s/%(title)s.%(ext)s\" PLAYLIST_URL",
"Embed Album Art Automatically": "yt-dlp -f bestaudio --extract-audio --audio-format mp3 --embed-thumbnail --audio-quality 0 -o \"P:/Local Music/%(title)s.%(ext)s\" VIDEO_URL",
"Download Multiple Tracks from SoundCloud": "yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o \"P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s\" SOUNDCLOUD_TRACK_URL",
"Download Playlist (Specific Range)": "yt-dlp --playlist-items 1-5 -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o \"P:/Local Music/%(playlist_title)s/%(title)s.%(ext)s\" PLAYLIST_URL",
"Download and Split by Chapters": "yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --split-chapters -o \"P:/Local Music/%(title)s.%(ext)s\" VIDEO_URL",
"Extract Specific Portion of Video": "yt-dlp -f bestvideo+bestaudio --external-downloader ffmpeg --external-downloader-args \"ffmpeg_i:-ss 00:01:00 -to 00:05:00\" -o \"P:/Local Music/%(title)s.%(ext)s\" VIDEO_URL",
"Update Metadata of Existing Files": "yt-dlp --download-archive \"P:/Local Music/downloaded.txt\" --skip-download --embed-metadata --embed-thumbnail --write-description VIDEO_URL",
"Download YouTube Transcript as Text": "yt-dlp --write-auto-subs --sub-lang en --skip-download -o \"P:/Local Music/%(title)s.%(ext)s\" VIDEO_URL",
"Download YouTube Transcript as Markdown": "yt-dlp --write-auto-subs --sub-lang en --skip-download --convert-subs srt -o \"P:/Local Music/%(title)s.md\" VIDEO_URL",
"Download from Vimeo": "yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o \"P:/Local Music/Vimeo/%(uploader)s - %(title)s.%(ext)s\" VIDEO_URL",
"Download from Instagram": "yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o \"P:/Local Music/Instagram/%(uploader)s - %(title)s.%(ext)s\" VIDEO_URL",
"Download from Twitter": "yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o \"P:/Local Music/Twitter/%(uploader)s - %(title)s.%(ext)s\" VIDEO_URL",
"Download from TikTok": "yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o \"P:/Local Music/TikTok/%(uploader)s - %(title)s.%(ext)s\" VIDEO_URL",
"Download from Dailymotion": "yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o \"P:/Local Music/Dailymotion/%(uploader)s - %(title)s.%(ext)s\" VIDEO_URL"
}
# Create Gradio Interface
def create_app():
command_dropdown = gr.Dropdown(choices=list(commands.keys()), label="Select YT-DLP Command")
url_input = gr.Textbox(lines=1, placeholder="Enter Video/Playlist URL", label="URL")
output_textbox = gr.Textbox(label="Command Output")
# Interface
interface = gr.Interface(fn=yt_dlp_handler, inputs=[command_dropdown, url_input], outputs=output_textbox, live=False,
title="YT-DLP Command Executor",
description="Use this app to run various YT-DLP commands without using the command line. Select a command, provide the URL, and hit Submit to run the command.",
theme="default",
layout="vertical")
return interface
# Launch the App
if __name__ == "__main__":
app = create_app()
app.launch(share=True, server_name="0.0.0.0", server_port=7860, debug=True)