Skip to content

Instantly share code, notes, and snippets.

@imylomylo
Created January 25, 2023 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imylomylo/edbf8eeb9b6ed634d72cc6095201e5b6 to your computer and use it in GitHub Desktop.
Save imylomylo/edbf8eeb9b6ed634d72cc6095201e5b6 to your computer and use it in GitHub Desktop.
Get YouTube video transcript into a text file
from youtube_transcript_api import YouTubeTranscriptApi
# https://www.geeksforgeeks.org/python-downloading-captions-from-youtube/
srt = YouTubeTranscriptApi.get_transcript("_6YwF1OkbVU")
with open("subtitles.txt", "w") as f:
for i in srt:
f.write("{}\n".format(i.get('text')))
# some improvements to make in future
# 1. get name of video and put that as the filename instead of subtitles.txt
# 2. accept as an argument the video id, instead of replacing the hard-coded _6YwF10kbVU manually
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment