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.55k stars 280 forks source link

Transcript exists for video_id. Exception when attempting access via get_transcript() #212

Closed solarslurpi closed 1 year ago

solarslurpi commented 1 year 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

from youtube_transcript_api import YouTubeTranscriptApi
list_of_dicts = YouTubeTranscriptApi.get_transcript('lVY1RlrX9fc')

What code / cli command are you executing?

For example: I am running

see abpve

Which Python version are you using?

Python 3.10.11

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

youtube-transcript-api-0.6.1

Expected behavior

Describe what you expected to happen. transcript is downloaded. For example, this video_id works fine: MNlooDlfJns

I can't figure out the difference. The error indicates the html doesn't include "captions": and indeed it doesn't. I then made sure cc was checked. (which is weird if i want the transcript?) still no luck.

Actual behaviour

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

TranscriptsDisabled                       Traceback (most recent call last)
Cell In[4], line 1
----> 1 list_of_dicts = YouTubeTranscriptApi.get_transcript('lVY1RlrX9fc')
jdepoix commented 1 year ago

Hi @solarslurpi, the reason you cannot get the transcript using the api, but you can in the browser, is that the video is age-restricted. Since you are probably logged into YouTube in your browser this is no problem using a browser, but it is for the API. You can work around this by using cookies.

I know the error message is currently a bit misleading. There is a ticket to work on a more descriptive error message! 😊

solarslurpi commented 1 year ago

Thank you @jdepoix. Mostly, thank you for your library. It is so very helpful! Also, I am grateful for your reply. You are right, a better error message would be great! A couple of things I do not understand:

jdepoix commented 1 year ago

Hi @solarslurpi, thank you very much for the kind words an the support!! 🥳

To be honest, I don't quite know how the age-restriction works, but I figured that it is automatically done by YouTube and not by the uploader. Since the videos seem to be about cannabis, I would imagine that some of them contain words which YouTube links to drug abuse or something like that, and therefore applies age-restriction to them. Regarding your section question: it definitely seems that you can't retrieve the subtitle for those because they are disabled, but I unfortunately cannot tell you why they are disabled and whether that's because of YouTube or because of the uploader choosing to not enable transcripts for those. I am sorry that I do not have more information here!