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