Skip to content

Instantly share code, notes, and snippets.

@brianyang
Last active April 2, 2024 22:08
Show Gist options
  • Save brianyang/6502a44bb406536f6d0d14aaed122393 to your computer and use it in GitHub Desktop.
Save brianyang/6502a44bb406536f6d0d14aaed122393 to your computer and use it in GitHub Desktop.
chat with youtube video
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