0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-29 03:23:02 +00:00

Add field name for subtitles

Co-authored by: pukkandan, tpikonen

Based on: #310, https://github.com/ytdl-org/youtube-dl/pull/26112
This commit is contained in:
pukkandan 2021-05-13 01:07:58 +05:30
parent 120916dac2
commit 2412044c90
No known key found for this signature in database
GPG key ID: 0F00D95A001F4698
3 changed files with 18 additions and 6 deletions

View file

@ -3005,10 +3005,17 @@ def list_subtitles(self, video_id, subtitles, name='subtitles'):
return return
self.to_screen( self.to_screen(
'Available %s for %s:' % (name, video_id)) 'Available %s for %s:' % (name, video_id))
def _row(lang, formats):
exts, names = zip(*((f['ext'], f['name']) for f in reversed(formats)))
if len(set(names)) == 1:
names = names[:1]
return [lang, ', '.join(names), ', '.join(exts)]
self.to_screen(render_table( self.to_screen(render_table(
['Language', 'formats'], ['Language', 'Name', 'Formats'],
[[lang, ', '.join(f['ext'] for f in reversed(formats))] [_row(lang, formats) for lang, formats in subtitles.items()],
for lang, formats in subtitles.items()])) hideEmpty=True))
def urlopen(self, req): def urlopen(self, req):
""" Start an HTTP download """ """ Start an HTTP download """

View file

@ -250,6 +250,8 @@ class InfoExtractor(object):
entry and one of: entry and one of:
* "data": The subtitles file contents * "data": The subtitles file contents
* "url": A URL pointing to the subtitles file * "url": A URL pointing to the subtitles file
It can optionally also have:
* "name": Name or description of the subtitles
"ext" will be calculated from URL if missing "ext" will be calculated from URL if missing
automatic_captions: Like 'subtitles'; contains automatically generated automatic_captions: Like 'subtitles'; contains automatically generated
captions instead of normal subtitles captions instead of normal subtitles

View file

@ -474,8 +474,7 @@ def run(self, information):
filename = information['filepath'] filename = information['filepath']
ext = information['ext'] ext = information['ext']
sub_langs = [] sub_langs, sub_names, sub_filenames = [], [], []
sub_filenames = []
webm_vtt_warn = False webm_vtt_warn = False
mp4_ass_warn = False mp4_ass_warn = False
@ -485,6 +484,7 @@ def run(self, information):
self.report_warning('JSON subtitles cannot be embedded') self.report_warning('JSON subtitles cannot be embedded')
elif ext != 'webm' or ext == 'webm' and sub_ext == 'vtt': elif ext != 'webm' or ext == 'webm' and sub_ext == 'vtt':
sub_langs.append(lang) sub_langs.append(lang)
sub_names.append(sub_info.get('name'))
sub_filenames.append(sub_info['filepath']) sub_filenames.append(sub_info['filepath'])
else: else:
if not webm_vtt_warn and ext == 'webm' and sub_ext != 'vtt': if not webm_vtt_warn and ext == 'webm' and sub_ext != 'vtt':
@ -510,10 +510,13 @@ def run(self, information):
] ]
if information['ext'] == 'mp4': if information['ext'] == 'mp4':
opts += ['-c:s', 'mov_text'] opts += ['-c:s', 'mov_text']
for (i, lang) in enumerate(sub_langs): for i, (lang, name) in enumerate(zip(sub_langs, sub_names)):
opts.extend(['-map', '%d:0' % (i + 1)]) opts.extend(['-map', '%d:0' % (i + 1)])
lang_code = ISO639Utils.short2long(lang) or lang lang_code = ISO639Utils.short2long(lang) or lang
opts.extend(['-metadata:s:s:%d' % i, 'language=%s' % lang_code]) opts.extend(['-metadata:s:s:%d' % i, 'language=%s' % lang_code])
if name:
opts.extend(['-metadata:s:s:%d' % i, 'handler_name=%s' % name,
'-metadata:s:s:%d' % i, 'title=%s' % name])
temp_filename = prepend_extension(filename, 'temp') temp_filename = prepend_extension(filename, 'temp')
self.to_screen('Embedding subtitles in "%s"' % filename) self.to_screen('Embedding subtitles in "%s"' % filename)