DeeeeeeM commited on
Commit
a4eb07e
·
1 Parent(s): e52ccdb

Added additional features in .SRT downloader

Browse files
Files changed (4) hide show
  1. app.py +76 -31
  2. requirements-gpu.txt +2 -1
  3. requirements.txt +2 -1
  4. ssui-app.code-workspace +7 -0
app.py CHANGED
@@ -13,7 +13,6 @@ import os
13
  import subprocess
14
  import glob
15
  import shutil
16
- import unicodedata
17
 
18
  def process_media(
19
  model_size, source_lang, upload, model_type,
@@ -39,7 +38,6 @@ def process_media(
39
  language=source_lang,
40
  vad=True,
41
  regroup=False,
42
- #no_speech_threshold=0.9,
43
  #denoiser="demucs",
44
  #batch_size=16,
45
  initial_prompt=initial_prompt
@@ -112,8 +110,6 @@ def process_media(
112
  audio_out = temp_path if mime and mime.startswith("audio") else None
113
  video_out = temp_path if mime and mime.startswith("video") else None
114
 
115
- elapsed = time.time() - start_time
116
- print(f"process_media completed in {elapsed:.2f} seconds")
117
 
118
  return audio_out, video_out, transcript_txt, srt_file_path
119
 
@@ -198,34 +194,67 @@ def extract_playlist_to_csv(playlist_url):
198
  except Exception as e:
199
  return None
200
 
201
- def download_srt(video_url):
202
  try:
203
- temp_dir = tempfile.mkdtemp()
204
- output_template = os.path.join(temp_dir, "%(id)s.%(ext)s")
205
- cmd = [
206
- "yt-dlp",
207
- "--write-subs",
208
- "--write-auto-subs",
209
- "--sub-lang", "en-US",
210
- "--skip-download",
211
- "--convert-subs", "srt",
212
- "-o", output_template,
213
- video_url
214
- ]
215
- result = subprocess.run(cmd, check=True, capture_output=True, text=True)
216
- print(result.stdout)
217
- print(result.stderr)
218
- srt_files = glob.glob(os.path.join(temp_dir, "*.srt"))
219
- if srt_files:
220
- return srt_files[0]
221
  else:
222
- vtt_files = glob.glob(os.path.join(temp_dir, "*.vtt"))
223
- if vtt_files:
224
- return vtt_files[0]
 
 
 
 
225
  return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  except Exception as e:
227
  print("SRT download error:", e)
228
- return None
 
229
 
230
  def check_youtube_tag(video_url, tag_to_check):
231
 
@@ -560,17 +589,17 @@ with gr.Blocks() as interface:
560
  outputs=csv_output
561
  )
562
 
563
- with gr.TabItem(".srt Downloader"):
564
- gr.Markdown("### Download English subtitles (.srt) from a YouTube video.###")
565
 
566
-
567
  srt_url = gr.Textbox(label="YouTube Video URL", placeholder="Paste video URL here")
568
  srt_btn = gr.Button("Process")
569
  srt_file = gr.File(label="Download SRT")
 
570
  srt_btn.click(
571
  download_srt,
572
  inputs=srt_url,
573
- outputs=srt_file
574
  )
575
 
576
  with gr.TabItem("Tag Checker"):
@@ -604,5 +633,21 @@ with gr.Blocks() as interface:
604
  outputs=tag_output_playlist
605
  )
606
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
607
 
608
  interface.launch(share=True)
 
13
  import subprocess
14
  import glob
15
  import shutil
 
16
 
17
  def process_media(
18
  model_size, source_lang, upload, model_type,
 
38
  language=source_lang,
39
  vad=True,
40
  regroup=False,
 
41
  #denoiser="demucs",
42
  #batch_size=16,
43
  initial_prompt=initial_prompt
 
110
  audio_out = temp_path if mime and mime.startswith("audio") else None
111
  video_out = temp_path if mime and mime.startswith("video") else None
112
 
 
 
113
 
114
  return audio_out, video_out, transcript_txt, srt_file_path
115
 
 
194
  except Exception as e:
195
  return None
196
 
197
+ def download_srt(video_urls):
198
  try:
199
+ if not video_urls:
200
+ return None
201
+
202
+ if isinstance(video_urls, (list, tuple)):
203
+ urls = [u.strip() for u in video_urls if u and u.strip()]
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  else:
205
+ parts = []
206
+ for line in str(video_urls).splitlines():
207
+ for part in line.split(','):
208
+ parts.append(part.strip())
209
+ urls = [p for p in parts if p]
210
+
211
+ if not urls:
212
  return None
213
+
214
+ downloads_dir = os.path.join(os.path.expanduser("~"), "Downloads")
215
+ output_template = os.path.join(downloads_dir, "%(id)s.%(ext)s")
216
+
217
+ for url in urls:
218
+ if not url:
219
+ continue
220
+ cmd = [
221
+ "yt-dlp",
222
+ "--write-subs",
223
+ "--write-auto-subs",
224
+ "--sub-lang", "en-US",
225
+ "--skip-download",
226
+ "--convert-subs", "srt",
227
+ "-o", output_template,
228
+ url
229
+ ]
230
+ try:
231
+ result = subprocess.run(cmd, check=True, capture_output=True, text=True)
232
+ print(result.stdout)
233
+ print(result.stderr)
234
+ except Exception as e:
235
+ print(f"SRT download error for {url}: {e}")
236
+
237
+ srt_files = glob.glob(os.path.join(downloads_dir, "*.srt"))
238
+ vtt_files = glob.glob(os.path.join(downloads_dir, "*.vtt"))
239
+ all_files = srt_files + vtt_files
240
+
241
+ if not all_files:
242
+ # No subtitle files were found in Downloads
243
+ return None, "No subtitle files found in Downloads."
244
+
245
+ if len(all_files) == 1:
246
+ # Single subtitle file found, return its path and a friendly message
247
+ return all_files[0], f"Downloaded subtitle saved to {downloads_dir}"
248
+
249
+ # Multiple subtitle files: create a zip archive and return its path
250
+ zip_base = os.path.join(downloads_dir, "srt_files")
251
+ zip_path = shutil.make_archive(zip_base, "zip", downloads_dir)
252
+ return zip_path, f"Multiple subtitle files archived to {zip_path}"
253
+
254
  except Exception as e:
255
  print("SRT download error:", e)
256
+ # Return no file and a human-friendly message
257
+ return None, "Saved in Downloads"
258
 
259
  def check_youtube_tag(video_url, tag_to_check):
260
 
 
589
  outputs=csv_output
590
  )
591
 
592
+ with gr.TabItem("SRT Downloader"):
593
+ gr.Markdown("### Download English subtitles (.srt) from a YouTube video(s). <i>Separate each URL with a comma or Enter for multiple videos.</i>")
594
 
 
595
  srt_url = gr.Textbox(label="YouTube Video URL", placeholder="Paste video URL here")
596
  srt_btn = gr.Button("Process")
597
  srt_file = gr.File(label="Download SRT")
598
+ srt_status = gr.Textbox(label="Status", interactive=False)
599
  srt_btn.click(
600
  download_srt,
601
  inputs=srt_url,
602
+ outputs=[srt_file, srt_status]
603
  )
604
 
605
  with gr.TabItem("Tag Checker"):
 
633
  outputs=tag_output_playlist
634
  )
635
 
636
+ gr.HTML(
637
+ """
638
+ <audio id="notify-audio" src="https://www.soundjay.com/buttons/sounds/button-3.mp3"></audio>
639
+ <script>
640
+ function playNotify() {
641
+ var audio = document.getElementById('notify-audio');
642
+ if (audio) { audio.play(); }
643
+ }
644
+ let outputs = document.querySelectorAll("textarea, input[type='file'], video, audio");
645
+ outputs.forEach(function(output) {
646
+ output.addEventListener("change", playNotify);
647
+ });
648
+ });
649
+ </script>
650
+ """
651
+ )
652
 
653
  interface.launch(share=True)
requirements-gpu.txt CHANGED
@@ -6,4 +6,5 @@ torch==2.6.0+cu124
6
  numpy>=1.24,<2.3
7
  sympy==1.13.1
8
  chardet
9
- yt-dlp
 
 
6
  numpy>=1.24,<2.3
7
  sympy==1.13.1
8
  chardet
9
+ yt-dlp
10
+ ffmpeg
requirements.txt CHANGED
@@ -6,4 +6,5 @@ torch==2.6.0
6
  numpy>=1.24,<2.3
7
  sympy==1.13.1
8
  chardet
9
- yt-dlp
 
 
6
  numpy>=1.24,<2.3
7
  sympy==1.13.1
8
  chardet
9
+ yt-dlp
10
+ ffmpeg
ssui-app.code-workspace ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "folders": [
3
+ {
4
+ "path": "."
5
+ }
6
+ ]
7
+ }