Skip to content

Commit 83db41d

Browse files
committed
Add subtitle support
Following a user request, YDL_SUBTITLES_LANGUAGES variable has been added, and can be set to: - None (default) to not download subtitles - 'all' to get all available subtitles - a coma separated list of languages to fetch, for example 'en,es'
1 parent 25f227a commit 83db41d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

youtube-dl-server.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class QueueAction:
3030
'YDL_SERVER_PORT': 8080,
3131
'YDL_CACHE_DIR': '/youtube-dl/.cache',
3232
'YDL_DB_PATH': '/youtube-dl/.ydl-metadata.db',
33+
'YDL_SUBTITLES_LANGUAGES': None,
3334
}
3435

35-
3636
@app.route('/')
3737
def front_index():
3838
return static_file('index.html', root='./')
@@ -142,14 +142,23 @@ def get_ydl_options(request_options):
142142
'preferedformat': ydl_vars['YDL_RECODE_VIDEO_FORMAT'],
143143
})
144144

145-
return {
145+
ydl_options = {
146146
'format': ydl_vars['YDL_FORMAT'],
147147
'postprocessors': postprocessors,
148148
'outtmpl': ydl_vars['YDL_OUTPUT_TEMPLATE'],
149149
'download_archive': ydl_vars['YDL_ARCHIVE_FILE'],
150150
'cachedir': ydl_vars['YDL_CACHE_DIR']
151151
}
152152

153+
if ydl_vars['YDL_SUBTITLES_LANGUAGES']:
154+
ydl_options['writesubtitles'] = True
155+
if ydl_vars['YDL_SUBTITLES_LANGUAGES'] != 'all':
156+
ydl_options['subtitleslangs'] = \
157+
ydl_vars['YDL_SUBTITLES_LANGUAGES'].split(',')
158+
else:
159+
ydl_options['allsubtitles'] = True
160+
161+
return ydl_options
153162

154163
def download(url, request_options):
155164
with youtube_dl.YoutubeDL(get_ydl_options(request_options)) as ydl:

0 commit comments

Comments
 (0)