Last active
April 2, 2024 22:08
-
-
Save brianyang/6502a44bb406536f6d0d14aaed122393 to your computer and use it in GitHub Desktop.
chat with youtube video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from youtube_transcript_api import YouTubeTranscriptApi | |
def fetch_and_concat_transcript(video_id): | |
try: | |
# Fetching the transcript | |
transcript_list = YouTubeTranscriptApi.get_transcript(video_id) | |
# Concatenating text from the transcript | |
concatenated_text = " ".join(item['text'] for item in transcript_list) | |
print(concatenated_text) | |
except Exception as e: | |
print(f"An error occurred: {e}") | |
return | |
if __name__ == "__main__": | |
if len(sys.argv) != 2: | |
print("Usage: script.py <YouTube Video ID>") | |
else: | |
video_id = sys.argv[1] | |
fetch_and_concat_transcript(video_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment