Spaces:
Build error
Build error
| import streamlit as st | |
| from youtube_transcript_api import YouTubeTranscriptApi | |
| def get_video_id(url): | |
| from urllib.parse import urlparse, parse_qs | |
| query = urlparse(url) | |
| if query.hostname == 'youtu.be': | |
| return query.path[1:] | |
| if query.hostname in ('www.youtube.com', 'youtube.com'): | |
| if query.path == '/watch': | |
| p = parse_qs(query.query) | |
| return p['v'][0] | |
| if query.path[:7] == '/embed/': | |
| return query.path.split('/')[2] | |
| if query.path[:3] == '/v/': | |
| return query.path.split('/')[2] | |
| return None | |
| def get_transcript(video_id): | |
| try: | |
| transcript = YouTubeTranscriptApi.get_transcript(video_id) | |
| return ' '.join([entry['text'] for entry in transcript]) | |
| except Exception as e: | |
| return str(e) | |
| st.title('YouTube Transcript Reader') | |
| url = st.text_input('Enter YouTube URL') | |
| if url: | |
| video_id = get_video_id(url) | |
| if video_id: | |
| transcript = get_transcript(video_id) | |
| st.write(transcript) | |
| else: | |
| st.write('Invalid YouTube URL') | |