Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,202 +1,58 @@
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
-
import os
|
4 |
-
import json
|
5 |
-
from typing import List, Optional
|
6 |
|
7 |
-
|
8 |
-
|
9 |
try:
|
10 |
-
|
11 |
-
|
|
|
|
|
12 |
except Exception as e:
|
13 |
-
return
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
command
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
"""
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
#
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
if time_range:
|
53 |
-
start, end = time_range.split("-")
|
54 |
-
command.extend([
|
55 |
-
"--external-downloader", "ffmpeg",
|
56 |
-
"--external-downloader-args", f"ffmpeg_i:-ss {start} -to {end}"
|
57 |
-
])
|
58 |
-
if download_archive:
|
59 |
-
command.extend(["--download-archive", os.path.join(output_dir, "downloaded.txt")])
|
60 |
-
if rate_limit:
|
61 |
-
command.extend(["--rate-limit", rate_limit])
|
62 |
-
|
63 |
-
command.append(url)
|
64 |
-
return run_ytdlp_command(command)
|
65 |
-
|
66 |
-
def download_transcript(url: str, output_dir: str, format: str = "srt") -> str:
|
67 |
-
"""Download video transcript."""
|
68 |
-
command = [
|
69 |
-
"yt-dlp",
|
70 |
-
"--write-auto-subs",
|
71 |
-
"--sub-lang", "en",
|
72 |
-
"--skip-download",
|
73 |
-
"--convert-subs", format,
|
74 |
-
"-o", os.path.join(output_dir, "%(title)s.%(ext)s"),
|
75 |
-
url
|
76 |
-
]
|
77 |
-
return run_ytdlp_command(command)
|
78 |
-
|
79 |
-
def download_info_json(url: str, output_dir: str) -> str:
|
80 |
-
"""Download video information as JSON."""
|
81 |
-
command = [
|
82 |
-
"yt-dlp",
|
83 |
-
"--write-info-json",
|
84 |
-
"--skip-download",
|
85 |
-
"-o", os.path.join(output_dir, "%(title)s.json"),
|
86 |
-
url
|
87 |
-
]
|
88 |
-
return run_ytdlp_command(command)
|
89 |
-
|
90 |
-
def create_interface():
|
91 |
-
with gr.Blocks(title="YT-DLP GUI") as app:
|
92 |
-
gr.Markdown("# YT-DLP Graphical Interface")
|
93 |
-
|
94 |
-
with gr.Tab("Basic Download"):
|
95 |
-
url_input = gr.Textbox(label="URL")
|
96 |
-
output_dir = gr.Textbox(label="Output Directory", value="downloads")
|
97 |
-
|
98 |
-
with gr.Row():
|
99 |
-
audio_format = gr.Dropdown(
|
100 |
-
choices=["mp3", "opus", "m4a", "wav"],
|
101 |
-
value="mp3",
|
102 |
-
label="Audio Format"
|
103 |
-
)
|
104 |
-
audio_quality = gr.Dropdown(
|
105 |
-
choices=["320k", "256k", "192k", "128k"],
|
106 |
-
value="320k",
|
107 |
-
label="Audio Quality"
|
108 |
-
)
|
109 |
-
|
110 |
-
with gr.Row():
|
111 |
-
extract_metadata = gr.Checkbox(label="Extract Metadata", value=True)
|
112 |
-
embed_thumbnail = gr.Checkbox(label="Embed Thumbnail", value=True)
|
113 |
-
|
114 |
-
download_btn = gr.Button("Download")
|
115 |
-
output = gr.Textbox(label="Output", lines=5)
|
116 |
-
|
117 |
-
download_btn.click(
|
118 |
-
download_audio,
|
119 |
-
inputs=[
|
120 |
-
url_input,
|
121 |
-
output_dir,
|
122 |
-
audio_format,
|
123 |
-
audio_quality,
|
124 |
-
extract_metadata,
|
125 |
-
embed_thumbnail
|
126 |
-
],
|
127 |
-
outputs=output
|
128 |
-
)
|
129 |
-
|
130 |
-
with gr.Tab("Advanced Options"):
|
131 |
-
adv_url = gr.Textbox(label="URL")
|
132 |
-
adv_output_dir = gr.Textbox(label="Output Directory", value="downloads")
|
133 |
-
|
134 |
-
with gr.Row():
|
135 |
-
playlist_items = gr.Textbox(label="Playlist Items (e.g., 1-5)")
|
136 |
-
rate_limit = gr.Textbox(label="Rate Limit (e.g., 1M)")
|
137 |
-
|
138 |
-
with gr.Row():
|
139 |
-
split_chapters = gr.Checkbox(label="Split by Chapters")
|
140 |
-
use_archive = gr.Checkbox(label="Use Download Archive")
|
141 |
-
|
142 |
-
time_range = gr.Textbox(label="Time Range (e.g., 00:01:00-00:05:00)")
|
143 |
-
|
144 |
-
adv_download_btn = gr.Button("Download with Advanced Options")
|
145 |
-
adv_output = gr.Textbox(label="Output", lines=5)
|
146 |
-
|
147 |
-
adv_download_btn.click(
|
148 |
-
download_audio,
|
149 |
-
inputs=[
|
150 |
-
adv_url,
|
151 |
-
adv_output_dir,
|
152 |
-
"mp3", # fixed format for simplicity
|
153 |
-
"320k", # fixed quality for simplicity
|
154 |
-
True, # always extract metadata
|
155 |
-
True, # always embed thumbnail
|
156 |
-
playlist_items,
|
157 |
-
split_chapters,
|
158 |
-
time_range,
|
159 |
-
use_archive,
|
160 |
-
rate_limit
|
161 |
-
],
|
162 |
-
outputs=adv_output
|
163 |
-
)
|
164 |
-
|
165 |
-
with gr.Tab("Format Info"):
|
166 |
-
format_url = gr.Textbox(label="URL")
|
167 |
-
format_btn = gr.Button("Get Available Formats")
|
168 |
-
format_output = gr.Textbox(label="Available Formats", lines=10)
|
169 |
-
|
170 |
-
format_btn.click(
|
171 |
-
get_available_formats,
|
172 |
-
inputs=format_url,
|
173 |
-
outputs=format_output
|
174 |
-
)
|
175 |
-
|
176 |
-
with gr.Tab("Extras"):
|
177 |
-
extra_url = gr.Textbox(label="URL")
|
178 |
-
extra_output_dir = gr.Textbox(label="Output Directory", value="downloads")
|
179 |
-
|
180 |
-
with gr.Row():
|
181 |
-
transcript_btn = gr.Button("Download Transcript")
|
182 |
-
info_json_btn = gr.Button("Download Info JSON")
|
183 |
-
|
184 |
-
extra_output = gr.Textbox(label="Output", lines=5)
|
185 |
-
|
186 |
-
transcript_btn.click(
|
187 |
-
download_transcript,
|
188 |
-
inputs=[extra_url, extra_output_dir],
|
189 |
-
outputs=extra_output
|
190 |
-
)
|
191 |
-
|
192 |
-
info_json_btn.click(
|
193 |
-
download_info_json,
|
194 |
-
inputs=[extra_url, extra_output_dir],
|
195 |
-
outputs=extra_output
|
196 |
-
)
|
197 |
-
|
198 |
-
return app
|
199 |
-
|
200 |
if __name__ == "__main__":
|
201 |
-
app =
|
202 |
-
app.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
|
|
|
|
|
|
3 |
|
4 |
+
# Command execution function
|
5 |
+
def run_command(command, url):
|
6 |
try:
|
7 |
+
# Replace placeholders like VIDEO_URL, PLAYLIST_URL, etc. with the actual URL
|
8 |
+
command = command.replace("VIDEO_URL", url).replace("SOUNDCLOUD_TRACK_URL", url).replace("PLAYLIST_URL", url)
|
9 |
+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
10 |
+
return result.stdout + "\n" + result.stderr
|
11 |
except Exception as e:
|
12 |
+
return str(e)
|
13 |
+
|
14 |
+
# Function to handle commands
|
15 |
+
def yt_dlp_handler(command, url):
|
16 |
+
return run_command(command, url)
|
17 |
+
|
18 |
+
# Available commands dictionary
|
19 |
+
commands = {
|
20 |
+
"List Available Formats": "yt-dlp -F VIDEO_URL",
|
21 |
+
"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",
|
22 |
+
"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",
|
23 |
+
"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",
|
24 |
+
"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",
|
25 |
+
"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",
|
26 |
+
"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",
|
27 |
+
"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",
|
28 |
+
"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",
|
29 |
+
"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",
|
30 |
+
"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",
|
31 |
+
"Update Metadata of Existing Files": "yt-dlp --download-archive \"P:/Local Music/downloaded.txt\" --skip-download --embed-metadata --embed-thumbnail --write-description VIDEO_URL",
|
32 |
+
"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",
|
33 |
+
"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",
|
34 |
+
"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",
|
35 |
+
"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",
|
36 |
+
"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",
|
37 |
+
"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",
|
38 |
+
"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"
|
39 |
+
}
|
40 |
+
|
41 |
+
# Create Gradio Interface
|
42 |
+
def create_app():
|
43 |
+
command_dropdown = gr.Dropdown(choices=list(commands.keys()), label="Select YT-DLP Command")
|
44 |
+
url_input = gr.Textbox(lines=1, placeholder="Enter Video/Playlist URL", label="URL")
|
45 |
+
output_textbox = gr.Textbox(label="Command Output")
|
46 |
|
47 |
+
# Interface
|
48 |
+
interface = gr.Interface(fn=yt_dlp_handler, inputs=[command_dropdown, url_input], outputs=output_textbox, live=False,
|
49 |
+
title="YT-DLP Command Executor",
|
50 |
+
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.",
|
51 |
+
theme="default",
|
52 |
+
layout="vertical")
|
53 |
+
return interface
|
54 |
+
|
55 |
+
# Launch the App
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
if __name__ == "__main__":
|
57 |
+
app = create_app()
|
58 |
+
app.launch(share=True, server_name="0.0.0.0", server_port=7860, debug=True)
|