2 from __future__ import unicode_literals
7 from .adobepass import AdobePassIE
10 compat_urllib_parse_unquote,
21 class FOXIE(AdobePassIE):
22 _VALID_URL = r'https?://(?:www\.)?fox\.com/watch/(?P<id>[\da-fA-F]+)'
25 'url': 'https://www.fox.com/watch/4b765a60490325103ea69888fb2bd4e8/',
26 'md5': 'ebd296fcc41dd4b19f8115d8461a3165',
28 'id': '4b765a60490325103ea69888fb2bd4e8',
30 'title': 'Aftermath: Bruce Wayne Develops Into The Dark Knight',
31 'description': 'md5:549cd9c70d413adb32ce2a779b53b486',
33 'timestamp': 1504291893,
34 'upload_date': '20170901',
40 'skip_download': True,
43 # episode, geo-restricted
44 'url': 'https://www.fox.com/watch/087036ca7f33c8eb79b08152b4dd75c1/',
45 'only_matching': True,
47 # episode, geo-restricted, tv provided required
48 'url': 'https://www.fox.com/watch/30056b295fb57f7452aeeb4920bc3024/',
49 'only_matching': True,
51 _HOME_PAGE_URL = 'https://www.fox.com/'
52 _API_KEY = 'abdcbed02c124d393b39e818a4312055'
55 def _call_api(self, path, video_id, data=None):
57 'X-Api-Key': self._API_KEY,
59 if self._access_token:
60 headers['Authorization'] = 'Bearer ' + self._access_token
61 return self._download_json(
62 'https://api2.fox.com/v2.0/' + path,
63 video_id, data=data, headers=headers)
65 def _real_initialize(self):
66 if not self._access_token:
67 mvpd_auth = self._get_cookies(self._HOME_PAGE_URL).get('mvpd-auth')
69 self._access_token = (self._parse_json(compat_urllib_parse_unquote(
70 mvpd_auth.value), None, fatal=False) or {}).get('accessToken')
71 if not self._access_token:
72 self._access_token = self._call_api(
73 'login', None, json.dumps({
74 'deviceId': compat_str(uuid.uuid4()),
75 }).encode())['accessToken']
77 def _real_extract(self, url):
78 video_id = self._match_id(url)
80 video = self._call_api('vodplayer/' + video_id, video_id)
83 release_url = video['url']
84 m3u8_url = self._download_json(release_url, video_id)['playURL']
85 formats = self._extract_m3u8_formats(
86 m3u8_url, video_id, 'mp4',
87 entry_protocol='m3u8_native', m3u8_id='hls')
88 self._sort_formats(formats)
91 video, lambda x: x['trackingData']['properties'], dict) or {}
93 duration = int_or_none(video.get('durationInSeconds')) or int_or_none(
94 video.get('duration')) or parse_duration(video.get('duration'))
95 timestamp = unified_timestamp(video.get('datePublished'))
96 creator = data.get('brand') or data.get('network') or video.get('network')
97 series = video.get('seriesName') or data.get(
98 'seriesName') or data.get('show')
101 for doc_rel in video.get('documentReleases', []):
102 rel_url = doc_rel.get('url')
103 if not url or doc_rel.get('format') != 'SCC':
115 'description': video.get('description'),
116 'duration': duration,
117 'timestamp': timestamp,
118 'age_limit': parse_age_limit(video.get('contentRating')),
121 'season_number': int_or_none(video.get('seasonNumber')),
122 'episode': video.get('name'),
123 'episode_number': int_or_none(video.get('episodeNumber')),
124 'release_year': int_or_none(video.get('releaseYear')),
125 'subtitles': subtitles,