2 from __future__ import unicode_literals
7 from .adobepass import AdobePassIE
11 compat_urllib_parse_unquote,
23 class FOXIE(AdobePassIE):
24 _VALID_URL = r'https?://(?:www\.)?fox\.com/watch/(?P<id>[\da-fA-F]+)'
27 'url': 'https://www.fox.com/watch/4b765a60490325103ea69888fb2bd4e8/',
28 'md5': 'ebd296fcc41dd4b19f8115d8461a3165',
30 'id': '4b765a60490325103ea69888fb2bd4e8',
32 'title': 'Aftermath: Bruce Wayne Develops Into The Dark Knight',
33 'description': 'md5:549cd9c70d413adb32ce2a779b53b486',
35 'timestamp': 1504291893,
36 'upload_date': '20170901',
42 'skip_download': True,
45 # episode, geo-restricted
46 'url': 'https://www.fox.com/watch/087036ca7f33c8eb79b08152b4dd75c1/',
47 'only_matching': True,
49 # episode, geo-restricted, tv provided required
50 'url': 'https://www.fox.com/watch/30056b295fb57f7452aeeb4920bc3024/',
51 'only_matching': True,
53 _HOME_PAGE_URL = 'https://www.fox.com/'
54 _API_KEY = 'abdcbed02c124d393b39e818a4312055'
57 def _call_api(self, path, video_id, data=None):
59 'X-Api-Key': self._API_KEY,
61 if self._access_token:
62 headers['Authorization'] = 'Bearer ' + self._access_token
63 return self._download_json(
64 'https://api2.fox.com/v2.0/' + path,
65 video_id, data=data, headers=headers)
67 def _real_initialize(self):
68 if not self._access_token:
69 mvpd_auth = self._get_cookies(self._HOME_PAGE_URL).get('mvpd-auth')
71 self._access_token = (self._parse_json(compat_urllib_parse_unquote(
72 mvpd_auth.value), None, fatal=False) or {}).get('accessToken')
73 if not self._access_token:
74 self._access_token = self._call_api(
75 'login', None, json.dumps({
76 'deviceId': compat_str(uuid.uuid4()),
77 }).encode())['accessToken']
79 def _real_extract(self, url):
80 video_id = self._match_id(url)
82 video = self._call_api('vodplayer/' + video_id, video_id)
85 release_url = video['url']
86 m3u8_url = self._download_json(release_url, video_id)['playURL']
87 formats = self._extract_m3u8_formats(
88 m3u8_url, video_id, 'mp4',
89 entry_protocol='m3u8_native', m3u8_id='hls')
90 self._sort_formats(formats)
93 video, lambda x: x['trackingData']['properties'], dict) or {}
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(video.get('contentRating')),
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,