aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/extractor/common.py
diff options
context:
space:
mode:
authorFelix S <felix.von.s@posteo.de>2021-04-19 19:25:54 +0200
committerFelix S <felix.von.s@posteo.de>2021-04-28 17:19:46 +0530
commit19bb39202d10e171378fc407b1e0590bbb9df96b (patch)
treeff1cbaebca32023ea4b44917f596cb5d25eb1e63 /yt_dlp/extractor/common.py
parentd4553567d2f38809df2adaaf3a2257bc01d518f4 (diff)
downloadhypervideo-pre-19bb39202d10e171378fc407b1e0590bbb9df96b.tar.lz
hypervideo-pre-19bb39202d10e171378fc407b1e0590bbb9df96b.tar.xz
hypervideo-pre-19bb39202d10e171378fc407b1e0590bbb9df96b.zip
[extractor/common] Generalise _merge_subtitles
This allows modifying a subtitles dictionary in-place.
Diffstat (limited to 'yt_dlp/extractor/common.py')
-rw-r--r--yt_dlp/extractor/common.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/yt_dlp/extractor/common.py b/yt_dlp/extractor/common.py
index 4487c5375..ee8a54b66 100644
--- a/yt_dlp/extractor/common.py
+++ b/yt_dlp/extractor/common.py
@@ -3319,12 +3319,22 @@ class InfoExtractor(object):
return ret
@classmethod
- def _merge_subtitles(cls, subtitle_dict1, subtitle_dict2):
- """ Merge two subtitle dictionaries, language by language. """
- ret = dict(subtitle_dict1)
- for lang in subtitle_dict2:
- ret[lang] = cls._merge_subtitle_items(subtitle_dict1.get(lang, []), subtitle_dict2[lang])
- return ret
+ def _merge_subtitles(cls, *dicts, **kwargs):
+ """ Merge subtitle dictionaries, language by language. """
+
+ target = (lambda target=None: target)(**kwargs)
+ # The above lambda extracts the keyword argument 'target' from kwargs
+ # 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):
if (self._downloader.params.get('writeautomaticsub', False)