Compare commits

..

No commits in common. "23e2bc581b6f88d9b9490e0e5b30e46c01c29bc4" and "5a63b0ec715a7e6879ebe16bef6bdd0d87d7ec7a" have entirely different histories.

View File

@ -19,7 +19,6 @@ from ..utils import (
get_element_by_id, get_element_by_id,
get_first, get_first,
int_or_none, int_or_none,
join_nonempty,
js_to_json, js_to_json,
merge_dicts, merge_dicts,
parse_count, parse_count,
@ -422,25 +421,29 @@ class FacebookIE(InfoExtractor):
post = traverse_obj(post_data, ( post = traverse_obj(post_data, (
..., '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'))) 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_meta(['og:locale', 'twitter:locale'], webpage, 'locale', default='en_US')
captions = get_first(snippet, 'video_available_captions_locales', 'captions_url') captions = get_first(snippet, 'video_available_captions_locales', 'captions_url')
is_video_broadcast = get_first(snippet, 'is_video_broadcast', expected_type=bool) useIsVideoBroadcast = get_first(snippet, ('is_video_broadcast')) or False
automatic_captions = {} automatic_captions = {}
subtitles = {} subtitles = {}
if url_or_none(captions): # snippet only had 'captions_url' if isinstance(captions, str):
subtitles[locale] = [{'url': captions}] subtitles[locale] = [{'ext': determine_ext(captions, default_ext='srt'), 'url': captions}]
else: elif isinstance(captions, list):
captions = sorted(captions, key=lambda c: c['locale']) if len(captions) > 1:
for caption in traverse_obj(captions, lambda _, v: v['captions_url'] and v['locale']): captions = sorted(captions, key=lambda c: (c['locale'] != locale, c['locale']))
subs = { for c in captions:
'url': caption['captions_url'], s = {
'name': join_nonempty('localized_language', 'localized_country', from_dict=caption), 'ext': determine_ext(c['captions_url'], default_ext='srt'),
'url': c['captions_url'],
'name': (c['localized_language']
+ (' (' + c['localized_country'] + ')' if c['localized_country'] else '')
+ (' (' + c['localized_creation_method'] + ')' if c['localized_creation_method'] else '')),
} }
if caption.get('localized_creation_method') or is_video_broadcast: if c['localized_creation_method'] or useIsVideoBroadcast:
automatic_captions.setdefault(caption['locale'], []).append(subs) automatic_captions.setdefault(c['locale'], []).append(s)
else: else:
subtitles.setdefault(caption['locale'], []).append(subs) 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'))
@ -731,7 +734,6 @@ class FacebookIE(InfoExtractor):
video_data = video_data[0] video_data = video_data[0]
formats = [] formats = []
subtitles = {}
for f in video_data: for f in video_data:
format_id = f['stream_type'] format_id = f['stream_type']
if f and isinstance(f, dict): if f and isinstance(f, dict):
@ -754,14 +756,10 @@ class FacebookIE(InfoExtractor):
'height': 720 if quality == 'hd' else None 'height': 720 if quality == 'hd' else None
}) })
extract_dash_manifest(f[0], formats) extract_dash_manifest(f[0], formats)
subtitles_src = f[0].get('subtitles_src')
if subtitles_src:
subtitles.setdefault('en', []).append({'url': subtitles_src})
info_dict = { info_dict = {
'id': video_id, 'id': video_id,
'formats': formats, 'formats': formats,
'subtitles': subtitles,
} }
process_formats(info_dict) process_formats(info_dict)
info_dict.update(extract_metadata(webpage)) info_dict.update(extract_metadata(webpage))