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!
MIT License
2.54k stars 279 forks source link

KeyError video_id is 'P3pFkriw10Q' #241

Closed renine94 closed 6 months ago

renine94 commented 6 months ago

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?

For example: I am running

YouTubeTranscriptApi.get_transcript(P3pFkriw10Q, ['ar'])
YouTubeTranscriptApi.list_transcript(P3pFkriw10Q)

Which Python version are you using?

Python 3.11.3

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

youtube-transcript-api 0.6.1

Expected behavior

Describe what you expected to happen.

For example: I expected to receive the transcript

Actual behaviour

Describe what is happening instead of the Expected behavior. Add error messages if there are any.

For example: Instead I received the following error message: KeyError

# ... error message ...

  File "/Users/user/Workspace/backend/venv/lib/python3.11/site-packages/youtube_transcript_api/_transcripts.py", line 133, in build
    } for translation_language in captions_json['translationLanguages']
                                  ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'translationLanguages'
kylefoley76 commented 6 months ago

I'm getting the same result

jdepoix commented 6 months ago

Hi, thanks for reporting! It seems that YouTube has made some changes which caused the translationLanguages key to sometimes be missing from the captions json. I just published v0.6.2, which initializes translation_languages with an empty list in case that happens. So upgrading to v0.6.2 should fix this error!