Nymbo commited on
Commit
19c2a10
·
verified ·
1 Parent(s): ad05f8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -351
app.py CHANGED
@@ -1,352 +1,85 @@
1
  import gradio as gr
2
- import subprocess
3
-
4
- def run_command(command):
5
- try:
6
- result = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
7
- return result.stdout.decode('utf-8')
8
- except subprocess.CalledProcessError as e:
9
- return e.stderr.decode('utf-8')
10
-
11
- def list_available_formats(url):
12
- command = f'yt-dlp -F "{url}"'
13
- return run_command(command)
14
-
15
- def download_mp3_max_quality(url):
16
- 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}"'
17
- return run_command(command)
18
-
19
- def basic_high_quality_mp3_download(url):
20
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
21
- return run_command(command)
22
-
23
- def download_custom_bitrate(url, bitrate):
24
- 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}"'
25
- return run_command(command)
26
-
27
- def download_with_metadata(url):
28
- 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}"'
29
- return run_command(command)
30
-
31
- def download_entire_playlist(url):
32
- 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}"'
33
- return run_command(command)
34
-
35
- def download_playlist_range(url, start, end):
36
- 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}"'
37
- return run_command(command)
38
-
39
- def download_hq_soundcloud(url):
40
- 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}"'
41
- return run_command(command)
42
-
43
- def embed_album_art(url):
44
- 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}"'
45
- return run_command(command)
46
-
47
- def download_specific_format(url, format):
48
- command = f'yt-dlp -f bestaudio --extract-audio --audio-format {format} -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
49
- return run_command(command)
50
-
51
- def skip_downloaded_files(url):
52
- 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}"'
53
- return run_command(command)
54
-
55
- def download_multiple_files(urls):
56
- 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)}'
57
- return run_command(command)
58
-
59
- def split_by_chapters(url):
60
- 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}"'
61
- return run_command(command)
62
-
63
- def extract_portion(url, start_time, end_time):
64
- 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}"'
65
- return run_command(command)
66
-
67
- def update_metadata(url):
68
- command = f'yt-dlp --download-archive "P:/Local Music/downloaded.txt" --skip-download --embed-metadata --embed-thumbnail --write-description "{url}"'
69
- return run_command(command)
70
-
71
- def auto_rename_duplicates(url):
72
- 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}"'
73
- return run_command(command)
74
-
75
- def download_from_url_list(file_path):
76
- 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"'
77
- return run_command(command)
78
-
79
- def limit_download_speed(url, speed):
80
- 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}"'
81
- return run_command(command)
82
-
83
- def download_from_vimeo(url):
84
- 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}"'
85
- return run_command(command)
86
-
87
- def download_from_facebook(url):
88
- 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}"'
89
- return run_command(command)
90
-
91
- def download_from_instagram(url):
92
- 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}"'
93
- return run_command(command)
94
-
95
- def download_from_twitter(url):
96
- 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}"'
97
- return run_command(command)
98
-
99
- def download_from_tiktok(url):
100
- 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}"'
101
- return run_command(command)
102
-
103
- def download_from_reddit(url):
104
- 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}"'
105
- return run_command(command)
106
-
107
- def download_from_dailymotion(url):
108
- 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}"'
109
- return run_command(command)
110
-
111
- def download_youtube_transcript_text(url):
112
- command = f'yt-dlp --write-auto-subs --sub-lang en --skip-download -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
113
- return run_command(command)
114
-
115
- def download_youtube_transcript_markdown(url):
116
- command = f'yt-dlp --write-auto-subs --sub-lang en --skip-download --convert-subs srt -o "P:/Local Music/%(title)s.md" "{url}"'
117
- return run_command(command)
118
-
119
- def download_video_info_json(url):
120
- command = f'yt-dlp --write-info-json --skip-download -o "P:/Local Music/%(title)s.json" "{url}"'
121
- return run_command(command)
122
-
123
- def list_available_formats_no_download(url):
124
- command = f'yt-dlp -F "{url}"'
125
- return run_command(command)
126
-
127
- def download_age_restricted_content(url, email, password):
128
- command = f'yt-dlp --username "{email}" --password "{password}" -f bestvideo+bestaudio -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
129
- return run_command(command)
130
-
131
- # Define the Gradio interface
132
- with gr.Blocks() as demo:
133
- gr.Markdown("## YT-DLP Commands via Gradio")
134
-
135
- with gr.Tab("General Commands"):
136
- with gr.Row():
137
- url_input = gr.Textbox(label="URL")
138
- list_formats_btn = gr.Button("List Available Formats")
139
- list_formats_btn.click(list_available_formats, inputs=url_input, outputs=gr.Textbox())
140
-
141
- with gr.Row():
142
- download_mp3_max_btn = gr.Button("Download MP3 at Max Quality")
143
- download_mp3_max_btn.click(download_mp3_max_quality, inputs=url_input, outputs=gr.Textbox())
144
-
145
- with gr.Row():
146
- download_mp3_basic_btn = gr.Button("Basic High-Quality MP3 Download")
147
- download_mp3_basic_btn.click(basic_high_quality_mp3_download, inputs=url_input, outputs=gr.Textbox())
148
-
149
- with gr.Row():
150
- bitrate_input = gr.Textbox(label="Bitrate (e.g., 192)")
151
- download_custom_bitrate_btn = gr.Button("Download Custom Bitrate")
152
- download_custom_bitrate_btn.click(download_custom_bitrate, inputs=[url_input, bitrate_input], outputs=gr.Textbox())
153
-
154
- with gr.Row():
155
- download_metadata_btn = gr.Button("Download and add Metadata Tags")
156
- download_metadata_btn.click(download_with_metadata, inputs=url_input, outputs=gr.Textbox())
157
-
158
- with gr.Row():
159
- playlist_url_input = gr.Textbox(label="Playlist URL")
160
- download_playlist_btn = gr.Button("Download Entire Playlist")
161
- download_playlist_btn.click(download_entire_playlist, inputs=playlist_url_input, outputs=gr.Textbox())
162
-
163
- with gr.Row():
164
- start_input = gr.Textbox(label="Start Index")
165
- end_input = gr.Textbox(label="End Index")
166
- download_playlist_range_btn = gr.Button("Download Playlist (Specific Range)")
167
- download_playlist_range_btn.click(download_playlist_range, inputs=[playlist_url_input, start_input, end_input], outputs=gr.Textbox())
168
-
169
- with gr.Row():
170
- soundcloud_url_input = gr.Textbox(label="SoundCloud URL")
171
- download_hq_soundcloud_btn = gr.Button("Download HQ from SoundCloud")
172
- download_hq_soundcloud_btn.click(download_hq_soundcloud, inputs=soundcloud_url_input, outputs=gr.Textbox())
173
-
174
- with gr.Row():
175
- embed_album_art_btn = gr.Button("Embed Album Art Automatically")
176
- embed_album_art_btn.click(embed_album_art, inputs=url_input, outputs=gr.Textbox())
177
-
178
- with gr.Row():
179
- format_input = gr.Textbox(label="Format (e.g., opus)")
180
- download_specific_format_btn = gr.Button("Download Specific Formats")
181
- download_specific_format_btn.click(download_specific_format, inputs=[url_input, format_input], outputs=gr.Textbox())
182
-
183
- with gr.Row():
184
- skip_downloaded_btn = gr.Button("Skip Already Downloaded Files")
185
- skip_downloaded_btn.click(skip_downloaded_files, inputs=url_input, outputs=gr.Textbox())
186
-
187
- with gr.Row():
188
- urls_input = gr.Textbox(label="URLs (space-separated)")
189
- download_multiple_files_btn = gr.Button("Download Multiple Individual Files")
190
- download_multiple_files_btn.click(download_multiple_files, inputs=urls_input, outputs=gr.Textbox())
191
-
192
- with gr.Row():
193
- split_chapters_btn = gr.Button("Download and Automatically Split by Chapters")
194
- split_chapters_btn.click(split_by_chapters, inputs=url_input, outputs=gr.Textbox())
195
-
196
- with gr.Row():
197
- start_time_input = gr.Textbox(label="Start Time (e.g., 00:01:00)")
198
- end_time_input = gr.Textbox(label="End Time (e.g., 00:05:00)")
199
- extract_portion_btn = gr.Button("Extract Only a Portion of a Video (by Time)")
200
- extract_portion_btn.click(extract_portion, inputs=[url_input, start_time_input, end_time_input], outputs=gr.Textbox())
201
-
202
- with gr.Row():
203
- update_metadata_btn = gr.Button("Update Metadata of Existing Files")
204
- update_metadata_btn.click(update_metadata, inputs=url_input, outputs=gr.Textbox())
205
-
206
- with gr.Row():
207
- auto_rename_btn = gr.Button("Auto-Rename Duplicate Files")
208
- auto_rename_btn.click(auto_rename_duplicates, inputs=url_input, outputs=gr.Textbox())
209
-
210
- with gr.Row():
211
- file_path_input = gr.Textbox(label="File Path")
212
- download_url_list_btn = gr.Button("Download from a URL List File")
213
- download_url_list_btn.click(download_from_url_list, inputs=file_path_input, outputs=gr.Textbox())
214
-
215
- with gr.Row():
216
- speed_input = gr.Textbox(label="Speed (e.g., 1M)")
217
- limit_download_speed_btn = gr.Button("Download and Limit Download Speed")
218
- limit_download_speed_btn.click(limit_download_speed, inputs=[url_input, speed_input], outputs=gr.Textbox())
219
-
220
- with gr.Row():
221
- vimeo_url_input = gr.Textbox(label="Vimeo URL")
222
- download_vimeo_btn = gr.Button("Download from Vimeo")
223
- download_vimeo_btn.click(download_from_vimeo, inputs=vimeo_url_input, outputs=gr.Textbox())
224
-
225
- with gr.Row():
226
- facebook_url_input = gr.Textbox(label="Facebook URL")
227
- download_facebook_btn = gr.Button("Download from Facebook")
228
- download_facebook_btn.click(download_from_facebook, inputs=facebook_url_input, outputs=gr.Textbox())
229
-
230
- with gr.Row():
231
- instagram_url_input = gr.Textbox(label="Instagram URL")
232
- download_instagram_btn = gr.Button("Download from Instagram")
233
- download_instagram_btn.click(download_from_instagram, inputs=instagram_url_input, outputs=gr.Textbox())
234
-
235
- with gr.Row():
236
- twitter_url_input = gr.Textbox(label="Twitter URL")
237
- download_twitter_btn = gr.Button("Download from Twitter")
238
- download_twitter_btn.click(download_from_twitter, inputs=twitter_url_input, outputs=gr.Textbox())
239
-
240
- with gr.Row():
241
- tiktok_url_input = gr.Textbox(label="TikTok URL")
242
- download_tiktok_btn = gr.Button("Download from TikTok")
243
- download_tiktok_btn.click(download_from_tiktok, inputs=tiktok_url_input, outputs=gr.Textbox())
244
-
245
- with gr.Row():
246
- reddit_url_input = gr.Textbox(label="Reddit URL")
247
- download_reddit_btn = gr.Button("Download from Reddit")
248
- download_reddit_btn.click(download_from_reddit, inputs=reddit_url_input, outputs=gr.Textbox())
249
-
250
- with gr.Row():
251
- dailymotion_url_input = gr.Textbox(label="Dailymotion URL")
252
- download_dailymotion_btn = gr.Button("Download from Dailymotion")
253
- download_dailymotion_btn.click(download_from_dailymotion, inputs=dailymotion_url_input, outputs=gr.Textbox())
254
-
255
- with gr.Row():
256
- download_transcript_text_btn = gr.Button("Download YouTube Transcript as Text")
257
- download_transcript_text_btn.click(download_youtube_transcript_text, inputs=url_input, outputs=gr.Textbox())
258
-
259
- with gr.Row():
260
- download_transcript_markdown_btn = gr.Button("Download YouTube Transcript as Markdown")
261
- download_transcript_markdown_btn.click(download_youtube_transcript_markdown, inputs=url_input, outputs=gr.Textbox())
262
-
263
- with gr.Row():
264
- download_video_info_btn = gr.Button("Download Video Info and Save as JSON")
265
- download_video_info_btn.click(download_video_info_json, inputs=url_input, outputs=gr.Textbox())
266
-
267
- with gr.Row():
268
- list_formats_no_download_btn = gr.Button("List Available Formats without Downloading")
269
- list_formats_no_download_btn.click(list_available_formats_no_download, inputs=url_input, outputs=gr.Textbox())
270
-
271
- with gr.Row():
272
- email_input = gr.Textbox(label="Email")
273
- password_input = gr.Textbox(label="Password", type="password")
274
- age_restricted_url_input = gr.Textbox(label="Age-Restricted Video URL")
275
- download_age_restricted_btn = gr.Button("Download YouTube Age-Restricted Content")
276
- download_age_restricted_btn.click(download_age_restricted_content, inputs=[age_restricted_url_input, email_input, password_input], outputs=gr.Textbox())
277
-
278
- with gr.Tab("SoundCloud Commands"):
279
- with gr.Row():
280
- soundcloud_list_formats_btn = gr.Button("List Available Formats")
281
- soundcloud_list_formats_btn.click(list_available_formats, inputs=soundcloud_url_input, outputs=gr.Textbox())
282
-
283
- with gr.Row():
284
- soundcloud_download_hq_btn = gr.Button("Download High-Quality MP3 from SoundCloud")
285
- soundcloud_download_hq_btn.click(download_hq_soundcloud, inputs=soundcloud_url_input, outputs=gr.Textbox())
286
-
287
- with gr.Row():
288
- soundcloud_download_hq_metadata_btn = gr.Button("Download HQ with Metadata from SoundCloud")
289
- soundcloud_download_hq_metadata_btn.click(download_hq_soundcloud, inputs=soundcloud_url_input, outputs=gr.Textbox())
290
-
291
- with gr.Row():
292
- soundcloud_playlist_url_input = gr.Textbox(label="SoundCloud Playlist URL")
293
- soundcloud_download_playlist_btn = gr.Button("Download Entire Playlist from SoundCloud")
294
- soundcloud_download_playlist_btn.click(download_entire_playlist, inputs=soundcloud_playlist_url_input, outputs=gr.Textbox())
295
-
296
- with gr.Row():
297
- soundcloud_download_playlist_metadata_btn = gr.Button("Download Entire Playlist from SoundCloud with Metadata")
298
- soundcloud_download_playlist_metadata_btn.click(download_entire_playlist, inputs=soundcloud_playlist_url_input, outputs=gr.Textbox())
299
-
300
- with gr.Row():
301
- soundcloud_multiple_playlists_input = gr.Textbox(label="SoundCloud Playlist URLs (space-separated)")
302
- soundcloud_download_multiple_playlists_btn = gr.Button("Download Multiple Playlists with Metadata")
303
- soundcloud_download_multiple_playlists_btn.click(download_multiple_files, inputs=soundcloud_multiple_playlists_input, outputs=gr.Textbox())
304
-
305
- with gr.Row():
306
- soundcloud_playlist_range_start_input = gr.Textbox(label="Start Index")
307
- soundcloud_playlist_range_end_input = gr.Textbox(label="End Index")
308
- soundcloud_download_playlist_range_btn = gr.Button("Download Playlist with Specific Range")
309
- soundcloud_download_playlist_range_btn.click(download_playlist_range, inputs=[soundcloud_playlist_url_input, soundcloud_playlist_range_start_input, soundcloud_playlist_range_end_input], outputs=gr.Textbox())
310
-
311
- with gr.Row():
312
- soundcloud_embed_album_art_btn = gr.Button("Download and Embed Album Art")
313
- soundcloud_embed_album_art_btn.click(embed_album_art, inputs=soundcloud_url_input, outputs=gr.Textbox())
314
-
315
- with gr.Row():
316
- soundcloud_skip_downloaded_btn = gr.Button("Skip Downloading Already Downloaded SoundCloud Files")
317
- soundcloud_skip_downloaded_btn.click(skip_downloaded_files, inputs=soundcloud_url_input, outputs=gr.Textbox())
318
-
319
- with gr.Row():
320
- soundcloud_multiple_tracks_input = gr.Textbox(label="SoundCloud Track URLs (space-separated)")
321
- soundcloud_download_multiple_tracks_btn = gr.Button("Download Multiple Tracks from SoundCloud")
322
- soundcloud_download_multiple_tracks_btn.click(download_multiple_files, inputs=soundcloud_multiple_tracks_input, outputs=gr.Textbox())
323
-
324
- with gr.Row():
325
- soundcloud_limit_speed_input = gr.Textbox(label="Speed (e.g., 1M)")
326
- soundcloud_limit_download_speed_btn = gr.Button("Limit Download Speed for SoundCloud")
327
- soundcloud_limit_download_speed_btn.click(limit_download_speed, inputs=[soundcloud_url_input, soundcloud_limit_speed_input], outputs=gr.Textbox())
328
-
329
- with gr.Row():
330
- soundcloud_split_chapters_btn = gr.Button("Download from SoundCloud and Split by Chapters (if available)")
331
- soundcloud_split_chapters_btn.click(split_by_chapters, inputs=soundcloud_url_input, outputs=gr.Textbox())
332
-
333
- with gr.Row():
334
- soundcloud_extract_portion_start_input = gr.Textbox(label="Start Time (e.g., 00:01:00)")
335
- soundcloud_extract_portion_end_input = gr.Textbox(label="End Time (e.g., 00:05:00)")
336
- soundcloud_extract_portion_btn = gr.Button("Download SoundCloud Track and Extract a Specific Portion")
337
- soundcloud_extract_portion_btn.click(extract_portion, inputs=[soundcloud_url_input, soundcloud_extract_portion_start_input, soundcloud_extract_portion_end_input], outputs=gr.Textbox())
338
-
339
- with gr.Row():
340
- soundcloud_update_metadata_btn = gr.Button("Update Metadata of Existing SoundCloud Downloads")
341
- soundcloud_update_metadata_btn.click(update_metadata, inputs=soundcloud_url_input, outputs=gr.Textbox())
342
-
343
- with gr.Row():
344
- soundcloud_auto_rename_btn = gr.Button("Auto-Rename Duplicate SoundCloud Files")
345
- soundcloud_auto_rename_btn.click(auto_rename_duplicates, inputs=soundcloud_url_input, outputs=gr.Textbox())
346
-
347
- with gr.Row():
348
- soundcloud_url_list_file_input = gr.Textbox(label="File Path")
349
- soundcloud_download_url_list_btn = gr.Button("Download from SoundCloud URL List File")
350
- soundcloud_download_url_list_btn.click(download_from_url_list, inputs=soundcloud_url_list_file_input, outputs=gr.Textbox())
351
-
352
- demo.launch()
 
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()