Skip to main content

YouTube Transcript/Subtitle API (including automatically generated subtitles)

Donate Build Status Coverage Status MIT license image image

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

Install

It is recommended to install this module by using pip:

pip install youtube_transcript_api

If you want to use it from source, you'll have to install the dependencies manually:

pip install -r requirements.txt

How to use it

You could either integrate this module into an existing application, or just use it via an CLI

In code

To get a transcript for a given video you can do:

from youtube_transcript_api import YouTubeTranscriptApi

YouTubeTranscriptApi.get_transcript(video_id)

This will return a list of dictionaries looking somewhat like this:

[
    {
        'text': 'Hey there',
        'start': 7.58,
        'duration': 6.13
    },
    {
        'text': 'how are you',
        'start': 14.08,
        'duration': 7.58
    },
    # ...
]

You can also add the languages param if you want to make sure the transcripts are retrieved in your desired language (it usually defaults to english).

YouTubeTranscriptApi.get_transcripts(video_ids, languages=['de', 'en'])

It's a list of language codes in a descending priority. In this example it will first try to fetch the german transcript ('de') and then fetch the english transcript ('en') if it fails to do so. As I can't provide a complete list of all working language codes with full certainty, you may have to play around with the language codes a bit, to find the one which is working for you!

To get transcripts for a list fo video ids you can call:

YouTubeTranscriptApi.get_transcripts(video_ids, languages=['de', 'en'])

languages also is optional here.

CLI

Execute the CLI script using the video ids as parameters and the results will be printed out to the command line:

youtube_transcript_api <first_video_id> <second_video_id> ...

The CLI also gives you the option to provide a list of preferred languages:

youtube_transcript_api <first_video_id> <second_video_id> ... --languages de en

If you would prefer to write it into a file or pipe it into another application, you can also output the results as json using the following line:

youtube_transcript_api <first_video_id> <second_video_id> ... --languages de en --json > transcripts.json

Proxy

You can specify a https/http proxy, which will be used during the requests to YouTube:

from youtube_transcript_api import YouTubeTranscriptApi

YouTubeTranscriptApi.get_transcript(video_id, proxies={"http": "http://user:pass@domain:port", "https": "https://user:pass@domain:port"})

As the proxies dict is passed on to the requests.get(...) call, it follows the format used by the requests library.

Using the CLI:

youtube_transcript_api <first_video_id> <second_video_id> --http-proxy http://user:pass@domain:port --https-proxy https://user:pass@domain:port

Warning

This code uses an undocumented part of the YouTube API, which is called by the YouTube web-client. So there is no guarantee that it won't stop working tomorrow, if they change how things work. I will however do my best to make things working again as soon as possible if that happens. So if it stops working, let me know!

Donation

If this project makes you happy by reducing your development time, you can make me happy by treating me to a cup of coffee :)

Donate

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

youtube_transcript_api-0.1.9.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

youtube_transcript_api-0.1.9-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file youtube_transcript_api-0.1.9.tar.gz.

File metadata

  • Download URL: youtube_transcript_api-0.1.9.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/41.4.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

File hashes

Hashes for youtube_transcript_api-0.1.9.tar.gz
Algorithm Hash digest
SHA256 995f9ce91fcdf996cb6f02d82bc7c8afcb059f754e8fbe59c288e813c7e0c111
MD5 f5b8458cb825c4123f55854039b08888
BLAKE2b-256 30527f50ec2a014a66bc5ab7c5f459e6291e83a3bcfa50326791f0858f39cd58

See more details on using hashes here.

File details

Details for the file youtube_transcript_api-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: youtube_transcript_api-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/41.4.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

File hashes

Hashes for youtube_transcript_api-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 ebb828d7f08c146c5977b40cd9dd3763c8117b8acc58cb937d67c16f94ea6f29
MD5 4cf640a54c8b624f31c65c3879c62fa3
BLAKE2b-256 b7f80c6d080ec15a90f511b4519598a7728e741b231b447e80603c3b5b008344

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page