Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading subtitles using youtube_dl

Tags:

I am looking to download a video with subtitles using the Youtube_dl library. Currently, I am able to download a single video at a time but I am unable to download subtitles with it.

Currently, my implementation is:

import youtube_dl

link = input('Please enter a url link:\n')

youtube_dl_options = {}

with youtube_dl.YoutubeDL(youtube_dl_options) as youtube_dl_client:
    youtube_dl_client.download([link])

I would like to be able to download the subtitle as well as the video with it.

like image 447
Anish Mazumdar Avatar asked Feb 21 '19 15:02

Anish Mazumdar


People also ask

How do I download a subtitle file?

The easiest way is to visit a subtitle website, search for your TV show or movie and download the SRT file. The two most popular sites for getting subtitles are Subscene and OpenSubtitles.org. On OpenSubtitles, perform a search and then you'll see all the available subtitles for different languages at the bottom.


1 Answers

The youtube_dl project is hosted on github (https://github.com/rg3/youtube-dl/blob/master/youtube_dl/YoutubeDL.py)

Looking at the YoutubeDL module it looks like there are a bunch of options (see lines 142-298, the one you want is on line 183).

You can pass the option using the dictionary ydl_opts

Try changing ydl_opts to this:

ydl_opts = {"writesubtitles": True}
like image 138
AllenMoh Avatar answered Oct 22 '22 12:10

AllenMoh