diff options
author | Yen Chi Hsuan <yan12125@gmail.com> | 2015-08-21 01:37:07 +0800 |
---|---|---|
committer | Yen Chi Hsuan <yan12125@gmail.com> | 2015-08-21 01:37:07 +0800 |
commit | 912e0b7e46d795df3ec1866f9b0ff071cca8d550 (patch) | |
tree | 7495969b17febd06366e0cf6db2b9c11d4bdc688 /youtube_dl/extractor/common.py | |
parent | 03bc7237add1747de4c0c5d09e72e03639b4fd21 (diff) |
[common] Add _merge_subtitles()
Diffstat (limited to 'youtube_dl/extractor/common.py')
-rw-r--r-- | youtube_dl/extractor/common.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py index 999afc110..b7437af5a 100644 --- a/youtube_dl/extractor/common.py +++ b/youtube_dl/extractor/common.py @@ -1279,6 +1279,26 @@ class InfoExtractor(object): def _get_subtitles(self, *args, **kwargs): raise NotImplementedError("This method must be implemented by subclasses") + @staticmethod + def _merge_subtitle_items(subtitle_list1, subtitle_list2): + """ Merge subtitle items for one language. Items with duplicated URLs + will be dropped. """ + list1_urls = set([item['url'] for item in subtitle_list1]) + ret = list(subtitle_list1) + ret.extend([item for item in subtitle_list2 if item['url'] not in list1_urls]) + return ret + + @classmethod + def _merge_subtitles(kls, subtitle_dict1, subtitle_dict2): + """ Merge two subtitle dictionaries, language by language. """ + print(subtitle_dict1) + print(subtitle_dict2) + ret = dict(subtitle_dict1) + for lang in subtitle_dict2: + ret[lang] = kls._merge_subtitle_items(subtitle_dict1.get(lang, []), subtitle_dict2[lang]) + print(ret) + return ret + def extract_automatic_captions(self, *args, **kwargs): if (self._downloader.params.get('writeautomaticsub', False) or self._downloader.params.get('listsubtitles')): |