4 from .common
import InfoExtractor
8 compat_urllib_parse_unquote
,
22 class FOXIE(InfoExtractor
):
23 _VALID_URL
= r
'https?://(?:www\.)?fox\.com/watch/(?P<id>[\da-fA-F]+)'
26 'url': 'https://www.fox.com/watch/4b765a60490325103ea69888fb2bd4e8/',
27 'md5': 'ebd296fcc41dd4b19f8115d8461a3165',
29 'id': '4b765a60490325103ea69888fb2bd4e8',
31 'title': 'Aftermath: Bruce Wayne Develops Into The Dark Knight',
32 'description': 'md5:549cd9c70d413adb32ce2a779b53b486',
34 'timestamp': 1504291893,
35 'upload_date': '20170901',
39 'episode': 'Aftermath: Bruce Wayne Develops Into The Dark Knight',
40 'thumbnail': r
're:^https?://.*\.jpg$',
43 'skip_download': True,
46 # episode, geo-restricted
47 'url': 'https://www.fox.com/watch/087036ca7f33c8eb79b08152b4dd75c1/',
48 'only_matching': True,
50 # sports event, geo-restricted
51 'url': 'https://www.fox.com/watch/b057484dade738d1f373b3e46216fa2c/',
52 'only_matching': True,
55 _HOME_PAGE_URL
= 'https://www.fox.com/'
56 _API_KEY
= '6E9S4bmcoNnZwVLOHywOv8PJEdu76cM9'
58 _device_id
= compat_str(uuid
.uuid4())
60 def _call_api(self
, path
, video_id
, data
=None):
62 'X-Api-Key': self
._API
_KEY
,
64 if self
._access
_token
:
65 headers
['Authorization'] = 'Bearer ' + self
._access
_token
67 return self
._download
_json
(
68 'https://api3.fox.com/v2.0/' + path
,
69 video_id
, data
=data
, headers
=headers
)
70 except ExtractorError
as e
:
71 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
72 entitlement_issues
= self
._parse
_json
(
73 e
.cause
.read().decode(), video_id
)['entitlementIssues']
74 for e
in entitlement_issues
:
75 if e
.get('errorCode') == 1005:
77 'This video is only available via cable service provider '
78 'subscription. You may want to use --cookies.', expected
=True)
79 messages
= ', '.join([e
['message'] for e
in entitlement_issues
])
80 raise ExtractorError(messages
, expected
=True)
83 def _real_initialize(self
):
84 if not self
._access
_token
:
85 mvpd_auth
= self
._get
_cookies
(self
._HOME
_PAGE
_URL
).get('mvpd-auth')
87 self
._access
_token
= (self
._parse
_json
(compat_urllib_parse_unquote(
88 mvpd_auth
.value
), None, fatal
=False) or {}).get('accessToken')
89 if not self
._access
_token
:
90 self
._access
_token
= self
._call
_api
(
91 'login', None, json
.dumps({
92 'deviceId': self
._device
_id
,
93 }).encode())['accessToken']
95 def _real_extract(self
, url
):
96 video_id
= self
._match
_id
(url
)
98 self
._access
_token
= self
._call
_api
(
99 'previewpassmvpd?device_id=%s&mvpd_id=TempPass_fbcfox_60min' % self
._device
_id
,
100 video_id
)['accessToken']
102 video
= self
._call
_api
('watch', video_id
, data
=json
.dumps({
103 'capabilities': ['drm/widevine', 'fsdk/yo'],
110 'freewheel': {'did': self._device_id}
,
111 'vdms': {'rays': ''}
,
112 'dmp': {'kuid': '', 'seg': ''}
115 'privacy': {'us': '1---'}
,
118 'streamId': video_id
}).encode('utf-8'))
120 title
= video
['name']
121 release_url
= video
['url']
124 m3u8_url
= self
._download
_json
(release_url
, video_id
)['playURL']
125 except ExtractorError
as e
:
126 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
127 error
= self
._parse
_json
(e
.cause
.read().decode(), video_id
)
128 if error
.get('exception') == 'GeoLocationBlocked':
129 self
.raise_geo_restricted(countries
=['US'])
130 raise ExtractorError(error
['description'], expected
=True)
132 formats
= self
._extract
_m
3u8_formats
(
133 m3u8_url
, video_id
, 'mp4',
134 entry_protocol
='m3u8_native', m3u8_id
='hls')
137 video
, lambda x
: x
['trackingData']['properties'], dict) or {}
139 duration
= int_or_none(video
.get('durationInSeconds')) or int_or_none(
140 video
.get('duration')) or parse_duration(video
.get('duration'))
141 timestamp
= unified_timestamp(video
.get('datePublished'))
142 creator
= data
.get('brand') or data
.get('network') or video
.get('network')
143 series
= video
.get('seriesName') or data
.get(
144 'seriesName') or data
.get('show')
147 for doc_rel
in video
.get('documentReleases', []):
148 rel_url
= doc_rel
.get('url')
149 if not url
or doc_rel
.get('format') != 'SCC':
161 'description': video
.get('description'),
162 'duration': duration
,
163 'timestamp': timestamp
,
164 'age_limit': parse_age_limit(video
.get('contentRating')),
167 'season_number': int_or_none(video
.get('seasonNumber')),
168 'episode': video
.get('name'),
169 'episode_number': int_or_none(video
.get('episodeNumber')),
170 'thumbnail': traverse_obj(video
, ('images', 'still', 'raw'), expected_type
=url_or_none
),
171 'release_year': int_or_none(video
.get('releaseYear')),
172 'subtitles': subtitles
,