wavesoumen commited on
Commit
221c45f
·
verified ·
1 Parent(s): 10a957f
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from youtube_transcript_api import YouTubeTranscriptApi
3
+
4
+ def Transcript(url):
5
+ id = url.split('watch?v=')
6
+
7
+ if len(id) < 2:
8
+ st.error("Invalid URL format. Please provide a valid YouTube video URL.")
9
+ return None
10
+
11
+ video_id = id[1]
12
+ try:
13
+ srt = YouTubeTranscriptApi.get_transcript(video_id)
14
+ except youtube_transcript_api._errors.TranscriptsDisabled:
15
+ st.error("Transcripts are disabled for this video.")
16
+ return None
17
+ except youtube_transcript_api._errors.NoTranscriptAvailable:
18
+ st.error("Transcript not available for the provided video.")
19
+ return None
20
+ except Exception as e:
21
+ st.error(f"An error occurred: {e}")
22
+ return None
23
+
24
+ text_list = []
25
+ for i in srt:
26
+ text_list.append(i['text'])
27
+
28
+ return ' '.join(text_list)
29
+
30
+ st.title('YouTube Video Transcript Extractor')
31
+
32
+ url = st.text_input("Enter YouTube URL:")
33
+
34
+ if st.button("Get Transcript"):
35
+ if url:
36
+ text = Transcript(url)
37
+ if text is not None:
38
+ st.success("Transcript successfully fetched!")
39
+ st.text_area("Transcript", text, height=300)
40
+ else:
41
+ st.warning("Please enter a URL.")