4 from .common
import InfoExtractor
7 compat_urllib_parse_unquote
,
9 from ..networking
.exceptions
import HTTPError
22 class FOXIE(InfoExtractor
):
23 _VALID_URL
= r
'https?://(?:www\.)?fox(?:sports)?\.com/(?:watch|replay)/(?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,
54 # fox sports replay, geo-restricted
55 'url': 'https://www.foxsports.com/replay/561f3e071347a24e5e877abc56b22e89',
56 'only_matching': True,
59 _HOME_PAGE_URL
= 'https://www.fox.com/'
60 _API_KEY
= '6E9S4bmcoNnZwVLOHywOv8PJEdu76cM9'
62 _device_id
= compat_str(uuid
.uuid4())
64 def _call_api(self
, path
, video_id
, data
=None):
66 'X-Api-Key': self
._API
_KEY
,
68 if self
._access
_token
:
69 headers
['Authorization'] = 'Bearer ' + self
._access
_token
71 return self
._download
_json
(
72 'https://api3.fox.com/v2.0/' + path
,
73 video_id
, data
=data
, headers
=headers
)
74 except ExtractorError
as e
:
75 if isinstance(e
.cause
, HTTPError
) and e
.cause
.status
== 403:
76 entitlement_issues
= self
._parse
_json
(
77 e
.cause
.response
.read().decode(), video_id
)['entitlementIssues']
78 for e
in entitlement_issues
:
79 if e
.get('errorCode') == 1005:
81 'This video is only available via cable service provider '
82 'subscription. You may want to use --cookies.', expected
=True)
83 messages
= ', '.join([e
['message'] for e
in entitlement_issues
])
84 raise ExtractorError(messages
, expected
=True)
87 def _real_initialize(self
):
88 if not self
._access
_token
:
89 mvpd_auth
= self
._get
_cookies
(self
._HOME
_PAGE
_URL
).get('mvpd-auth')
91 self
._access
_token
= (self
._parse
_json
(compat_urllib_parse_unquote(
92 mvpd_auth
.value
), None, fatal
=False) or {}).get('accessToken')
93 if not self
._access
_token
:
94 self
._access
_token
= self
._call
_api
(
95 'login', None, json
.dumps({
96 'deviceId': self
._device
_id
,
97 }).encode())['accessToken']
99 def _real_extract(self
, url
):
100 video_id
= self
._match
_id
(url
)
102 self
._access
_token
= self
._call
_api
(
103 'previewpassmvpd?device_id=%s&mvpd_id=TempPass_fbcfox_60min' % self
._device
_id
,
104 video_id
)['accessToken']
106 video
= self
._call
_api
('watch', video_id
, data
=json
.dumps({
107 'capabilities': ['drm/widevine', 'fsdk/yo'],
114 'freewheel': {'did': self._device_id}
,
115 'vdms': {'rays': ''}
,
116 'dmp': {'kuid': '', 'seg': ''}
119 'privacy': {'us': '1---'}
,
122 'streamId': video_id
}).encode('utf-8'))
124 title
= video
['name']
125 release_url
= video
['url']
128 m3u8_url
= self
._download
_json
(release_url
, video_id
)['playURL']
129 except ExtractorError
as e
:
130 if isinstance(e
.cause
, HTTPError
) and e
.cause
.status
== 403:
131 error
= self
._parse
_json
(e
.cause
.response
.read().decode(), video_id
)
132 if error
.get('exception') == 'GeoLocationBlocked':
133 self
.raise_geo_restricted(countries
=['US'])
134 raise ExtractorError(error
['description'], expected
=True)
136 formats
= self
._extract
_m
3u8_formats
(
137 m3u8_url
, video_id
, 'mp4',
138 entry_protocol
='m3u8_native', m3u8_id
='hls')
141 video
, lambda x
: x
['trackingData']['properties'], dict) or {}
143 duration
= int_or_none(video
.get('durationInSeconds')) or int_or_none(
144 video
.get('duration')) or parse_duration(video
.get('duration'))
145 timestamp
= unified_timestamp(video
.get('datePublished'))
146 creator
= data
.get('brand') or data
.get('network') or video
.get('network')
147 series
= video
.get('seriesName') or data
.get(
148 'seriesName') or data
.get('show')
151 for doc_rel
in video
.get('documentReleases', []):
152 rel_url
= doc_rel
.get('url')
153 if not url
or doc_rel
.get('format') != 'SCC':
165 'description': video
.get('description'),
166 'duration': duration
,
167 'timestamp': timestamp
,
168 'age_limit': parse_age_limit(video
.get('contentRating')),
171 'season_number': int_or_none(video
.get('seasonNumber')),
172 'episode': video
.get('name'),
173 'episode_number': int_or_none(video
.get('episodeNumber')),
174 'thumbnail': traverse_obj(video
, ('images', 'still', 'raw'), expected_type
=url_or_none
),
175 'release_year': int_or_none(video
.get('releaseYear')),
176 'subtitles': subtitles
,