
YouTube Transcript API Module allows you to easily get the text transcript of a YouTube video with timestamp.
NOTE: The module only accepts the Video ID so we run 2 replace methods to remove the rest of the URL to make it easier to copy/paste a YouTube video into the script.
Install Python Module
pip3 install youtube-transcript-api
yt-transcript.py
from youtube_transcript_api import YouTubeTranscriptApi
url = "https://www.youtube.com/watch?v=CQCnmsyl61Q"
print(url)
video_id = url.replace("https://youtu.be/", "")
video_id = url.replace("https://www.youtube.com/watch?v=", "")
print(video_id)
transcript = YouTubeTranscriptApi.get_transcript(video_id)
print(transcript)
output=""
for x in transcript:
sentence = x['text']
output += f' {sentence}\n'
print(output)
Code language: PHP (php)