jdepoix / youtube-transcript-api

This is a python API which allows you to get the transcript/subtitles for a given YouTube video. It also works for automatically generated subtitles and it does not require an API key nor a headless browser, like other selenium based solutions do!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

transcript cannot be retrieved

Sihaam20 opened this issue · comments

DO NOT DELETE THIS! Please take the time to fill this out properly. I am not able to help you if I do not know what you are executing and what error messages you are getting. If you are having problems with a specific video make sure to include the video id.

To Reproduce

Steps to reproduce the behavior:

What code / cli command are you executing?

!pip install youtube_transcript_api

from youtube_transcript_api import YouTubeTranscriptApi

def get_transcript(video_url):

try:
# Extract video ID from the URL
video_id = video_url.split("=")[1]
transcript = YouTubeTranscriptApi.get_transcript(video_id)
return transcript
except Exception as e:
print(f"Error retrieving transcript: {e}")
return []

Example usage

video_link = input("Enter the YouTube video URL: ")
transcript = get_transcript(video_link)

if transcript:
print("Transcript:")
for segment in transcript:
print(f"{segment['start']} - {segment['end']}: {segment['text']}")
else:
print("Transcript not found for the provided video.")

YouTubeTranscriptApi.get_transcript ...

Which Python version are you using?

Python x.y

Which version of youtube-transcript-api are you using?

youtube-transcript-api x.y.z

Expected behavior

I expected to receive the english transcript

Actual behaviour

Error retrieving transcript:
Could not retrieve a transcript for the video https://www.youtube.com/watch?v=qc3QhQAO3JS73RrB! This is most likely caused by:

Subtitles are disabled for this video

If you are sure that the described cause is not responsible for this error and that a transcript should be retrievable, please create an issue at https://github.com/jdepoix/youtube-transcript-api/issues. Please add which version of youtube_transcript_api you are using and provide the information needed to replicate the error. Also make sure that there are no open issues which already describe your problem!
Transcript not found for the provided video.

For example: Instead I received the following error message:

# ... error message ...

Hi @Sihaam20, when I try to open the video https://www.youtube.com/watch?v=qc3QhQAO3JS73RrB in a browser, it says "Video is not available anymore". So it makes that the transcripts cannot be retrieved.