4 from .common
import InfoExtractor
8 compat_urllib_parse_unquote
,
20 class FOXIE(InfoExtractor
):
21 _VALID_URL
= r
'https?://(?:www\.)?fox\.com/watch/(?P<id>[\da-fA-F]+)'
24 'url': 'https://www.fox.com/watch/4b765a60490325103ea69888fb2bd4e8/',
25 'md5': 'ebd296fcc41dd4b19f8115d8461a3165',
27 'id': '4b765a60490325103ea69888fb2bd4e8',
29 'title': 'Aftermath: Bruce Wayne Develops Into The Dark Knight',
30 'description': 'md5:549cd9c70d413adb32ce2a779b53b486',
32 'timestamp': 1504291893,
33 'upload_date': '20170901',
37 'episode': 'Aftermath: Bruce Wayne Develops Into The Dark Knight'
40 'skip_download': True,
43 # episode, geo-restricted
44 'url': 'https://www.fox.com/watch/087036ca7f33c8eb79b08152b4dd75c1/',
45 'only_matching': True,
47 # sports event, geo-restricted
48 'url': 'https://www.fox.com/watch/b057484dade738d1f373b3e46216fa2c/',
49 'only_matching': True,
52 _HOME_PAGE_URL
= 'https://www.fox.com/'
53 _API_KEY
= '6E9S4bmcoNnZwVLOHywOv8PJEdu76cM9'
55 _device_id
= compat_str(uuid
.uuid4())
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
64 return self
._download
_json
(
65 'https://api3.fox.com/v2.0/' + path
,
66 video_id
, data
=data
, headers
=headers
)
67 except ExtractorError
as e
:
68 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
69 entitlement_issues
= self
._parse
_json
(
70 e
.cause
.read().decode(), video_id
)['entitlementIssues']
71 for e
in entitlement_issues
:
72 if e
.get('errorCode') == 1005:
74 'This video is only available via cable service provider '
75 'subscription. You may want to use --cookies.', expected
=True)
76 messages
= ', '.join([e
['message'] for e
in entitlement_issues
])
77 raise ExtractorError(messages
, expected
=True)
80 def _real_initialize(self
):
81 if not self
._access
_token
:
82 mvpd_auth
= self
._get
_cookies
(self
._HOME
_PAGE
_URL
).get('mvpd-auth')
84 self
._access
_token
= (self
._parse
_json
(compat_urllib_parse_unquote(
85 mvpd_auth
.value
), None, fatal
=False) or {}).get('accessToken')
86 if not self
._access
_token
:
87 self
._access
_token
= self
._call
_api
(
88 'login', None, json
.dumps({
89 'deviceId': self
._device
_id
,
90 }).encode())['accessToken']
92 def _real_extract(self
, url
):
93 video_id
= self
._match
_id
(url
)
95 self
._access
_token
= self
._call
_api
(
96 'previewpassmvpd?device_id=%s&mvpd_id=TempPass_fbcfox_60min' % self
._device
_id
,
97 video_id
)['accessToken']
99 video
= self
._call
_api
('watch', video_id
, data
=json
.dumps({
100 'capabilities': ['drm/widevine', 'fsdk/yo'],
107 'freewheel': {'did': self._device_id}
,
108 'vdms': {'rays': ''}
,
109 'dmp': {'kuid': '', 'seg': ''}
112 'privacy': {'us': '1---'}
,
115 'streamId': video_id
}).encode('utf-8'))
117 title
= video
['name']
118 release_url
= video
['url']
121 m3u8_url
= self
._download
_json
(release_url
, video_id
)['playURL']
122 except ExtractorError
as e
:
123 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
124 error
= self
._parse
_json
(e
.cause
.read().decode(), video_id
)
125 if error
.get('exception') == 'GeoLocationBlocked':
126 self
.raise_geo_restricted(countries
=['US'])
127 raise ExtractorError(error
['description'], expected
=True)
129 formats
= self
._extract
_m
3u8_formats
(
130 m3u8_url
, video_id
, 'mp4',
131 entry_protocol
='m3u8_native', m3u8_id
='hls')
132 self
._sort
_formats
(formats
)
135 video
, lambda x
: x
['trackingData']['properties'], dict) or {}
137 duration
= int_or_none(video
.get('durationInSeconds')) or int_or_none(
138 video
.get('duration')) or parse_duration(video
.get('duration'))
139 timestamp
= unified_timestamp(video
.get('datePublished'))
140 creator
= data
.get('brand') or data
.get('network') or video
.get('network')
141 series
= video
.get('seriesName') or data
.get(
142 'seriesName') or data
.get('show')
145 for doc_rel
in video
.get('documentReleases', []):
146 rel_url
= doc_rel
.get('url')
147 if not url
or doc_rel
.get('format') != 'SCC':
159 'description': video
.get('description'),
160 'duration': duration
,
161 'timestamp': timestamp
,
162 'age_limit': parse_age_limit(video
.get('contentRating')),
165 'season_number': int_or_none(video
.get('seasonNumber')),
166 'episode': video
.get('name'),
167 'episode_number': int_or_none(video
.get('episodeNumber')),
168 'release_year': int_or_none(video
.get('releaseYear')),
169 'subtitles': subtitles
,