mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-15 07:42:42 +00:00
[extractor/common] Generalise _merge_subtitles
This allows modifying a subtitles dictionary in-place.
This commit is contained in:
parent
d4553567d2
commit
19bb39202d
1 changed files with 16 additions and 6 deletions
|
@ -3319,12 +3319,22 @@ class InfoExtractor(object):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _merge_subtitles(cls, subtitle_dict1, subtitle_dict2):
|
def _merge_subtitles(cls, *dicts, **kwargs):
|
||||||
""" Merge two subtitle dictionaries, language by language. """
|
""" Merge subtitle dictionaries, language by language. """
|
||||||
ret = dict(subtitle_dict1)
|
|
||||||
for lang in subtitle_dict2:
|
target = (lambda target=None: target)(**kwargs)
|
||||||
ret[lang] = cls._merge_subtitle_items(subtitle_dict1.get(lang, []), subtitle_dict2[lang])
|
# The above lambda extracts the keyword argument 'target' from kwargs
|
||||||
return ret
|
# while ensuring there are no stray ones. When Python 2 support
|
||||||
|
# is dropped, remove it and change the function signature to:
|
||||||
|
#
|
||||||
|
# def _merge_subtitles(cls, *dicts, target=None):
|
||||||
|
|
||||||
|
if target is None:
|
||||||
|
target = {}
|
||||||
|
for d in dicts:
|
||||||
|
for lang, subs in d.items():
|
||||||
|
target[lang] = cls._merge_subtitle_items(target.get(lang, []), subs)
|
||||||
|
return target
|
||||||
|
|
||||||
def extract_automatic_captions(self, *args, **kwargs):
|
def extract_automatic_captions(self, *args, **kwargs):
|
||||||
if (self._downloader.params.get('writeautomaticsub', False)
|
if (self._downloader.params.get('writeautomaticsub', False)
|
||||||
|
|
Loading…
Reference in a new issue