aboutsummaryrefslogtreecommitdiffstats
path: root/hypervideo_dl/extractor/naver.py
diff options
context:
space:
mode:
Diffstat (limited to 'hypervideo_dl/extractor/naver.py')
-rw-r--r--hypervideo_dl/extractor/naver.py35
1 files changed, 18 insertions, 17 deletions
diff --git a/hypervideo_dl/extractor/naver.py b/hypervideo_dl/extractor/naver.py
index e2e6e97..d79caf5 100644
--- a/hypervideo_dl/extractor/naver.py
+++ b/hypervideo_dl/extractor/naver.py
@@ -21,6 +21,23 @@ from ..utils import (
class NaverBaseIE(InfoExtractor):
_CAPTION_EXT_RE = r'\.(?:ttml|vtt)'
+ @staticmethod # NB: Used in VLiveWebArchiveIE, WeverseIE
+ def process_subtitles(vod_data, process_url):
+ ret = {'subtitles': {}, 'automatic_captions': {}}
+ for caption in traverse_obj(vod_data, ('captions', 'list', ...)):
+ caption_url = caption.get('source')
+ if not caption_url:
+ continue
+ type_ = 'automatic_captions' if caption.get('type') == 'auto' else 'subtitles'
+ lang = caption.get('locale') or join_nonempty('language', 'country', from_dict=caption) or 'und'
+ if caption.get('type') == 'fan':
+ lang += '_fan%d' % next(i for i in itertools.count(1) if f'{lang}_fan{i}' not in ret[type_])
+ ret[type_].setdefault(lang, []).extend({
+ 'url': sub_url,
+ 'name': join_nonempty('label', 'fanName', from_dict=caption, delim=' - '),
+ } for sub_url in process_url(caption_url))
+ return ret
+
def _extract_video_info(self, video_id, vid, key):
video_data = self._download_json(
'http://play.rmcnmv.naver.com/vod/play/v2.0/' + vid,
@@ -79,34 +96,18 @@ class NaverBaseIE(InfoExtractor):
]
return [caption_url]
- automatic_captions = {}
- subtitles = {}
- for caption in get_list('caption'):
- caption_url = caption.get('source')
- if not caption_url:
- continue
- sub_dict = automatic_captions if caption.get('type') == 'auto' else subtitles
- lang = caption.get('locale') or join_nonempty('language', 'country', from_dict=caption) or 'und'
- if caption.get('type') == 'fan':
- lang += '_fan%d' % next(i for i in itertools.count(1) if f'{lang}_fan{i}' not in sub_dict)
- sub_dict.setdefault(lang, []).extend({
- 'url': sub_url,
- 'name': join_nonempty('label', 'fanName', from_dict=caption, delim=' - '),
- } for sub_url in get_subs(caption_url))
-
user = meta.get('user', {})
return {
'id': video_id,
'title': title,
'formats': formats,
- 'subtitles': subtitles,
- 'automatic_captions': automatic_captions,
'thumbnail': try_get(meta, lambda x: x['cover']['source']),
'view_count': int_or_none(meta.get('count')),
'uploader_id': user.get('id'),
'uploader': user.get('name'),
'uploader_url': user.get('url'),
+ **self.process_subtitles(video_data, get_subs),
}