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

get_transcript() not working. But works if using fetch(). #145

Closed pohnson closed 2 years ago

pohnson commented 2 years ago

OS: Mac Monterey 12.2.1 Python Version: 3.8 Package Version: 0.4.3 Demonstrated Video: https://www.youtube.com/watch?v=zeRJRBNRrpA

Summary I got an error if I use get_transcript() directly. But if I were to use list_transcript(), find_transcript(), and fetch(), it works just fine.

get_transcript Way

from youtube_transcript_api import YouTubeTranscriptApi

transcript = YouTubeTranscriptApi.get_transcripts(
    video_ids='zeRJRBNRrpA'
)
transcript = YouTubeTranscriptApi.get_transcripts(
    video_ids='zeRJRBNRrpA’,
    languages=‘en’
)

Error Screen

Fetch Way

from youtube_transcript_api import YouTubeTranscriptApi

transcript_list = YouTubeTranscriptApi.list_transcripts(
    'zeRJRBNRrpA'
)

transcript = transcript_list.find_transcript(['en'])

final = transcript.fetch()

Success

Please let me know if you need additional information.

jdepoix commented 2 years ago

HI @pohnson, if you're using get_transcripts the param video_ids has to be a list of video ids, not a string. So either supply a list (video_ids=['zeRJRBNRrpA']) or use get_transcript instead.