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.87k stars 326 forks source link

KeyError: 'playerCaptionsTracklistRenderer' #136

Closed xenova closed 2 years ago

xenova commented 2 years ago
$ python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from youtube_transcript_api import YouTubeTranscriptApi
>>> 
>>> YouTubeTranscriptApi.get_transcript('Fjg5lYqvzUs') 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\joshu\AppData\Local\Programs\Python\Python38\lib\site-packages\youtube_transcript_api\_api.py", line 128, in get_transcript
    return cls.list_transcripts(video_id, proxies, cookies).find_transcript(languages).fetch()
  File "C:\Users\joshu\AppData\Local\Programs\Python\Python38\lib\site-packages\youtube_transcript_api\_api.py", line 70, in list_transcripts
    return TranscriptListFetcher(http_client).fetch(video_id)
  File "C:\Users\joshu\AppData\Local\Programs\Python\Python38\lib\site-packages\youtube_transcript_api\_transcripts.py", line 47, in fetch
    self._extract_captions_json(self._fetch_video_html(video_id), video_id)
  File "C:\Users\joshu\AppData\Local\Programs\Python\Python38\lib\site-packages\youtube_transcript_api\_transcripts.py", line 61, in _extract_captions_json
    captions_json = json.loads(
KeyError: 'playerCaptionsTracklistRenderer'
>>> YouTubeTranscriptApi.get_transcript('dZ5Uicedipc') 
[{'text': '[Music]', 'start': 0.59, 'duration': 2.14}, ...

I am using the latest version (0.4.2):

$ pip install --upgrade youtube_transcript_api
Requirement already satisfied: youtube_transcript_api in c:\users\joshu\appdata\local\programs\python\python38\lib\site-packages (0.4.2)

I don't believe this is an issue with rate limiting or anything as it works perfectly fine on all other videos. In fact, I have downloaded transcripts for over 40000 videos and never had an issue.

If this error cannot be reproduced on your side, I will gladly give more information. Thanks 👍

jdepoix commented 2 years ago

Hi @xenova, thanks for reporting, I can replicate this error. It seems like subtitles are disabled on Fjg5lYqvzUs, however, a TranscriptDisabled exception should be raised. I will look into this as soon as I can.

xenova commented 2 years ago

Great, thanks! 👍

Strange that it happens on only 1 of the 40k+ videos I've been working on.

xenova commented 2 years ago

If you want, I can provide a pull request to fix it.

jdepoix commented 2 years ago

That would be greatly appreciated, as I am currently a bit short on time!! 😊

xenova commented 2 years ago

A very simple fix: https://github.com/jdepoix/youtube-transcript-api/pull/137