- for key in ('caption_file', '.......'):
- # ....... = pending vtt support that doesn't clobber srt 'chapter_file':
- url = js.get(key, '')
- if url == '' or url is None:
- continue
- if not re.match(r'^https?://', url):
- url = base_host + url
- ext = re.search(r'\.([^\.]+)$', url).group(1)
- subtitles['eng'] = [{
- 'ext': ext,
- 'url': url,
- }]
- for key in ('file', 'audio'):
- url = js.get(key, '')
- if url == '' or url is None:
+
+ def add_subtitle_item(lang, info_dict):
+ if lang not in subtitles:
+ subtitles[lang] = []
+ subtitles[lang].append(info_dict)
+
+ # chapter_file are not subtitles
+ if 'caption_file' in json_data:
+ add_subtitle_item(default_lang, {
+ 'url': compat_urlparse.urljoin(url, json_data['caption_file']),
+ })
+
+ for subtitle_item in json_data.get('captions', []):
+ lang = subtitle_item.get('language', '').lower() or default_lang
+ add_subtitle_item(lang, {
+ 'url': compat_urlparse.urljoin(url, subtitle_item['url']),
+ })
+
+ for key in ('file', 'audio', 'video'):
+ media_url = json_data.get(key, '')
+ if not media_url: