Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,389 +1,85 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import
|
|
|
|
|
4 |
|
5 |
-
def
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
try:
|
10 |
-
# Use shlex to split the command for better security
|
11 |
-
result = subprocess.run(shlex.split(command), capture_output=True, text=True)
|
12 |
-
if result.stdout:
|
13 |
-
return result.stdout
|
14 |
-
elif result.stderr:
|
15 |
-
return result.stderr
|
16 |
-
else:
|
17 |
-
return "No output received."
|
18 |
-
except Exception as e:
|
19 |
-
return str(e)
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
26 |
|
27 |
-
#
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
]
|
42 |
-
"command": lambda url, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --postprocessor-args "-b:a 320k" -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
43 |
-
},
|
44 |
-
{
|
45 |
-
"title": "Basic High-Quality MP3 Download",
|
46 |
-
"inputs": [
|
47 |
-
gr.Textbox(label="Video URL", placeholder="Enter the video URL here"),
|
48 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.%(ext)s', value='P:/Local Music/%(title)s.%(ext)s')
|
49 |
-
],
|
50 |
-
"command": lambda url, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
51 |
-
},
|
52 |
-
{
|
53 |
-
"title": "Download Custom Bitrate",
|
54 |
-
"inputs": [
|
55 |
-
gr.Textbox(label="Video URL", placeholder="Enter the video URL here"),
|
56 |
-
gr.Textbox(label="Bitrate", placeholder='192k', value='192k'),
|
57 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.%(ext)s', value='P:/Local Music/%(title)s.%(ext)s')
|
58 |
-
],
|
59 |
-
"command": lambda url, bitrate, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --postprocessor-args "-b:a {escape_quotes(bitrate)}" -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
60 |
-
},
|
61 |
-
{
|
62 |
-
"title": "Download and Add Metadata Tags",
|
63 |
-
"inputs": [
|
64 |
-
gr.Textbox(label="Video URL", placeholder="Enter the video URL here"),
|
65 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.%(ext)s', value='P:/Local Music/%(title)s.%(ext)s')
|
66 |
-
],
|
67 |
-
"command": lambda url, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --embed-metadata -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
68 |
-
},
|
69 |
-
{
|
70 |
-
"title": "Download Entire Playlist",
|
71 |
-
"inputs": [
|
72 |
-
gr.Textbox(label="Playlist URL", placeholder="Enter the playlist URL here"),
|
73 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(playlist_title)s/%(title)s.%(ext)s', value='P:/Local Music/%(playlist_title)s/%(title)s.%(ext)s')
|
74 |
-
],
|
75 |
-
"command": lambda url, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
76 |
-
},
|
77 |
-
{
|
78 |
-
"title": "Download Playlist (Specific Range)",
|
79 |
-
"inputs": [
|
80 |
-
gr.Textbox(label="Playlist URL", placeholder="Enter the playlist URL here"),
|
81 |
-
gr.Textbox(label="Playlist Items", placeholder='e.g., 1-5', value='1-5'),
|
82 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(playlist_title)s/%(title)s.%(ext)s', value='P:/Local Music/%(playlist_title)s/%(title)s.%(ext)s')
|
83 |
-
],
|
84 |
-
"command": lambda url, items, path: f'yt-dlp --playlist-items {escape_quotes(items)} -f bestaudio --extract-audio --audio-format mp3 -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
85 |
-
},
|
86 |
-
{
|
87 |
-
"title": "Embed Album Art Automatically",
|
88 |
-
"inputs": [
|
89 |
-
gr.Textbox(label="Video URL", placeholder="Enter the video URL here"),
|
90 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.%(ext)s', value='P:/Local Music/%(title)s.%(ext)s')
|
91 |
-
],
|
92 |
-
"command": lambda url, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --embed-thumbnail --audio-quality 0 -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
93 |
-
},
|
94 |
-
{
|
95 |
-
"title": "Download Specific Formats (Opus)",
|
96 |
-
"inputs": [
|
97 |
-
gr.Textbox(label="Video URL", placeholder="Enter the video URL here"),
|
98 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.%(ext)s', value='P:/Local Music/%(title)s.%(ext)s')
|
99 |
-
],
|
100 |
-
"command": lambda url, path: f'yt-dlp -f bestaudio --extract-audio --audio-format opus -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
101 |
-
},
|
102 |
-
{
|
103 |
-
"title": "Skip Already Downloaded Files",
|
104 |
-
"inputs": [
|
105 |
-
gr.Textbox(label="Video URL", placeholder="Enter the video URL here"),
|
106 |
-
gr.Textbox(label="Download Archive Path", placeholder='P:/Local Music/downloaded.txt', value='P:/Local Music/downloaded.txt'),
|
107 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.%(ext)s', value='P:/Local Music/%(title)s.%(ext)s')
|
108 |
-
],
|
109 |
-
"command": lambda url, archive, path: f'yt-dlp --download-archive "{escape_quotes(archive)}" -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
110 |
-
},
|
111 |
-
{
|
112 |
-
"title": "Download Multiple Individual Files",
|
113 |
-
"inputs": [
|
114 |
-
gr.Textbox(label="Video URLs", placeholder='Enter multiple URLs separated by spaces', lines=2),
|
115 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.%(ext)s', value='P:/Local Music/%(title)s.%(ext)s')
|
116 |
-
],
|
117 |
-
"command": lambda urls, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --add-metadata --embed-thumbnail --write-description --postprocessor-args "-b:a 320k" -o "{escape_quotes(path)}" {" ".join([f\'"{escape_quotes(url)}"\' for url in urls.split()])}'
|
118 |
-
},
|
119 |
-
{
|
120 |
-
"title": "Download and Automatically Split by Chapters",
|
121 |
-
"inputs": [
|
122 |
-
gr.Textbox(label="Video URL", placeholder="Enter the video URL here"),
|
123 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.%(ext)s', value='P:/Local Music/%(title)s.%(ext)s')
|
124 |
-
],
|
125 |
-
"command": lambda url, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --split-chapters -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
126 |
-
},
|
127 |
-
{
|
128 |
-
"title": "Extract Only a Portion of a Video (by Time)",
|
129 |
-
"inputs": [
|
130 |
-
gr.Textbox(label="Video URL", placeholder="Enter the video URL here"),
|
131 |
-
gr.Textbox(label="Start Time", placeholder='00:01:00', value='00:01:00'),
|
132 |
-
gr.Textbox(label="End Time", placeholder='00:05:00', value='00:05:00'),
|
133 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.%(ext)s', value='P:/Local Music/%(title)s.%(ext)s')
|
134 |
-
],
|
135 |
-
"command": lambda url, start, end, path: f'yt-dlp -f bestvideo+bestaudio --external-downloader ffmpeg --external-downloader-args "ffmpeg_i:-ss {escape_quotes(start)} -to {escape_quotes(end)}" -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
136 |
-
},
|
137 |
-
{
|
138 |
-
"title": "Update Metadata of Existing Files",
|
139 |
-
"inputs": [
|
140 |
-
gr.Textbox(label="Video URL", placeholder="Enter the video URL here"),
|
141 |
-
gr.Textbox(label="Download Archive Path", placeholder='P:/Local Music/downloaded.txt', value='P:/Local Music/downloaded.txt')
|
142 |
-
],
|
143 |
-
"command": lambda url, archive: f'yt-dlp --download-archive "{escape_quotes(archive)}" --skip-download --embed-metadata --embed-thumbnail --write-description "{escape_quotes(url)}"'
|
144 |
-
},
|
145 |
-
{
|
146 |
-
"title": "Auto-Rename Duplicate Files",
|
147 |
-
"inputs": [
|
148 |
-
gr.Textbox(label="Video URL", placeholder="Enter the video URL here"),
|
149 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.%(ext)s', value='P:/Local Music/%(title)s.%(ext)s')
|
150 |
-
],
|
151 |
-
"command": lambda url, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --force-overwrites -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
152 |
-
},
|
153 |
-
{
|
154 |
-
"title": "Download from a URL List File",
|
155 |
-
"inputs": [
|
156 |
-
gr.Textbox(label="URL List File Path", placeholder='P:/Local Music/urls.txt', value='P:/Local Music/urls.txt'),
|
157 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.%(ext)s', value='P:/Local Music/%(title)s.%(ext)s')
|
158 |
-
],
|
159 |
-
"command": lambda list_file, path: f'yt-dlp -a "{escape_quotes(list_file)}" -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "{escape_quotes(path)}"'
|
160 |
-
},
|
161 |
-
{
|
162 |
-
"title": "Download and Limit Download Speed",
|
163 |
-
"inputs": [
|
164 |
-
gr.Textbox(label="Video URL", placeholder="Enter the video URL here"),
|
165 |
-
gr.Textbox(label="Rate Limit", placeholder='1M', value='1M'),
|
166 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.%(ext)s', value='P:/Local Music/%(title)s.%(ext)s')
|
167 |
-
],
|
168 |
-
"command": lambda url, rate, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --rate-limit {escape_quotes(rate)} -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
169 |
-
},
|
170 |
-
{
|
171 |
-
"title": "Download YouTube Transcript as Text",
|
172 |
-
"inputs": [
|
173 |
-
gr.Textbox(label="Video URL", placeholder="Enter the video URL here"),
|
174 |
-
gr.Textbox(label="Subtitle Language", placeholder='en', value='en'),
|
175 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.%(ext)s', value='P:/Local Music/%(title)s.%(ext)s')
|
176 |
-
],
|
177 |
-
"command": lambda url, lang, path: f'yt-dlp --write-auto-subs --sub-lang {escape_quotes(lang)} --skip-download -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
178 |
-
},
|
179 |
-
{
|
180 |
-
"title": "Download YouTube Transcript as Markdown",
|
181 |
-
"inputs": [
|
182 |
-
gr.Textbox(label="Video URL", placeholder="Enter the video URL here"),
|
183 |
-
gr.Textbox(label="Subtitle Language", placeholder='en', value='en'),
|
184 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.md', value='P:/Local Music/%(title)s.md')
|
185 |
-
],
|
186 |
-
"command": lambda url, lang, path: f'yt-dlp --write-auto-subs --sub-lang {escape_quotes(lang)} --skip-download --convert-subs srt -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
187 |
-
},
|
188 |
-
{
|
189 |
-
"title": "Download Video Info and Save as JSON",
|
190 |
-
"inputs": [
|
191 |
-
gr.Textbox(label="Video URL", placeholder="Enter the video URL here"),
|
192 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.json', value='P:/Local Music/%(title)s.json')
|
193 |
-
],
|
194 |
-
"command": lambda url, path: f'yt-dlp --write-info-json --skip-download -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
195 |
-
},
|
196 |
-
{
|
197 |
-
"title": "Download from YouTube Age-Restricted Content",
|
198 |
-
"inputs": [
|
199 |
-
gr.Textbox(label="Age-Restricted Video URL", placeholder="Enter the video URL here"),
|
200 |
-
gr.Textbox(label="YouTube Email", placeholder="Enter your YouTube email"),
|
201 |
-
gr.Password(label="YouTube Password", placeholder="Enter your YouTube password"),
|
202 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/%(title)s.%(ext)s', value='P:/Local Music/%(title)s.%(ext)s')
|
203 |
-
],
|
204 |
-
"command": lambda url, email, password, path: f'yt-dlp --username "{escape_quotes(email)}" --password "{escape_quotes(password)}" -f bestvideo+bestaudio -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
205 |
-
},
|
206 |
-
]
|
207 |
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
]
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
"title": "Download High-Quality MP3 from SoundCloud",
|
218 |
-
"inputs": [
|
219 |
-
gr.Textbox(label="SoundCloud Track URL", placeholder="Enter the SoundCloud track URL here"),
|
220 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s', value='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s')
|
221 |
-
],
|
222 |
-
"command": lambda url, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
223 |
-
},
|
224 |
-
{
|
225 |
-
"title": "Download HQ with Metadata from SoundCloud",
|
226 |
-
"inputs": [
|
227 |
-
gr.Textbox(label="SoundCloud Track URL", placeholder="Enter the SoundCloud track URL here"),
|
228 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s', value='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s')
|
229 |
-
],
|
230 |
-
"command": lambda url, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --embed-metadata -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
231 |
-
},
|
232 |
-
{
|
233 |
-
"title": "Download Entire Playlist from SoundCloud",
|
234 |
-
"inputs": [
|
235 |
-
gr.Textbox(label="SoundCloud Playlist URL", placeholder="Enter the SoundCloud playlist URL here"),
|
236 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/SoundCloud/%(playlist_title)s/%(title)s.%(ext)s', value='P:/Local Music/SoundCloud/%(playlist_title)s/%(title)s.%(ext)s')
|
237 |
-
],
|
238 |
-
"command": lambda url, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
239 |
-
},
|
240 |
-
{
|
241 |
-
"title": "Download Entire Playlist from SoundCloud with Metadata",
|
242 |
-
"inputs": [
|
243 |
-
gr.Textbox(label="SoundCloud Playlist URL", placeholder="Enter the SoundCloud playlist URL here"),
|
244 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/SoundCloud/%(playlist_title)s/%(title)s.%(ext)s', value='P:/Local Music/SoundCloud/%(playlist_title)s/%(title)s.%(ext)s')
|
245 |
-
],
|
246 |
-
"command": lambda url, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --embed-metadata --add-metadata --embed-thumbnail -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
247 |
-
},
|
248 |
-
{
|
249 |
-
"title": "Download Multiple Playlists with Metadata",
|
250 |
-
"inputs": [
|
251 |
-
gr.Textbox(label="SoundCloud Playlist URLs", placeholder='Enter multiple playlist URLs separated by spaces', lines=2),
|
252 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/SoundCloud/%(playlist_title)s/%(title)s.%(ext)s', value='P:/Local Music/SoundCloud/%(playlist_title)s/%(title)s.%(ext)s')
|
253 |
-
],
|
254 |
-
"command": lambda urls, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --embed-metadata --add-metadata --embed-thumbnail -o "{escape_quotes(path)}" {" ".join([f\'"{escape_quotes(url)}"\' for url in urls.split()])}'
|
255 |
-
},
|
256 |
-
{
|
257 |
-
"title": "Download Playlist with Specific Range",
|
258 |
-
"inputs": [
|
259 |
-
gr.Textbox(label="SoundCloud Playlist URL", placeholder="Enter the SoundCloud playlist URL here"),
|
260 |
-
gr.Textbox(label="Playlist Items", placeholder='e.g., 1-5', value='1-5'),
|
261 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/SoundCloud/%(playlist_title)s/%(title)s.%(ext)s', value='P:/Local Music/SoundCloud/%(playlist_title)s/%(title)s.%(ext)s')
|
262 |
-
],
|
263 |
-
"command": lambda url, items, path: f'yt-dlp --playlist-items {escape_quotes(items)} -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
264 |
-
},
|
265 |
-
{
|
266 |
-
"title": "Download and Embed Album Art",
|
267 |
-
"inputs": [
|
268 |
-
gr.Textbox(label="SoundCloud Track URL", placeholder="Enter the SoundCloud track URL here"),
|
269 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s', value='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s')
|
270 |
-
],
|
271 |
-
"command": lambda url, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --embed-thumbnail -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
272 |
-
},
|
273 |
-
{
|
274 |
-
"title": "Skip Downloading Already Downloaded SoundCloud Files",
|
275 |
-
"inputs": [
|
276 |
-
gr.Textbox(label="SoundCloud Track URL", placeholder="Enter the SoundCloud track URL here"),
|
277 |
-
gr.Textbox(label="Download Archive Path", placeholder='P:/Local Music/downloaded_soundcloud.txt', value='P:/Local Music/downloaded_soundcloud.txt'),
|
278 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s', value='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s')
|
279 |
-
],
|
280 |
-
"command": lambda url, archive, path: f'yt-dlp --download-archive "{escape_quotes(archive)}" -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
281 |
-
},
|
282 |
-
{
|
283 |
-
"title": "Download Multiple Tracks from SoundCloud",
|
284 |
-
"inputs": [
|
285 |
-
gr.Textbox(label="SoundCloud Track URLs", placeholder='Enter multiple track URLs separated by spaces', lines=2),
|
286 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s', value='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s')
|
287 |
-
],
|
288 |
-
"command": lambda urls, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "{escape_quotes(path)}" {" ".join([f\'"{escape_quotes(url)}"\' for url in urls.split()])}'
|
289 |
-
},
|
290 |
-
{
|
291 |
-
"title": "Limit Download Speed for SoundCloud",
|
292 |
-
"inputs": [
|
293 |
-
gr.Textbox(label="SoundCloud Track URL", placeholder="Enter the SoundCloud track URL here"),
|
294 |
-
gr.Textbox(label="Rate Limit", placeholder='1M', value='1M'),
|
295 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s', value='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s')
|
296 |
-
],
|
297 |
-
"command": lambda url, rate, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --rate-limit {escape_quotes(rate)} -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
298 |
-
},
|
299 |
-
{
|
300 |
-
"title": "Download from SoundCloud and Split by Chapters (if available)",
|
301 |
-
"inputs": [
|
302 |
-
gr.Textbox(label="SoundCloud Track URL", placeholder="Enter the SoundCloud track URL here"),
|
303 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s', value='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s')
|
304 |
-
],
|
305 |
-
"command": lambda url, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --split-chapters -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
306 |
-
},
|
307 |
-
{
|
308 |
-
"title": "Download SoundCloud Track and Extract a Specific Portion",
|
309 |
-
"inputs": [
|
310 |
-
gr.Textbox(label="SoundCloud Track URL", placeholder="Enter the SoundCloud track URL here"),
|
311 |
-
gr.Textbox(label="Start Time", placeholder='00:01:00', value='00:01:00'),
|
312 |
-
gr.Textbox(label="End Time", placeholder='00:05:00', value='00:05:00'),
|
313 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s', value='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s')
|
314 |
-
],
|
315 |
-
"command": lambda url, start, end, path: f'yt-dlp -f bestaudio --external-downloader ffmpeg --external-downloader-args "ffmpeg_i:-ss {escape_quotes(start)} -to {escape_quotes(end)}" -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
316 |
-
},
|
317 |
-
{
|
318 |
-
"title": "Update Metadata of Existing SoundCloud Downloads",
|
319 |
-
"inputs": [
|
320 |
-
gr.Textbox(label="SoundCloud Track URL", placeholder="Enter the SoundCloud track URL here"),
|
321 |
-
gr.Textbox(label="Download Archive Path", placeholder='P:/Local Music/downloaded_soundcloud.txt', value='P:/Local Music/downloaded_soundcloud.txt')
|
322 |
-
],
|
323 |
-
"command": lambda url, archive: f'yt-dlp --download-archive "{escape_quotes(archive)}" --skip-download --embed-metadata --embed-thumbnail "{escape_quotes(url)}"'
|
324 |
-
},
|
325 |
-
{
|
326 |
-
"title": "Auto-Rename Duplicate SoundCloud Files",
|
327 |
-
"inputs": [
|
328 |
-
gr.Textbox(label="SoundCloud Track URL", placeholder="Enter the SoundCloud track URL here"),
|
329 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s', value='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s')
|
330 |
-
],
|
331 |
-
"command": lambda url, path: f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --force-overwrites -o "{escape_quotes(path)}" "{escape_quotes(url)}"'
|
332 |
-
},
|
333 |
-
{
|
334 |
-
"title": "Download from SoundCloud URL List File",
|
335 |
-
"inputs": [
|
336 |
-
gr.Textbox(label="SoundCloud URL List File Path", placeholder='P:/Local Music/soundcloud_urls.txt', value='P:/Local Music/soundcloud_urls.txt'),
|
337 |
-
gr.Textbox(label="Output Path", placeholder='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s', value='P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s')
|
338 |
-
],
|
339 |
-
"command": lambda list_file, path: f'yt-dlp -a "{escape_quotes(list_file)}" -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "{escape_quotes(path)}"'
|
340 |
-
},
|
341 |
-
]
|
342 |
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
This application provides a user-friendly interface to execute various `yt-dlp` commands.
|
348 |
-
Select a command from the **General Commands** or **SoundCloud Commands** tabs and provide the necessary inputs.
|
349 |
-
"""
|
350 |
-
)
|
351 |
-
|
352 |
-
with gr.Tab("General Commands"):
|
353 |
-
for cmd in general_commands:
|
354 |
-
with gr.Accordion(cmd["title"], open=False):
|
355 |
-
input_components = cmd["inputs"]
|
356 |
-
output = gr.Textbox(label="Command Output", lines=10)
|
357 |
-
execute_button = gr.Button("Execute")
|
358 |
-
|
359 |
-
execute_button.click(
|
360 |
-
run_command,
|
361 |
-
inputs=[inp for inp in input_components],
|
362 |
-
outputs=output,
|
363 |
-
_js=None,
|
364 |
-
fn=lambda *args, cmd=cmd: cmd["command"](*args)
|
365 |
-
)
|
366 |
-
|
367 |
-
with gr.Tab("SoundCloud Commands"):
|
368 |
-
for cmd in soundcloud_commands:
|
369 |
-
with gr.Accordion(cmd["title"], open=False):
|
370 |
-
input_components = cmd["inputs"]
|
371 |
-
output = gr.Textbox(label="Command Output", lines=10)
|
372 |
-
execute_button = gr.Button("Execute")
|
373 |
-
|
374 |
-
execute_button.click(
|
375 |
-
run_command,
|
376 |
-
inputs=[inp for inp in input_components],
|
377 |
-
outputs=output,
|
378 |
-
_js=None,
|
379 |
-
fn=lambda *args, cmd=cmd: cmd["command"](*args)
|
380 |
-
)
|
381 |
-
|
382 |
-
gr.Markdown(
|
383 |
-
"""
|
384 |
-
---
|
385 |
-
**Disclaimer:** Use this tool responsibly. Ensure you have the right to download and convert content. Respect copyright laws and platform terms of service.
|
386 |
-
"""
|
387 |
-
)
|
388 |
|
389 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import yt_dlp
|
3 |
+
import os
|
4 |
+
import tempfile
|
5 |
+
from glob import glob
|
6 |
|
7 |
+
def download_media(urls, output_format, audio_quality, custom_bitrate, embed_metadata, embed_thumbnail, write_description):
|
8 |
+
# Create a temporary directory to store downloads
|
9 |
+
temp_dir = tempfile.mkdtemp()
|
10 |
+
output_template = os.path.join(temp_dir, '%(title)s.%(ext)s')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# Prepare the options
|
13 |
+
ydl_opts = {
|
14 |
+
'outtmpl': output_template,
|
15 |
+
'format': 'bestaudio/best',
|
16 |
+
'postprocessors': [],
|
17 |
+
}
|
18 |
|
19 |
+
# Set format options
|
20 |
+
if output_format in ['mp3', 'opus']:
|
21 |
+
extract_audio_postprocessor = {
|
22 |
+
'key': 'FFmpegExtractAudio',
|
23 |
+
'preferredcodec': output_format,
|
24 |
+
}
|
25 |
+
# Set postprocessor args
|
26 |
+
if audio_quality == 'Best':
|
27 |
+
extract_audio_postprocessor['preferredquality'] = '0' # Best quality
|
28 |
+
elif audio_quality == 'Custom' and custom_bitrate:
|
29 |
+
extract_audio_postprocessor['preferredquality'] = '5' # Default value
|
30 |
+
extract_audio_postprocessor['postprocessor_args'] = ['-b:a', custom_bitrate]
|
31 |
+
ydl_opts['postprocessors'].append(extract_audio_postprocessor)
|
32 |
+
else:
|
33 |
+
ydl_opts['format'] = 'bestvideo+bestaudio/best'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
# Additional options
|
36 |
+
if embed_metadata:
|
37 |
+
ydl_opts['addmetadata'] = True
|
38 |
+
ydl_opts['postprocessors'].append({'key': 'FFmpegMetadata'})
|
39 |
+
if embed_thumbnail:
|
40 |
+
ydl_opts['writethumbnail'] = True
|
41 |
+
ydl_opts['postprocessors'].append({'key': 'EmbedThumbnail'})
|
42 |
+
if write_description:
|
43 |
+
ydl_opts['writedescription'] = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
# Process URLs
|
46 |
+
url_list = urls.strip().split()
|
47 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
48 |
+
ydl.download(url_list)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
+
# Collect output files
|
51 |
+
downloaded_files = glob(os.path.join(temp_dir, '*'))
|
52 |
+
# Return the list of file paths for download
|
53 |
+
return downloaded_files
|
54 |
+
|
55 |
+
def main():
|
56 |
+
with gr.Blocks() as demo:
|
57 |
+
gr.Markdown("# YT-DLP Gradio Interface")
|
58 |
+
with gr.Row():
|
59 |
+
url_input = gr.Textbox(label="Video URL(s)", placeholder="Enter one or more URLs separated by space or newline")
|
60 |
+
with gr.Row():
|
61 |
+
output_format = gr.Dropdown(['mp3', 'opus', 'bestvideo+bestaudio'], label="Output Format", value='mp3')
|
62 |
+
audio_quality = gr.Dropdown(['Best', 'Custom'], label="Audio Quality", value='Best')
|
63 |
+
custom_bitrate = gr.Textbox(label="Custom Bitrate (e.g., 192k)", visible=False)
|
64 |
+
with gr.Row():
|
65 |
+
embed_metadata = gr.Checkbox(label="Embed Metadata")
|
66 |
+
embed_thumbnail = gr.Checkbox(label="Embed Thumbnail")
|
67 |
+
write_description = gr.Checkbox(label="Write Description")
|
68 |
+
start_button = gr.Button("Start Download")
|
69 |
+
output_files = gr.Files(label="Downloaded Files")
|
70 |
+
|
71 |
+
def show_custom_bitrate(audio_quality):
|
72 |
+
if audio_quality == 'Custom':
|
73 |
+
return gr.update(visible=True)
|
74 |
+
else:
|
75 |
+
return gr.update(visible=False)
|
76 |
+
|
77 |
+
audio_quality.change(show_custom_bitrate, inputs=audio_quality, outputs=custom_bitrate)
|
78 |
+
|
79 |
+
start_button.click(download_media,
|
80 |
+
inputs=[url_input, output_format, audio_quality, custom_bitrate, embed_metadata, embed_thumbnail, write_description],
|
81 |
+
outputs=output_files)
|
82 |
+
demo.launch()
|
83 |
+
|
84 |
+
if __name__ == "__main__":
|
85 |
+
main()
|