2 from __future__ import unicode_literals
7 from .adobepass import AdobePassIE
8 from ..compat import compat_str
19 class FOXIE(AdobePassIE):
20 _VALID_URL = r'https?://(?:www\.)?(?:fox\.com|nationalgeographic\.com/tv)/watch/(?P<id>[\da-fA-F]+)'
23 'url': 'https://www.fox.com/watch/4b765a60490325103ea69888fb2bd4e8/',
24 'md5': 'ebd296fcc41dd4b19f8115d8461a3165',
26 'id': '4b765a60490325103ea69888fb2bd4e8',
28 'title': 'Aftermath: Bruce Wayne Develops Into The Dark Knight',
29 'description': 'md5:549cd9c70d413adb32ce2a779b53b486',
31 'timestamp': 1504291893,
32 'upload_date': '20170901',
37 'skip_download': True,
40 # episode, geo-restricted
41 'url': 'https://www.fox.com/watch/087036ca7f33c8eb79b08152b4dd75c1/',
42 'only_matching': True,
44 # episode, geo-restricted, tv provided required
45 'url': 'https://www.fox.com/watch/30056b295fb57f7452aeeb4920bc3024/',
46 'only_matching': True,
48 'url': 'https://www.nationalgeographic.com/tv/watch/f690e05ebbe23ab79747becd0cc223d1/',
49 'only_matching': True,
53 def _call_api(self, path, video_id, data=None):
55 'X-Api-Key': '238bb0a0c2aba67922c48709ce0c06fd',
57 if self._access_token:
58 headers['Authorization'] = 'Bearer ' + self._access_token
59 return self._download_json(
60 'https://api2.fox.com/v2.0/' + path,
61 video_id, data=data, headers=headers)
63 def _real_initialize(self):
64 self._access_token = self._call_api(
65 'login', None, json.dumps({
66 'deviceId': compat_str(uuid.uuid4()),
67 }).encode())['accessToken']
69 def _real_extract(self, url):
70 video_id = self._match_id(url)
72 video = self._call_api('vodplayer/' + video_id, video_id)
75 release_url = video['url']
78 video, lambda x: x['trackingData']['properties'], dict) or {}
80 rating = video.get('contentRating')
81 if data.get('authRequired'):
82 resource = self._get_mvpd_resource(
83 'fbc-fox', title, video.get('guid'), rating)
84 release_url = update_url_query(
86 'auth': self._extract_mvpd_auth(
87 url, video_id, 'fbc-fox', resource)
89 m3u8_url = self._download_json(release_url, video_id)['playURL']
90 formats = self._extract_m3u8_formats(
91 m3u8_url, video_id, 'mp4',
92 entry_protocol='m3u8_native', m3u8_id='hls')
93 self._sort_formats(formats)
95 duration = int_or_none(video.get('durationInSeconds')) or int_or_none(
96 video.get('duration')) or parse_duration(video.get('duration'))
97 timestamp = unified_timestamp(video.get('datePublished'))
98 creator = data.get('brand') or data.get('network') or video.get('network')
99 series = video.get('seriesName') or data.get(
100 'seriesName') or data.get('show')
103 for doc_rel in video.get('documentReleases', []):
104 rel_url = doc_rel.get('url')
105 if not url or doc_rel.get('format') != 'SCC':
117 'description': video.get('description'),
118 'duration': duration,
119 'timestamp': timestamp,
120 'age_limit': parse_age_limit(rating),
123 'season_number': int_or_none(video.get('seasonNumber')),
124 'episode': video.get('name'),
125 'episode_number': int_or_none(video.get('episodeNumber')),
126 'release_year': int_or_none(video.get('releaseYear')),
127 'subtitles': subtitles,