Compare commits

..

No commits in common. "1d43d1f47900977e14e4365060948377cb3379ea" and "ef0c79214a49d5547ab5d44e6a243f125b8e9eb7" have entirely different histories.

View File

@ -422,30 +422,25 @@ class FacebookIE(InfoExtractor):
..., 'require', ..., ..., ..., '__bbox', 'require', ..., ..., ..., '__bbox', 'result', 'data'), expected_type=dict) or [] ..., 'require', ..., ..., ..., '__bbox', 'require', ..., ..., ..., '__bbox', 'result', 'data'), expected_type=dict) or []
snippet = traverse_obj(post, (..., 'video', ..., 'attachments', ..., lambda k, v: ( snippet = traverse_obj(post, (..., 'video', ..., 'attachments', ..., lambda k, v: (
k == 'media' and str(v['id']) == video_id and v['__typename'] == 'Video')), expected_type=dict) or {} k == 'media' and str(v['id']) == video_id and v['__typename'] == 'Video')), expected_type=dict) or {}
locale = self._html_search_meta(['og:locale', 'twitter:locale'], webpage, 'locale', default='en_US') locale = self._html_search_regex((self._meta_regex('og:locale'), self._meta_regex('twitter:locale')), webpage, 'locale', group='content')
captions = get_first(snippet, ('video_available_captions_locales')) or get_first(snippet, ('captions_url')) or None captions = get_first(snippet, ('video_available_captions_locales')) or get_first(snippet, ('captions_url')) or None
automatic_captions = {}
subtitles = {} subtitles = {}
if isinstance(captions, str): if isinstance(captions, str):
subtitles[locale] = [{'ext': self._search_regex(r'\.(\w{3,})\?', captions, 'captions_ext', default='srt'), 'url': captions}] subtitles[locale] = [{'ext': 'srt', 'url': captions}]
elif isinstance(captions, list): elif captions:
if len(captions) > 1:
captions = sorted(captions, key=lambda c: (c['locale'] != locale, c['locale']))
for c in captions: for c in captions:
s = { subtitles[c['locale']] = [{
'ext': self._search_regex(r'\.(\w{3,})\?', c['captions_url'], 'captions_ext', default='srt'), 'ext': 'srt',
'url': c['captions_url'], 'url': c['captions_url'],
'name': (c['localized_language'] 'name': (c['localized_language']
+ (' (' + c['localized_country'] + ')' if c['localized_country'] else '') + (' (' + c['localized_country'] + ')' if c['localized_country'] else '')
+ (' (' + c['localized_creation_method'] + ')' if c['localized_creation_method'] else '')), + (' (' + c['localized_creation_method'] + ')' if c['localized_creation_method'] else '')),
} }]
# observed 'localized_creation_method' value: null, "Auto-generated"(translated into diff lang) lang = list(subtitles.keys())
# if a 3rd method exists, captions created by such method will be categorized into automatic_captions lang.sort()
# TODO: better way to distinguish auto-generated captions from other captions if lang.index(locale):
if c['localized_creation_method']: lang.insert(0, lang.pop(lang.index(locale)))
automatic_captions.setdefault(c['locale'], []).append(s) subtitles = {i: subtitles[i] for i in lang}
else:
subtitles.setdefault(c['locale'], []).append(s)
media = traverse_obj(post, (..., 'attachments', ..., lambda k, v: ( media = traverse_obj(post, (..., 'attachments', ..., lambda k, v: (
k == 'media' and str(v['id']) == video_id and v['__typename'] == 'Video')), expected_type=dict) k == 'media' and str(v['id']) == video_id and v['__typename'] == 'Video')), expected_type=dict)
title = get_first(media, ('title', 'text')) title = get_first(media, ('title', 'text'))
@ -489,7 +484,6 @@ class FacebookIE(InfoExtractor):
webpage, 'view count', default=None)), webpage, 'view count', default=None)),
'concurrent_view_count': get_first(post, ( 'concurrent_view_count': get_first(post, (
('video', (..., ..., 'attachments', ..., 'media')), 'liveViewerCount', {int_or_none})), ('video', (..., ..., 'attachments', ..., 'media')), 'liveViewerCount', {int_or_none})),
'automatic_captions': automatic_captions,
'subtitles': subtitles, 'subtitles': subtitles,
} }