Nymbo commited on
Commit
ea4a110
·
verified ·
1 Parent(s): 499b696

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +110 -295
app.py CHANGED
@@ -1,300 +1,115 @@
1
  import gradio as gr
2
  import subprocess
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- def run_yt_dlp_command(command):
5
  try:
6
- result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
7
- return result.stdout
8
- except subprocess.CalledProcessError as e:
9
- return e.stderr
10
-
11
- def list_available_formats(url):
12
- command = f'yt-dlp -F "{url}"'
13
- return run_yt_dlp_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_yt_dlp_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_yt_dlp_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_yt_dlp_command(command)
26
-
27
- def download_and_add_metadata_tags(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_yt_dlp_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_yt_dlp_command(command)
34
-
35
- def download_playlist_specific_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_yt_dlp_command(command)
38
-
39
- def download_hq_from_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_yt_dlp_command(command)
42
-
43
- def embed_album_art_automatically(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_yt_dlp_command(command)
46
-
47
- def download_specific_formats(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_yt_dlp_command(command)
50
-
51
- def skip_already_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_yt_dlp_command(command)
54
-
55
- def download_multiple_individual_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_yt_dlp_command(command)
58
-
59
- def download_and_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_yt_dlp_command(command)
62
-
63
- def extract_portion_of_video(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_yt_dlp_command(command)
66
-
67
- def update_metadata_of_existing_files(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_yt_dlp_command(command)
70
-
71
- def auto_rename_duplicate_files(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_yt_dlp_command(command)
74
-
75
- def download_from_url_list_file(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_yt_dlp_command(command)
78
-
79
- def download_and_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_yt_dlp_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_yt_dlp_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_yt_dlp_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_yt_dlp_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_yt_dlp_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_yt_dlp_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_yt_dlp_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_yt_dlp_command(command)
110
-
111
- def download_youtube_transcript_as_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_yt_dlp_command(command)
114
-
115
- def download_youtube_transcript_as_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_yt_dlp_command(command)
118
-
119
- def download_video_info_and_save_as_json(url):
120
- command = f'yt-dlp --write-info-json --skip-download -o "P:/Local Music/%(title)s.json" "{url}"'
121
- return run_yt_dlp_command(command)
122
-
123
- def list_available_formats_without_downloading(url):
124
- command = f'yt-dlp -F "{url}"'
125
- return run_yt_dlp_command(command)
126
-
127
- def download_from_youtube_age_restricted_content(url, username, password):
128
- command = f'yt-dlp --username "{username}" --password "{password}" -f bestvideo+bestaudio -o "P:/Local Music/%(title)s.%(ext)s" "{url}"'
129
- return run_yt_dlp_command(command)
130
-
131
- # Define the Gradio interface
132
  with gr.Blocks() as demo:
133
- gr.Markdown("# YT-DLP Commands Interface")
134
-
135
- with gr.Tab("General Commands"):
136
- with gr.Row():
137
- with gr.Column():
138
- url_input = gr.Textbox(label="URL")
139
- list_formats_btn = gr.Button("List Available Formats")
140
- list_formats_btn.click(list_available_formats, inputs=url_input, outputs=gr.Textbox())
141
-
142
- download_mp3_max_quality_btn = gr.Button("Download MP3 at Max Quality")
143
- download_mp3_max_quality_btn.click(download_mp3_max_quality, inputs=url_input, outputs=gr.Textbox())
144
-
145
- basic_high_quality_mp3_download_btn = gr.Button("Basic High-Quality MP3 Download")
146
- basic_high_quality_mp3_download_btn.click(basic_high_quality_mp3_download, inputs=url_input, outputs=gr.Textbox())
147
-
148
- custom_bitrate_input = gr.Textbox(label="Custom Bitrate (e.g., 192k)")
149
- download_custom_bitrate_btn = gr.Button("Download Custom Bitrate")
150
- download_custom_bitrate_btn.click(download_custom_bitrate, inputs=[url_input, custom_bitrate_input], outputs=gr.Textbox())
151
-
152
- download_and_add_metadata_tags_btn = gr.Button("Download and Add Metadata Tags")
153
- download_and_add_metadata_tags_btn.click(download_and_add_metadata_tags, inputs=url_input, outputs=gr.Textbox())
154
-
155
- download_entire_playlist_btn = gr.Button("Download Entire Playlist")
156
- download_entire_playlist_btn.click(download_entire_playlist, inputs=url_input, outputs=gr.Textbox())
157
-
158
- playlist_range_start_input = gr.Textbox(label="Start Index")
159
- playlist_range_end_input = gr.Textbox(label="End Index")
160
- download_playlist_specific_range_btn = gr.Button("Download Playlist (Specific Range)")
161
- download_playlist_specific_range_btn.click(download_playlist_specific_range, inputs=[url_input, playlist_range_start_input, playlist_range_end_input], outputs=gr.Textbox())
162
-
163
- download_hq_from_soundcloud_btn = gr.Button("Download HQ from SoundCloud")
164
- download_hq_from_soundcloud_btn.click(download_hq_from_soundcloud, inputs=url_input, outputs=gr.Textbox())
165
-
166
- embed_album_art_automatically_btn = gr.Button("Embed Album Art Automatically")
167
- embed_album_art_automatically_btn.click(embed_album_art_automatically, inputs=url_input, outputs=gr.Textbox())
168
-
169
- specific_format_input = gr.Textbox(label="Specific Format (e.g., opus)")
170
- download_specific_formats_btn = gr.Button("Download Specific Formats")
171
- download_specific_formats_btn.click(download_specific_formats, inputs=[url_input, specific_format_input], outputs=gr.Textbox())
172
-
173
- skip_already_downloaded_files_btn = gr.Button("Skip Already Downloaded Files")
174
- skip_already_downloaded_files_btn.click(skip_already_downloaded_files, inputs=url_input, outputs=gr.Textbox())
175
-
176
- multiple_urls_input = gr.Textbox(label="Multiple URLs (space-separated)")
177
- download_multiple_individual_files_btn = gr.Button("Download Multiple Individual Files")
178
- download_multiple_individual_files_btn.click(download_multiple_individual_files, inputs=multiple_urls_input, outputs=gr.Textbox())
179
-
180
- download_and_split_by_chapters_btn = gr.Button("Download and Split by Chapters")
181
- download_and_split_by_chapters_btn.click(download_and_split_by_chapters, inputs=url_input, outputs=gr.Textbox())
182
-
183
- start_time_input = gr.Textbox(label="Start Time (e.g., 00:01:00)")
184
- end_time_input = gr.Textbox(label="End Time (e.g., 00:05:00)")
185
- extract_portion_of_video_btn = gr.Button("Extract Portion of Video")
186
- extract_portion_of_video_btn.click(extract_portion_of_video, inputs=[url_input, start_time_input, end_time_input], outputs=gr.Textbox())
187
-
188
- update_metadata_of_existing_files_btn = gr.Button("Update Metadata of Existing Files")
189
- update_metadata_of_existing_files_btn.click(update_metadata_of_existing_files, inputs=url_input, outputs=gr.Textbox())
190
-
191
- auto_rename_duplicate_files_btn = gr.Button("Auto-Rename Duplicate Files")
192
- auto_rename_duplicate_files_btn.click(auto_rename_duplicate_files, inputs=url_input, outputs=gr.Textbox())
193
-
194
- url_list_file_input = gr.Textbox(label="URL List File Path")
195
- download_from_url_list_file_btn = gr.Button("Download from URL List File")
196
- download_from_url_list_file_btn.click(download_from_url_list_file, inputs=url_list_file_input, outputs=gr.Textbox())
197
-
198
- download_speed_input = gr.Textbox(label="Download Speed (e.g., 1M)")
199
- download_and_limit_download_speed_btn = gr.Button("Download and Limit Download Speed")
200
- download_and_limit_download_speed_btn.click(download_and_limit_download_speed, inputs=[url_input, download_speed_input], outputs=gr.Textbox())
201
-
202
- download_from_vimeo_btn = gr.Button("Download from Vimeo")
203
- download_from_vimeo_btn.click(download_from_vimeo, inputs=url_input, outputs=gr.Textbox())
204
-
205
- download_from_facebook_btn = gr.Button("Download from Facebook")
206
- download_from_facebook_btn.click(download_from_facebook, inputs=url_input, outputs=gr.Textbox())
207
-
208
- download_from_instagram_btn = gr.Button("Download from Instagram")
209
- download_from_instagram_btn.click(download_from_instagram, inputs=url_input, outputs=gr.Textbox())
210
-
211
- download_from_twitter_btn = gr.Button("Download from Twitter")
212
- download_from_twitter_btn.click(download_from_twitter, inputs=url_input, outputs=gr.Textbox())
213
-
214
- download_from_tiktok_btn = gr.Button("Download from TikTok")
215
- download_from_tiktok_btn.click(download_from_tiktok, inputs=url_input, outputs=gr.Textbox())
216
-
217
- download_from_reddit_btn = gr.Button("Download from Reddit")
218
- download_from_reddit_btn.click(download_from_reddit, inputs=url_input, outputs=gr.Textbox())
219
-
220
- download_from_dailymotion_btn = gr.Button("Download from Dailymotion")
221
- download_from_dailymotion_btn.click(download_from_dailymotion, inputs=url_input, outputs=gr.Textbox())
222
-
223
- download_youtube_transcript_as_text_btn = gr.Button("Download YouTube Transcript as Text")
224
- download_youtube_transcript_as_text_btn.click(download_youtube_transcript_as_text, inputs=url_input, outputs=gr.Textbox())
225
-
226
- download_youtube_transcript_as_markdown_btn = gr.Button("Download YouTube Transcript as Markdown")
227
- download_youtube_transcript_as_markdown_btn.click(download_youtube_transcript_as_markdown, inputs=url_input, outputs=gr.Textbox())
228
-
229
- download_video_info_and_save_as_json_btn = gr.Button("Download Video Info and Save as JSON")
230
- download_video_info_and_save_as_json_btn.click(download_video_info_and_save_as_json, inputs=url_input, outputs=gr.Textbox())
231
-
232
- list_available_formats_without_downloading_btn = gr.Button("List Available Formats without Downloading")
233
- list_available_formats_without_downloading_btn.click(list_available_formats_without_downloading, inputs=url_input, outputs=gr.Textbox())
234
-
235
- username_input = gr.Textbox(label="YouTube Username")
236
- password_input = gr.Textbox(label="YouTube Password", type="password")
237
- download_from_youtube_age_restricted_content_btn = gr.Button("Download from YouTube Age-Restricted Content")
238
- download_from_youtube_age_restricted_content_btn.click(download_from_youtube_age_restricted_content, inputs=[url_input, username_input, password_input], outputs=gr.Textbox())
239
-
240
- with gr.Tab("SoundCloud Commands"):
241
- with gr.Row():
242
- with gr.Column():
243
- soundcloud_url_input = gr.Textbox(label="SoundCloud URL")
244
- list_soundcloud_formats_btn = gr.Button("List Available Formats")
245
- list_soundcloud_formats_btn.click(list_available_formats, inputs=soundcloud_url_input, outputs=gr.Textbox())
246
-
247
- download_hq_mp3_from_soundcloud_btn = gr.Button("Download High-Quality MP3 from SoundCloud")
248
- download_hq_mp3_from_soundcloud_btn.click(download_hq_from_soundcloud, inputs=soundcloud_url_input, outputs=gr.Textbox())
249
-
250
- download_hq_with_metadata_from_soundcloud_btn = gr.Button("Download HQ with Metadata from SoundCloud")
251
- download_hq_with_metadata_from_soundcloud_btn.click(download_and_add_metadata_tags, inputs=soundcloud_url_input, outputs=gr.Textbox())
252
-
253
- download_entire_playlist_from_soundcloud_btn = gr.Button("Download Entire Playlist from SoundCloud")
254
- download_entire_playlist_from_soundcloud_btn.click(download_entire_playlist, inputs=soundcloud_url_input, outputs=gr.Textbox())
255
-
256
- download_entire_playlist_with_metadata_from_soundcloud_btn = gr.Button("Download Entire Playlist from SoundCloud with Metadata")
257
- download_entire_playlist_with_metadata_from_soundcloud_btn.click(download_and_add_metadata_tags, inputs=soundcloud_url_input, outputs=gr.Textbox())
258
-
259
- multiple_playlists_input = gr.Textbox(label="Multiple Playlist URLs (space-separated)")
260
- download_multiple_playlists_with_metadata_btn = gr.Button("Download Multiple Playlists with Metadata")
261
- download_multiple_playlists_with_metadata_btn.click(download_multiple_individual_files, inputs=multiple_playlists_input, outputs=gr.Textbox())
262
-
263
- playlist_range_start_input_soundcloud = gr.Textbox(label="Start Index")
264
- playlist_range_end_input_soundcloud = gr.Textbox(label="End Index")
265
- download_playlist_with_specific_range_btn = gr.Button("Download Playlist with Specific Range")
266
- download_playlist_with_specific_range_btn.click(download_playlist_specific_range, inputs=[soundcloud_url_input, playlist_range_start_input_soundcloud, playlist_range_end_input_soundcloud], outputs=gr.Textbox())
267
-
268
- embed_album_art_soundcloud_btn = gr.Button("Download and Embed Album Art")
269
- embed_album_art_soundcloud_btn.click(embed_album_art_automatically, inputs=soundcloud_url_input, outputs=gr.Textbox())
270
-
271
- skip_downloaded_soundcloud_files_btn = gr.Button("Skip Downloading Already Downloaded SoundCloud Files")
272
- skip_downloaded_soundcloud_files_btn.click(skip_already_downloaded_files, inputs=soundcloud_url_input, outputs=gr.Textbox())
273
-
274
- multiple_tracks_input = gr.Textbox(label="Multiple Track URLs (space-separated)")
275
- download_multiple_tracks_from_soundcloud_btn = gr.Button("Download Multiple Tracks from SoundCloud")
276
- download_multiple_tracks_from_soundcloud_btn.click(download_multiple_individual_files, inputs=multiple_tracks_input, outputs=gr.Textbox())
277
-
278
- download_speed_soundcloud_input = gr.Textbox(label="Download Speed (e.g., 1M)")
279
- limit_download_speed_for_soundcloud_btn = gr.Button("Limit Download Speed for SoundCloud")
280
- limit_download_speed_for_soundcloud_btn.click(download_and_limit_download_speed, inputs=[soundcloud_url_input, download_speed_soundcloud_input], outputs=gr.Textbox())
281
-
282
- split_by_chapters_soundcloud_btn = gr.Button("Download and Split by Chapters (if available)")
283
- split_by_chapters_soundcloud_btn.click(download_and_split_by_chapters, inputs=soundcloud_url_input, outputs=gr.Textbox())
284
-
285
- start_time_soundcloud_input = gr.Textbox(label="Start Time (e.g., 00:01:00)")
286
- end_time_soundcloud_input = gr.Textbox(label="End Time (e.g., 00:05:00)")
287
- extract_portion_of_soundcloud_track_btn = gr.Button("Download SoundCloud Track and Extract a Specific Portion")
288
- extract_portion_of_soundcloud_track_btn.click(extract_portion_of_video, inputs=[soundcloud_url_input, start_time_soundcloud_input, end_time_soundcloud_input], outputs=gr.Textbox())
289
-
290
- update_metadata_of_existing_soundcloud_downloads_btn = gr.Button("Update Metadata of Existing SoundCloud Downloads")
291
- update_metadata_of_existing_soundcloud_downloads_btn.click(update_metadata_of_existing_files, inputs=soundcloud_url_input, outputs=gr.Textbox())
292
-
293
- auto_rename_duplicate_soundcloud_files_btn = gr.Button("Auto-Rename Duplicate SoundCloud Files")
294
- auto_rename_duplicate_soundcloud_files_btn.click(auto_rename_duplicate_files, inputs=soundcloud_url_input, outputs=gr.Textbox())
295
-
296
- soundcloud_url_list_file_input = gr.Textbox(label="SoundCloud URL List File Path")
297
- download_from_soundcloud_url_list_file_btn = gr.Button("Download from SoundCloud URL List File")
298
- download_from_soundcloud_url_list_file_btn.click(download_from_url_list_file, inputs=soundcloud_url_list_file_input, outputs=gr.Textbox())
299
-
300
- demo.launch()
 
1
  import gradio as gr
2
  import subprocess
3
+ import os
4
+
5
+ def run_ytdlp_command(command_type, url_or_id, quality, bitrate, start_time, end_time, playlist_range, output_dir="downloads", archive_file="", sub_lang="en", additional_urls="", speed_limit="", cookies_browser=None):
6
+ """Runs the yt-dlp command based on the selected command type and parameters."""
7
+
8
+ # sanitize output_dir to prevent arbitrary code execution
9
+ output_dir = os.path.abspath(output_dir)
10
+
11
+ # Create output directory if it doesn't exist
12
+ os.makedirs(output_dir, exist_ok=True)
13
+
14
+ # Basic command structure
15
+ base_command = ["yt-dlp", "-o", f"{output_dir}/%(title)s.%(ext)s"]
16
+
17
+ # Add archive file if provided
18
+ if archive_file:
19
+ base_command.extend(["--download-archive", archive_file])
20
+
21
+ # Add cookies from browser if selected
22
+ if cookies_browser and cookies_browser != "None":
23
+ base_command.extend(["--cookies-from-browser", cookies_browser])
24
+
25
+ # Construct command based on type
26
+ if command_type == "List Formats":
27
+ command = ["yt-dlp", "-F", url_or_id]
28
+ elif command_type == "Download MP3 (Max Quality)":
29
+ command = base_command + ["-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "--postprocessor-args", "ffmpeg_a:-b:a 320k", url_or_id] # Explicit post-processor
30
+ elif command_type == "Basic MP3 Download":
31
+ command = base_command + ["-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", quality, url_or_id]
32
+ elif command_type == "Download with Custom Bitrate":
33
+ command = base_command + ["-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--postprocessor-args", f"ffmpeg_a:-b:a {bitrate}k", url_or_id] # Explicit post-processor
34
+ elif command_type == "Download with Metadata":
35
+ command = base_command + ["-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "--embed-metadata", url_or_id]
36
+ elif command_type == "Download Playlist":
37
+ command = base_command + ["-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "-o", f"{output_dir}/%(playlist_title)s/%(title)s.%(ext)s", url_or_id]
38
+ elif command_type == "Download Playlist (Range)":
39
+ command = base_command + ["--playlist-items", playlist_range, "-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "-o", f"{output_dir}/%(playlist_title)s/%(title)s.%(ext)s", url_or_id]
40
+ elif command_type == "Download with Album Art":
41
+ command = base_command + ["-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--embed-thumbnail", "--audio-quality", "0", url_or_id]
42
+ elif command_type == "Download Opus":
43
+ command = base_command + ["-f", "bestaudio", "--extract-audio", "--audio-format", "opus", url_or_id]
44
+ elif command_type == "Skip Downloaded":
45
+ command = base_command + ["--download-archive", archive_file, "-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", url_or_id]
46
+ elif command_type == "Download Multiple URLs":
47
+ if additional_urls:
48
+ urls = [url_or_id] + additional_urls.split(",")
49
+ command = base_command + ["-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "--add-metadata", "--embed-thumbnail", "--write-description", "--postprocessor-args", "ffmpeg_a:-b:a 320k", *urls] # Explicit post-processor
50
+ else:
51
+ return "Please provide additional URLs separated by commas."
52
+ elif command_type == "Download with Chapters":
53
+ command = base_command + ["-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "--split-chapters", url_or_id]
54
+ elif command_type == "Extract Portion":
55
+ command = base_command + ["-f", "bestvideo+bestaudio", "--external-downloader", "ffmpeg", "--external-downloader-args", f"ffmpeg_i:-ss {start_time} -to {end_time}", url_or_id]
56
+ elif command_type == "Update Metadata":
57
+ command = ["yt-dlp", "--download-archive", archive_file, "--skip-download", "--embed-metadata", "--embed-thumbnail", "--write-description", url_or_id]
58
+ elif command_type == "Rename Duplicate":
59
+ command = base_command + ["-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "--force-overwrites", url_or_id]
60
+ elif command_type == "Download from URL List":
61
+ command = ["yt-dlp", "-a", url_or_id, "-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "-o", f"{output_dir}/%(title)s.%(ext)s"]
62
+ elif command_type == "Limit Download Speed":
63
+ command = base_command + ["-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "--rate-limit", speed_limit, url_or_id]
64
+ elif command_type == "Download Transcript (Text)":
65
+ command = ["yt-dlp", "--write-auto-subs", "--sub-lang", sub_lang, "--skip-download", "-o", f"{output_dir}/%(title)s.%(ext)s", url_or_id]
66
+ elif command_type == "Download Transcript (Markdown)":
67
+ command = ["yt-dlp", "--write-auto-subs", "--sub-lang", sub_lang, "--skip-download", "--convert-subs", "srt", "-o", f"{output_dir}/%(title)s.md", url_or_id]
68
+ elif command_type == "Download Video Info (JSON)":
69
+ command = ["yt-dlp", "--write-info-json", "--skip-download", "-o", f"{output_dir}/%(title)s.json", url_or_id]
70
+ # SoundCloud Commands
71
+ elif command_type == "SoundCloud - Download MP3 (HQ)":
72
+ command = base_command + ["-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "-o", f"{output_dir}/SoundCloud/%(uploader)s - %(title)s.%(ext)s", url_or_id]
73
+ # ... (rest of the SoundCloud commands - apply the same fixes as above if they use postprocessor-args)
74
+ else:
75
+ return "Invalid command type selected."
76
 
 
77
  try:
78
+ # Execute command and capture output
79
+ process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
80
+ stdout, stderr = process.communicate()
81
+
82
+ # Decode output to string
83
+ stdout = stdout.decode("utf-8")
84
+ stderr = stderr.decode("utf-8")
85
+
86
+ if process.returncode != 0:
87
+ return f"Error executing command:\n{stderr}"
88
+ else:
89
+ return f"Command executed successfully:\n{stdout}"
90
+ except Exception as e:
91
+ return f"An error occurred: {e}"
92
+
93
+ # Define Gradio interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  with gr.Blocks() as demo:
95
+ gr.Markdown("# YT-DLP Gradio Interface")
96
+ with gr.Row():
97
+ with gr.Column():
98
+ # ... (other input elements)
99
+ cookies_browser = gr.Dropdown(
100
+ choices=["None", "chrome", "firefox", "edge", "opera", "chromium"], # Add more if needed
101
+ value="None",
102
+ label="Cookies from Browser"
103
+ )
104
+ submit_btn = gr.Button("Run Command")
105
+ with gr.Column():
106
+ output_text = gr.Textbox(label="Output", lines=10)
107
+
108
+ submit_btn.click(
109
+ run_ytdlp_command,
110
+ inputs=[command_type, url_or_id, quality, bitrate, start_time, end_time, playlist_range, output_dir, archive_file, sub_lang, additional_urls, speed_limit, cookies_browser], # Add cookies_browser to inputs
111
+ outputs=output_text
112
+ )
113
+
114
+ if __name__ == "__main__":
115
+ demo.launch()