/justsubs

Download subtitles from YouTube as plain text.

Primary LanguagePythonMIT LicenseMIT

justsubs

Download subtitles from YouTube as plain text.

Quick try

pip install justsubs
justsubs gBnLl3QBOdM --list
justsubs gBnLl3QBOdM > sarno.txt
justsubs --help

Pipeline

  1. Decide what captions or subtitles are available for a video;
  2. Download VTT file;
  3. Extract text from VTT1.

Install

pip install justsubs

Latest:

git clone https://github.com/epogrebnyak/justsubs.git
cd justsubs
pip install -e .

Usage

1. List subtitle options

from justsubs import Video

video = Video("KzWS7gJX5Z8")
video.list_subs()

From the output above you may need a language identifier like en-uYU-mmqFLq8, default is en.

2. Download subtitles

subtitles = Video("KzWS7gJX5Z8").vtt(language="en-uYU-mmqFLq8")
subtitles.download()

3. Print subtitles as plain text

print(subtitles.text()[:500])

Entire pipeline

from justsubs import get_text

text = get_text(video_id="KzWS7gJX5Z8", language="en-uYU-mmqFLq8")
print(text[:500])

Alternatives

Footnotes

  1. VTT conversion based on gist by glasslion.