Skip to content

Instantly share code, notes, and snippets.

@rabbitix
Created January 13, 2021 07:15
Show Gist options
  • Save rabbitix/d6a2956f1f237dffa361523db6cdf9f3 to your computer and use it in GitHub Desktop.
Save rabbitix/d6a2956f1f237dffa361523db6cdf9f3 to your computer and use it in GitHub Desktop.
download caption of a yt video
from pytube import YouTube
source = YouTube('https://www.youtube.com/watch?v=KR0g-1hnQPA&feature=emb_logo')
en_caption = source.captions.get_by_language_code('en')
en_caption_convert_to_srt =(en_caption.generate_srt_captions())
print(en_caption_convert_to_srt)
#save the caption to a file named Output.txt
text_file = open("cap.txt", "w")
text_file.write(en_caption_convert_to_srt)
text_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment