Nymbo commited on
Commit
9340a56
·
verified ·
1 Parent(s): 75c9267

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +128 -372
app.py CHANGED
@@ -1,377 +1,133 @@
1
  import gradio as gr
2
  import subprocess
3
-
4
- def list_available_formats(url):
5
- command = f'yt-dlp -F "{url}"'
6
- return run_command(command)
7
-
8
- def download_mp3_max_quality(url):
9
- command = f'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" "{url}"'
10
- return run_command(command)
11
-
12
- def basic_high_quality_mp3_download(url):
13
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
14
- return run_command(command)
15
-
16
- def download_custom_bitrate(url, bitrate):
17
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --postprocessor-args "-b:a {bitrate}k" -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
18
- return run_command(command)
19
-
20
- def download_and_add_metadata_tags(url):
21
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --embed-metadata -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
22
- return run_command(command)
23
-
24
- def download_entire_playlist(url):
25
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "P:/Local Music/%(playlist_title)s/%(title)s.%(ext)s" "{url}"'
26
- return run_command(command)
27
-
28
- def download_playlist_specific_range(url, start, end):
29
- command = f'yt-dlp --playlist-items {start}-{end} -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "P:/Local Music/%(playlist_title)s/%(title)s.%(ext)s" "{url}"'
30
- return run_command(command)
31
-
32
- def download_hq_from_soundcloud(url):
33
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s" "{url}"'
34
- return run_command(command)
35
-
36
- def embed_album_art_automatically(url):
37
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --embed-thumbnail --audio-quality 0 -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
38
- return run_command(command)
39
-
40
- def download_specific_formats(url, format):
41
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format {format} -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
42
- return run_command(command)
43
-
44
- def skip_already_downloaded_files(url):
45
- command = f'yt-dlp --download-archive "P:/Local Music/downloaded.txt" -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
46
- return run_command(command)
47
-
48
- def download_multiple_individual_files(urls):
49
- command = 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 "P:/Local Music/%(title)s.%(ext)s" {" ".join(urls)}'
50
- return run_command(command)
51
-
52
- def download_and_automatically_split_by_chapters(url):
53
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --split-chapters -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
54
- return run_command(command)
55
-
56
- def extract_only_a_portion_of_a_video(url, start_time, end_time):
57
- command = f'yt-dlp -f bestvideo+bestaudio --external-downloader ffmpeg --external-downloader-args "ffmpeg_i:-ss {start_time} -to {end_time}" -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
58
- return run_command(command)
59
-
60
- def update_metadata_of_existing_files(url):
61
- command = f'yt-dlp --download-archive "P:/Local Music/downloaded.txt" --skip-download --embed-metadata --embed-thumbnail --write-description "{url}"'
62
- return run_command(command)
63
-
64
- def auto_rename_duplicate_files(url):
65
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --force-overwrites -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
66
- return run_command(command)
67
-
68
- def download_from_url_list_file(file_path):
69
- command = f'yt-dlp -a "{file_path}" -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "P:/Local Music/%(title)s.%(ext)s"'
70
- return run_command(command)
71
-
72
- def download_and_limit_download_speed(url, speed):
73
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 --rate-limit {speed} -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
74
- return run_command(command)
75
-
76
- def download_from_vimeo(url):
77
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "P:/Local Music/Vimeo/%(uploader)s - %(title)s.%(ext)s" "{url}"'
78
- return run_command(command)
79
-
80
- def download_from_facebook(url):
81
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "P:/Local Music/Facebook/%(uploader)s - %(title)s.%(ext)s" "{url}"'
82
- return run_command(command)
83
-
84
- def download_from_instagram(url):
85
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "P:/Local Music/Instagram/%(uploader)s - %(title)s.%(ext)s" "{url}"'
86
- return run_command(command)
87
-
88
- def download_from_twitter(url):
89
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "P:/Local Music/Twitter/%(uploader)s - %(title)s.%(ext)s" "{url}"'
90
- return run_command(command)
91
-
92
- def download_from_tiktok(url):
93
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "P:/Local Music/TikTok/%(uploader)s - %(title)s.%(ext)s" "{url}"'
94
- return run_command(command)
95
-
96
- def download_from_reddit(url):
97
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "P:/Local Music/Reddit/%(uploader)s - %(title)s.%(ext)s" "{url}"'
98
- return run_command(command)
99
-
100
- def download_from_dailymotion(url):
101
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "P:/Local Music/Dailymotion/%(uploader)s - %(title)s.%(ext)s" "{url}"'
102
- return run_command(command)
103
-
104
- def download_youtube_transcript_as_text(url):
105
- command = f'yt-dlp --write-auto-subs --sub-lang en --skip-download -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
106
- return run_command(command)
107
-
108
- def download_youtube_transcript_as_markdown(url):
109
- command = f'yt-dlp --write-auto-subs --sub-lang en --skip-download --convert-subs srt -o "P:/Local Music/%(title)s.md" "{url}"'
110
- return run_command(command)
111
-
112
- def download_video_info_and_save_as_json(url):
113
- command = f'yt-dlp --write-info-json --skip-download -o "P:/Local Music/%(title)s.json" "{url}"'
114
- return run_command(command)
115
-
116
- def list_available_formats_without_downloading(url):
117
- command = f'yt-dlp -F "{url}"'
118
- return run_command(command)
119
-
120
- def download_from_youtube_age_restricted_content(url, email, password):
121
- command = f'yt-dlp --username "{email}" --password "{password}" -f bestvideo+bestaudio -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
122
- return run_command(command)
123
-
124
- def run_command(command):
125
- result = subprocess.run(command, shell=True, capture_output=True, text=True)
126
- return result.stdout + result.stderr
127
-
128
  with gr.Blocks() as demo:
129
- gr.Markdown("## YT-DLP Commands via Gradio")
130
-
131
- with gr.Tab("General Commands"):
132
- with gr.Row():
133
- url_input = gr.Textbox(label="URL")
134
- list_formats_btn = gr.Button("List Available Formats")
135
- list_formats_btn.click(list_available_formats, inputs=url_input, outputs=gr.Textbox())
136
-
137
- with gr.Row():
138
- url_input_mp3 = gr.Textbox(label="URL")
139
- download_mp3_btn = gr.Button("Download MP3 at Max Quality")
140
- download_mp3_btn.click(download_mp3_max_quality, inputs=url_input_mp3, outputs=gr.Textbox())
141
-
142
- with gr.Row():
143
- url_input_basic = gr.Textbox(label="URL")
144
- basic_mp3_btn = gr.Button("Basic High-Quality MP3 Download")
145
- basic_mp3_btn.click(basic_high_quality_mp3_download, inputs=url_input_basic, outputs=gr.Textbox())
146
-
147
- with gr.Row():
148
- url_input_custom = gr.Textbox(label="URL")
149
- bitrate_input = gr.Textbox(label="Bitrate (e.g., 192)")
150
- custom_bitrate_btn = gr.Button("Download Custom Bitrate")
151
- custom_bitrate_btn.click(download_custom_bitrate, inputs=[url_input_custom, bitrate_input], outputs=gr.Textbox())
152
-
153
- with gr.Row():
154
- url_input_metadata = gr.Textbox(label="URL")
155
- metadata_btn = gr.Button("Download and Add Metadata Tags")
156
- metadata_btn.click(download_and_add_metadata_tags, inputs=url_input_metadata, outputs=gr.Textbox())
157
-
158
- with gr.Row():
159
- url_input_playlist = gr.Textbox(label="Playlist URL")
160
- playlist_btn = gr.Button("Download Entire Playlist")
161
- playlist_btn.click(download_entire_playlist, inputs=url_input_playlist, outputs=gr.Textbox())
162
-
163
- with gr.Row():
164
- url_input_playlist_range = gr.Textbox(label="Playlist URL")
165
- start_input = gr.Textbox(label="Start Index")
166
- end_input = gr.Textbox(label="End Index")
167
- playlist_range_btn = gr.Button("Download Playlist (Specific Range)")
168
- playlist_range_btn.click(download_playlist_specific_range, inputs=[url_input_playlist_range, start_input, end_input], outputs=gr.Textbox())
169
-
170
- with gr.Row():
171
- url_input_soundcloud = gr.Textbox(label="SoundCloud Track URL")
172
- soundcloud_btn = gr.Button("Download HQ from SoundCloud")
173
- soundcloud_btn.click(download_hq_from_soundcloud, inputs=url_input_soundcloud, outputs=gr.Textbox())
174
-
175
- with gr.Row():
176
- url_input_album_art = gr.Textbox(label="URL")
177
- album_art_btn = gr.Button("Embed Album Art Automatically")
178
- album_art_btn.click(embed_album_art_automatically, inputs=url_input_album_art, outputs=gr.Textbox())
179
-
180
- with gr.Row():
181
- url_input_specific_format = gr.Textbox(label="URL")
182
- format_input = gr.Textbox(label="Format (e.g., opus)")
183
- specific_format_btn = gr.Button("Download Specific Formats")
184
- specific_format_btn.click(download_specific_formats, inputs=[url_input_specific_format, format_input], outputs=gr.Textbox())
185
-
186
- with gr.Row():
187
- url_input_skip = gr.Textbox(label="URL")
188
- skip_btn = gr.Button("Skip Already Downloaded Files")
189
- skip_btn.click(skip_already_downloaded_files, inputs=url_input_skip, outputs=gr.Textbox())
190
-
191
- with gr.Row():
192
- urls_input = gr.Textbox(label="URLs (space-separated)")
193
- multiple_files_btn = gr.Button("Download Multiple Individual Files")
194
- multiple_files_btn.click(download_multiple_individual_files, inputs=urls_input, outputs=gr.Textbox())
195
-
196
- with gr.Row():
197
- url_input_chapters = gr.Textbox(label="URL")
198
- chapters_btn = gr.Button("Download and Automatically Split by Chapters")
199
- chapters_btn.click(download_and_automatically_split_by_chapters, inputs=url_input_chapters, outputs=gr.Textbox())
200
-
201
- with gr.Row():
202
- url_input_portion = gr.Textbox(label="URL")
203
- start_time_input = gr.Textbox(label="Start Time (e.g., 00:01:00)")
204
- end_time_input = gr.Textbox(label="End Time (e.g., 00:05:00)")
205
- portion_btn = gr.Button("Extract Only a Portion of a Video")
206
- portion_btn.click(extract_only_a_portion_of_a_video, inputs=[url_input_portion, start_time_input, end_time_input], outputs=gr.Textbox())
207
-
208
- with gr.Row():
209
- url_input_metadata_update = gr.Textbox(label="URL")
210
- metadata_update_btn = gr.Button("Update Metadata of Existing Files")
211
- metadata_update_btn.click(update_metadata_of_existing_files, inputs=url_input_metadata_update, outputs=gr.Textbox())
212
-
213
- with gr.Row():
214
- url_input_rename = gr.Textbox(label="URL")
215
- rename_btn = gr.Button("Auto-Rename Duplicate Files")
216
- rename_btn.click(auto_rename_duplicate_files, inputs=url_input_rename, outputs=gr.Textbox())
217
-
218
- with gr.Row():
219
- file_path_input = gr.Textbox(label="File Path")
220
- url_list_btn = gr.Button("Download from URL List File")
221
- url_list_btn.click(download_from_url_list_file, inputs=file_path_input, outputs=gr.Textbox())
222
-
223
- with gr.Row():
224
- url_input_speed = gr.Textbox(label="URL")
225
- speed_input = gr.Textbox(label="Speed (e.g., 1M)")
226
- speed_btn = gr.Button("Download and Limit Download Speed")
227
- speed_btn.click(download_and_limit_download_speed, inputs=[url_input_speed, speed_input], outputs=gr.Textbox())
228
-
229
- with gr.Row():
230
- url_input_vimeo = gr.Textbox(label="Vimeo Video URL")
231
- vimeo_btn = gr.Button("Download from Vimeo")
232
- vimeo_btn.click(download_from_vimeo, inputs=url_input_vimeo, outputs=gr.Textbox())
233
-
234
- with gr.Row():
235
- url_input_facebook = gr.Textbox(label="Facebook Video URL")
236
- facebook_btn = gr.Button("Download from Facebook")
237
- facebook_btn.click(download_from_facebook, inputs=url_input_facebook, outputs=gr.Textbox())
238
-
239
- with gr.Row():
240
- url_input_instagram = gr.Textbox(label="Instagram Video URL")
241
- instagram_btn = gr.Button("Download from Instagram")
242
- instagram_btn.click(download_from_instagram, inputs=url_input_instagram, outputs=gr.Textbox())
243
-
244
- with gr.Row():
245
- url_input_twitter = gr.Textbox(label="Twitter Video URL")
246
- twitter_btn = gr.Button("Download from Twitter")
247
- twitter_btn.click(download_from_twitter, inputs=url_input_twitter, outputs=gr.Textbox())
248
-
249
- with gr.Row():
250
- url_input_tiktok = gr.Textbox(label="TikTok Video URL")
251
- tiktok_btn = gr.Button("Download from TikTok")
252
- tiktok_btn.click(download_from_tiktok, inputs=url_input_tiktok, outputs=gr.Textbox())
253
-
254
- with gr.Row():
255
- url_input_reddit = gr.Textbox(label="Reddit Video URL")
256
- reddit_btn = gr.Button("Download from Reddit")
257
- reddit_btn.click(download_from_reddit, inputs=url_input_reddit, outputs=gr.Textbox())
258
-
259
- with gr.Row():
260
- url_input_dailymotion = gr.Textbox(label="Dailymotion Video URL")
261
- dailymotion_btn = gr.Button("Download from Dailymotion")
262
- dailymotion_btn.click(download_from_dailymotion, inputs=url_input_dailymotion, outputs=gr.Textbox())
263
-
264
- with gr.Row():
265
- url_input_transcript_text = gr.Textbox(label="YouTube Video URL")
266
- transcript_text_btn = gr.Button("Download YouTube Transcript as Text")
267
- transcript_text_btn.click(download_youtube_transcript_as_text, inputs=url_input_transcript_text, outputs=gr.Textbox())
268
-
269
- with gr.Row():
270
- url_input_transcript_md = gr.Textbox(label="YouTube Video URL")
271
- transcript_md_btn = gr.Button("Download YouTube Transcript as Markdown")
272
- transcript_md_btn.click(download_youtube_transcript_as_markdown, inputs=url_input_transcript_md, outputs=gr.Textbox())
273
-
274
- with gr.Row():
275
- url_input_video_info = gr.Textbox(label="YouTube Video URL")
276
- video_info_btn = gr.Button("Download Video Info and Save as JSON")
277
- video_info_btn.click(download_video_info_and_save_as_json, inputs=url_input_video_info, outputs=gr.Textbox())
278
-
279
- with gr.Row():
280
- url_input_list_formats = gr.Textbox(label="YouTube Video URL")
281
- list_formats_without_downloading_btn = gr.Button("List Available Formats without Downloading")
282
- list_formats_without_downloading_btn.click(list_available_formats_without_downloading, inputs=url_input_list_formats, outputs=gr.Textbox())
283
-
284
- with gr.Row():
285
- url_input_age_restricted = gr.Textbox(label="Age-Restricted Video URL")
286
- email_input = gr.Textbox(label="Your YouTube Email")
287
- password_input = gr.Textbox(label="Your Password", type="password")
288
- age_restricted_btn = gr.Button("Download from YouTube Age-Restricted Content")
289
- age_restricted_btn.click(download_from_youtube_age_restricted_content, inputs=[url_input_age_restricted, email_input, password_input], outputs=gr.Textbox())
290
-
291
- with gr.Tab("SoundCloud Commands"):
292
- with gr.Row():
293
- url_input_soundcloud_formats = gr.Textbox(label="SoundCloud URL")
294
- soundcloud_formats_btn = gr.Button("List Available Formats")
295
- soundcloud_formats_btn.click(list_available_formats, inputs=url_input_soundcloud_formats, outputs=gr.Textbox())
296
-
297
- with gr.Row():
298
- url_input_soundcloud_hq = gr.Textbox(label="SoundCloud Track URL")
299
- soundcloud_hq_btn = gr.Button("Download High-Quality MP3 from SoundCloud")
300
- soundcloud_hq_btn.click(download_hq_from_soundcloud, inputs=url_input_soundcloud_hq, outputs=gr.Textbox())
301
-
302
- with gr.Row():
303
- url_input_soundcloud_metadata = gr.Textbox(label="SoundCloud Track URL")
304
- soundcloud_metadata_btn = gr.Button("Download HQ with Metadata from SoundCloud")
305
- soundcloud_metadata_btn.click(download_hq_from_soundcloud, inputs=url_input_soundcloud_metadata, outputs=gr.Textbox())
306
-
307
- with gr.Row():
308
- url_input_soundcloud_playlist = gr.Textbox(label="SoundCloud Playlist URL")
309
- soundcloud_playlist_btn = gr.Button("Download Entire Playlist from SoundCloud")
310
- soundcloud_playlist_btn.click(download_entire_playlist, inputs=url_input_soundcloud_playlist, outputs=gr.Textbox())
311
-
312
- with gr.Row():
313
- url_input_soundcloud_playlist_metadata = gr.Textbox(label="SoundCloud Playlist URL")
314
- soundcloud_playlist_metadata_btn = gr.Button("Download Entire Playlist from SoundCloud with Metadata")
315
- soundcloud_playlist_metadata_btn.click(download_entire_playlist, inputs=url_input_soundcloud_playlist_metadata, outputs=gr.Textbox())
316
-
317
- with gr.Row():
318
- url_input_soundcloud_multiple_playlists = gr.Textbox(label="SoundCloud Playlist URLs (space-separated)")
319
- soundcloud_multiple_playlists_btn = gr.Button("Download Multiple Playlists with Metadata")
320
- soundcloud_multiple_playlists_btn.click(download_multiple_individual_files, inputs=url_input_soundcloud_multiple_playlists, outputs=gr.Textbox())
321
-
322
- with gr.Row():
323
- url_input_soundcloud_playlist_range = gr.Textbox(label="SoundCloud Playlist URL")
324
- start_input_soundcloud = gr.Textbox(label="Start Index")
325
- end_input_soundcloud = gr.Textbox(label="End Index")
326
- soundcloud_playlist_range_btn = gr.Button("Download Playlist with Specific Range")
327
- soundcloud_playlist_range_btn.click(download_playlist_specific_range, inputs=[url_input_soundcloud_playlist_range, start_input_soundcloud, end_input_soundcloud], outputs=gr.Textbox())
328
-
329
- with gr.Row():
330
- url_input_soundcloud_album_art = gr.Textbox(label="SoundCloud Track URL")
331
- soundcloud_album_art_btn = gr.Button("Download and Embed Album Art")
332
- soundcloud_album_art_btn.click(embed_album_art_automatically, inputs=url_input_soundcloud_album_art, outputs=gr.Textbox())
333
-
334
- with gr.Row():
335
- url_input_soundcloud_skip = gr.Textbox(label="SoundCloud Track URL")
336
- soundcloud_skip_btn = gr.Button("Skip Downloading Already Downloaded SoundCloud Files")
337
- soundcloud_skip_btn.click(skip_already_downloaded_files, inputs=url_input_soundcloud_skip, outputs=gr.Textbox())
338
-
339
- with gr.Row():
340
- urls_input_soundcloud = gr.Textbox(label="SoundCloud Track URLs (space-separated)")
341
- soundcloud_multiple_tracks_btn = gr.Button("Download Multiple Tracks from SoundCloud")
342
- soundcloud_multiple_tracks_btn.click(download_multiple_individual_files, inputs=urls_input_soundcloud, outputs=gr.Textbox())
343
-
344
- with gr.Row():
345
- url_input_soundcloud_speed = gr.Textbox(label="SoundCloud Track URL")
346
- speed_input_soundcloud = gr.Textbox(label="Speed (e.g., 1M)")
347
- soundcloud_speed_btn = gr.Button("Limit Download Speed for SoundCloud")
348
- soundcloud_speed_btn.click(download_and_limit_download_speed, inputs=[url_input_soundcloud_speed, speed_input_soundcloud], outputs=gr.Textbox())
349
-
350
- with gr.Row():
351
- url_input_soundcloud_chapters = gr.Textbox(label="SoundCloud Track URL")
352
- soundcloud_chapters_btn = gr.Button("Download from SoundCloud and Split by Chapters (if available)")
353
- soundcloud_chapters_btn.click(download_and_automatically_split_by_chapters, inputs=url_input_soundcloud_chapters, outputs=gr.Textbox())
354
-
355
- with gr.Row():
356
- url_input_soundcloud_portion = gr.Textbox(label="SoundCloud Track URL")
357
- start_time_input_soundcloud = gr.Textbox(label="Start Time (e.g., 00:01:00)")
358
- end_time_input_soundcloud = gr.Textbox(label="End Time (e.g., 00:05:00)")
359
- soundcloud_portion_btn = gr.Button("Download SoundCloud Track and Extract a Specific Portion")
360
- soundcloud_portion_btn.click(extract_only_a_portion_of_a_video, inputs=[url_input_soundcloud_portion, start_time_input_soundcloud, end_time_input_soundcloud], outputs=gr.Textbox())
361
-
362
- with gr.Row():
363
- url_input_soundcloud_metadata_update = gr.Textbox(label="SoundCloud Track URL")
364
- soundcloud_metadata_update_btn = gr.Button("Update Metadata of Existing SoundCloud Downloads")
365
- soundcloud_metadata_update_btn.click(update_metadata_of_existing_files, inputs=url_input_soundcloud_metadata_update, outputs=gr.Textbox())
366
-
367
- with gr.Row():
368
- url_input_soundcloud_rename = gr.Textbox(label="SoundCloud Track URL")
369
- soundcloud_rename_btn = gr.Button("Auto-Rename Duplicate SoundCloud Files")
370
- soundcloud_rename_btn.click(auto_rename_duplicate_files, inputs=url_input_soundcloud_rename, outputs=gr.Textbox())
371
-
372
- with gr.Row():
373
- file_path_input_soundcloud = gr.Textbox(label="File Path")
374
- soundcloud_url_list_btn = gr.Button("Download from SoundCloud URL List File")
375
- soundcloud_url_list_btn.click(download_from_url_list_file, inputs=file_path_input_soundcloud, outputs=gr.Textbox())
376
 
377
  demo.launch()
 
1
  import gradio as gr
2
  import subprocess
3
+ import os
4
+
5
+ # Function to run yt-dlp commands
6
+ def run_yt_dlp(command, url, output_path, bitrate=None, start_time=None, end_time=None, playlist_items=None, archive_file=None):
7
+ base_command = ["yt-dlp", "-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "-o", output_path]
8
+
9
+ if command == "list_formats":
10
+ base_command = ["yt-dlp", "-F", url]
11
+ elif command == "download_mp3_max_quality":
12
+ base_command.extend(["--postprocessor-args", "-b:a 320k", url])
13
+ elif command == "basic_high_quality_mp3":
14
+ base_command.append(url)
15
+ elif command == "custom_bitrate":
16
+ base_command.extend(["--postprocessor-args", f"-b:a {bitrate}k", url])
17
+ elif command == "add_metadata_tags":
18
+ base_command.extend(["--embed-metadata", url])
19
+ elif command == "download_playlist":
20
+ base_command.append(url)
21
+ elif command == "download_playlist_range":
22
+ base_command.extend(["--playlist-items", playlist_items, url])
23
+ elif command == "download_hq_soundcloud":
24
+ base_command.extend(["-o", "P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s", url])
25
+ elif command == "embed_album_art":
26
+ base_command.extend(["--embed-thumbnail", url])
27
+ elif command == "download_opus":
28
+ base_command.extend(["--audio-format", "opus", url])
29
+ elif command == "skip_downloaded_files":
30
+ base_command.extend(["--download-archive", archive_file, url])
31
+ elif command == "download_multiple_files":
32
+ base_command.extend(url.split())
33
+ elif command == "download_split_chapters":
34
+ base_command.extend(["--split-chapters", url])
35
+ elif command == "extract_portion":
36
+ base_command.extend(["-f", "bestvideo+bestaudio", "--external-downloader", "ffmpeg", "--external-downloader-args", f"ffmpeg_i:-ss {start_time} -to {end_time}", url])
37
+ elif command == "update_metadata":
38
+ base_command.extend(["--download-archive", archive_file, "--skip-download", "--embed-metadata", "--embed-thumbnail", url])
39
+ elif command == "auto_rename":
40
+ base_command.extend(["--force-overwrites", url])
41
+ elif command == "download_url_list":
42
+ base_command.extend(["-a", url])
43
+ elif command == "limit_speed":
44
+ base_command.extend(["--rate-limit", "1M", url])
45
+ elif command == "download_vimeo":
46
+ base_command.extend(["-o", "P:/Local Music/Vimeo/%(uploader)s - %(title)s.%(ext)s", url])
47
+ elif command == "download_facebook":
48
+ base_command.extend(["-o", "P:/Local Music/Facebook/%(uploader)s - %(title)s.%(ext)s", url])
49
+ elif command == "download_instagram":
50
+ base_command.extend(["-o", "P:/Local Music/Instagram/%(uploader)s - %(title)s.%(ext)s", url])
51
+ elif command == "download_twitter":
52
+ base_command.extend(["-o", "P:/Local Music/Twitter/%(uploader)s - %(title)s.%(ext)s", url])
53
+ elif command == "download_tiktok":
54
+ base_command.extend(["-o", "P:/Local Music/TikTok/%(uploader)s - %(title)s.%(ext)s", url])
55
+ elif command == "download_reddit":
56
+ base_command.extend(["-o", "P:/Local Music/Reddit/%(uploader)s - %(title)s.%(ext)s", url])
57
+ elif command == "download_dailymotion":
58
+ base_command.extend(["-o", "P:/Local Music/Dailymotion/%(uploader)s - %(title)s.%(ext)s", url])
59
+ elif command == "download_transcript_text":
60
+ base_command.extend(["--write-auto-subs", "--sub-lang", "en", "--skip-download", url])
61
+ elif command == "download_transcript_markdown":
62
+ base_command.extend(["--write-auto-subs", "--sub-lang", "en", "--skip-download", "--convert-subs", "srt", "-o", "P:/Local Music/%(title)s.md", url])
63
+ elif command == "download_video_info":
64
+ base_command.extend(["--write-info-json", "--skip-download", "-o", "P:/Local Music/%(title)s.json", url])
65
+ elif command == "list_formats_no_download":
66
+ base_command = ["yt-dlp", "-F", url]
67
+ elif command == "download_age_restricted":
68
+ base_command.extend(["--username", "YOUR_YOUTUBE_EMAIL", "--password", "YOUR_PASSWORD", "-f", "bestvideo+bestaudio", url])
69
+
70
+ try:
71
+ result = subprocess.run(base_command, capture_output=True, text=True)
72
+ return result.stdout
73
+ except Exception as e:
74
+ return str(e)
75
+
76
+ # Gradio Interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  with gr.Blocks() as demo:
78
+ gr.Markdown("# yt-dlp Command Executor")
79
+
80
+ with gr.Row():
81
+ command = gr.Dropdown(choices=[
82
+ "list_formats",
83
+ "download_mp3_max_quality",
84
+ "basic_high_quality_mp3",
85
+ "custom_bitrate",
86
+ "add_metadata_tags",
87
+ "download_playlist",
88
+ "download_playlist_range",
89
+ "download_hq_soundcloud",
90
+ "embed_album_art",
91
+ "download_opus",
92
+ "skip_downloaded_files",
93
+ "download_multiple_files",
94
+ "download_split_chapters",
95
+ "extract_portion",
96
+ "update_metadata",
97
+ "auto_rename",
98
+ "download_url_list",
99
+ "limit_speed",
100
+ "download_vimeo",
101
+ "download_facebook",
102
+ "download_instagram",
103
+ "download_twitter",
104
+ "download_tiktok",
105
+ "download_reddit",
106
+ "download_dailymotion",
107
+ "download_transcript_text",
108
+ "download_transcript_markdown",
109
+ "download_video_info",
110
+ "list_formats_no_download",
111
+ "download_age_restricted"
112
+ ], label="Command")
113
+
114
+ url = gr.Textbox(label="URL", placeholder="Enter the URL here")
115
+
116
+ with gr.Row():
117
+ output_path = gr.Textbox(label="Output Path", placeholder="Enter the output path here")
118
+ bitrate = gr.Textbox(label="Bitrate (for custom bitrate)", placeholder="Enter bitrate in kbps, e.g., 192")
119
+ start_time = gr.Textbox(label="Start Time (HH:MM:SS)", placeholder="Enter start time, e.g., 00:01:00")
120
+ end_time = gr.Textbox(label="End Time (HH:MM:SS)", placeholder="Enter end time, e.g., 00:05:00")
121
+ playlist_items = gr.Textbox(label="Playlist Items (e.g., 1-5)", placeholder="Enter range of items, e.g., 1-5")
122
+ archive_file = gr.Textbox(label="Archive File", placeholder="Enter path to archive file, e.g., P:/Local Music/downloaded.txt")
123
+
124
+ execute_button = gr.Button("Execute Command")
125
+ output = gr.Textbox(label="Output", lines=10)
126
+
127
+ execute_button.click(
128
+ fn=run_yt_dlp,
129
+ inputs=[command, url, output_path, bitrate, start_time, end_time, playlist_items, archive_file],
130
+ outputs=output
131
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
  demo.launch()