Manasa1 commited on
Commit
2569351
·
verified ·
1 Parent(s): a468187

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -53,13 +53,27 @@ def get_youtube_captions(youtube_url):
53
  """
54
  yt = YouTube(youtube_url)
55
 
56
- # Check if captions are available in English (you can modify this language)
57
- if 'en' in yt.captions:
58
- caption = yt.captions['en']
59
- return caption.generate_srt_captions() # Return captions in SRT format
 
 
 
 
 
 
 
 
 
 
 
 
60
  else:
61
  return "No captions available for this video."
62
 
 
 
63
  # YouTube video URL input
64
  youtube_url = st.text_input(
65
  "Enter the YouTube video link",
 
53
  """
54
  yt = YouTube(youtube_url)
55
 
56
+ # List available caption tracks
57
+ caption_tracks = yt.caption_tracks
58
+ available_languages = [track.language_code for track in caption_tracks]
59
+
60
+ if available_languages:
61
+ st.write(f"Available caption languages: {', '.join(available_languages)}")
62
+
63
+ # You can set a fallback language or prompt the user to select
64
+ language = 'en' # Change this to any available language from the list
65
+
66
+ # Check if the chosen language exists in the video
67
+ if language in yt.captions:
68
+ caption = yt.captions[language]
69
+ return caption.generate_srt_captions() # Return captions in SRT format
70
+ else:
71
+ return f"Captions not available in the selected language ({language})."
72
  else:
73
  return "No captions available for this video."
74
 
75
+
76
+
77
  # YouTube video URL input
78
  youtube_url = st.text_input(
79
  "Enter the YouTube video link",