# pip install youtube_transcript_api from youtube_transcript_api import YouTubeTranscriptApi video_link = 'https://www.youtube.com/watch?v=Vdj1TNWJAZ4&t=8s' video_id = video_link.split('watch?v=') subtitle = YouTubeTranscriptApi.get_transcript(video_id=video_id, languages=['en']) # you can do anything with downloaded caption. # for example: print(subtitle)
Here is what the above code is Doing:
1. We are importing the YouTubeTranscriptApi library.
2. We are storing the video link in a variable.
3. We are extracting the video id from the video link.
4. We are downloading the caption of the video using the video id.
5. We are printing the caption.