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.")