mirror of
https://github.com/l1ving/youtube-dl
synced 2024-12-30 22:03:00 +08:00
[yahoo] Add support for closed captions (closes #5714)
This commit is contained in:
parent
1b0427e6c4
commit
ecee572411
@ -15,6 +15,7 @@ from ..utils import (
|
|||||||
unescapeHTML,
|
unescapeHTML,
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
|
mimetype2ext,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .nbc import NBCSportsVPlayerIE
|
from .nbc import NBCSportsVPlayerIE
|
||||||
@ -236,6 +237,22 @@ class YahooIE(InfoExtractor):
|
|||||||
|
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
|
closed_captions = self._html_search_regex(
|
||||||
|
r'"closedcaptions":(\[[^\]]+\])', webpage, 'closed captions',
|
||||||
|
default='[]')
|
||||||
|
|
||||||
|
cc_json = self._parse_json(closed_captions, video_id, fatal=False)
|
||||||
|
subtitles = {}
|
||||||
|
if cc_json:
|
||||||
|
for closed_caption in cc_json:
|
||||||
|
lang = closed_caption['lang']
|
||||||
|
if lang not in subtitles:
|
||||||
|
subtitles[lang] = []
|
||||||
|
subtitles[lang].append({
|
||||||
|
'url': closed_caption['url'],
|
||||||
|
'ext': mimetype2ext(closed_caption['content_type']),
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'display_id': display_id,
|
'display_id': display_id,
|
||||||
@ -244,6 +261,7 @@ class YahooIE(InfoExtractor):
|
|||||||
'description': clean_html(meta['description']),
|
'description': clean_html(meta['description']),
|
||||||
'thumbnail': meta['thumbnail'] if meta.get('thumbnail') else self._og_search_thumbnail(webpage),
|
'thumbnail': meta['thumbnail'] if meta.get('thumbnail') else self._og_search_thumbnail(webpage),
|
||||||
'duration': int_or_none(meta.get('duration')),
|
'duration': int_or_none(meta.get('duration')),
|
||||||
|
'subtitles': subtitles,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1665,6 +1665,7 @@ def mimetype2ext(mt):
|
|||||||
return {
|
return {
|
||||||
'x-ms-wmv': 'wmv',
|
'x-ms-wmv': 'wmv',
|
||||||
'x-mp4-fragmented': 'mp4',
|
'x-mp4-fragmented': 'mp4',
|
||||||
|
'ttml+xml': 'ttml',
|
||||||
}.get(res, res)
|
}.get(res, res)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user