Created
January 25, 2023 20:43
-
-
Save imylomylo/edbf8eeb9b6ed634d72cc6095201e5b6 to your computer and use it in GitHub Desktop.
Get YouTube video transcript into a text file
This file contains hidden or 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
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