wavesoumen/YouTube_Script
0
1import streamlit as st2from youtube_transcript_api import YouTubeTranscriptApi3 4def 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 None10 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 None17 except youtube_transcript_api._errors.NoTranscriptAvailable:18 st.error("Transcript not available for the provided video.")19 return None20 except Exception as e:21 st.error(f"An error occurred: {e}")22 return None23 24 text_list = []25 for i in srt:26 text_list.append(i['text'])27 28 return ' '.join(text_list)29 30st.title('YouTube Video Transcript Extractor')31 32url = st.text_input("Enter YouTube URL:")33 34if 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.")42 