7 from .anvato
import AnvatoIE
8 from .common
import InfoExtractor
19 class NFLBaseIE(InfoExtractor
):
20 _VALID_URL_BASE
= r
'''(?x)
38 (?:titansonline|tennesseetitans)|
46 (?:redskins|washingtonfootball)|
64 _VIDEO_CONFIG_REGEX
= r
'<script[^>]+id="[^"]*video-config-[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}[^"]*"[^>]*>\s*({.+});?\s*</script>'
65 _ANVATO_PREFIX
= 'anvato:GXvEgwyJeWem8KCYXfeoHWknwP48Mboj:'
68 'clientKey': '4cFUW6DmwJpzT9L7LrG3qRAcABG5s04g',
69 'clientSecret': 'CZuvCL49d9OwfGsR',
70 'deviceId': str(uuid
.uuid4()),
71 'deviceInfo': base64
.b64encode(json
.dumps({
76 }, separators
=(',', ':')).encode()).decode(),
77 'networkType': 'other',
78 'nflClaimGroupsToAdd': [],
79 'nflClaimGroupsToRemove': [],
87 def _get_account_info(self
, url
, slug
):
89 webpage
= self
._download
_webpage
(url
, slug
, fatal
=False) or ''
90 self
._API
_KEY
= self
._search
_regex
(
91 r
'window\.gigyaApiKey\s*=\s*["\'](\w
+)["\'];', webpage, 'API key',
92 fatal=False) or '3_Qa8TkWpIB8ESCBT8tY2TukbVKgO5F6BJVc7N1oComdwFzI7H2L9NOWdm11i_BY9f'
94 cookies = self._get_cookies('https://auth-id.nfl.com/')
95 login_token = traverse_obj(cookies, (
96 (f'glt_{self._API_KEY}', lambda k, _: k.startswith('glt_')), {lambda x: x.value}), get_all=False)
98 self.raise_login_required()
99 if 'ucid' not in cookies:
100 raise ExtractorError(
101 'Required cookies for the auth-id.nfl.com domain were not found among passed cookies. '
102 'If using --cookies, these cookies must be exported along with .nfl.com cookies, '
103 'or else try using --cookies-from-browser instead', expected=True)
105 account = self._download_json(
106 'https://auth-id.nfl.com/accounts.getAccountInfo', slug,
107 note='Downloading account info', data=urlencode_postdata({
108 'include': 'profile,data',
110 'APIKey': self._API_KEY,
112 'login_token': login_token,
113 'authMode': 'cookie',
115 'sdkBuild': traverse_obj(cookies, (
116 'gig_canary_ver', {lambda x: x.value.partition('-')[0]}), default='15170'),
118 }), headers={'Content-Type': 'application/x-www-form-urlencoded'})
120 self._ACCOUNT_INFO = traverse_obj(account, {
121 'signatureTimestamp': 'signatureTimestamp',
123 'uidSignature': 'UIDSignature',
126 if len(self._ACCOUNT_INFO) != 3:
127 raise ExtractorError('Failed to retrieve account info with provided cookies', expected=True)
129 def _get_auth_token(self, url, slug):
130 if self._TOKEN and self._TOKEN_EXPIRY > int(time.time() + 30):
133 if not self._ACCOUNT_INFO:
134 self._get_account_info(url, slug)
136 token = self._download_json(
137 'https://api.nfl.com/identity/v3/token%s' % (
138 '/refresh' if self._ACCOUNT_INFO.get('refreshToken') else ''),
139 slug, headers={'Content-Type': 'application/json'}, note='Downloading access token',
140 data=json.dumps({**self._CLIENT_DATA, **self._ACCOUNT_INFO}, separators=(',', ':')).encode())
142 self._TOKEN = token['accessToken']
143 self._TOKEN_EXPIRY = token['expiresIn']
144 self._ACCOUNT_INFO['refreshToken'] = token['refreshToken']
146 def _parse_video_config(self, video_config, display_id):
147 video_config = self._parse_json(video_config, display_id)
148 item = video_config['playlist'][0]
149 mcp_id = item.get('mcpID')
151 info = self.url_result(f'{self._ANVATO_PREFIX}{mcp_id}', AnvatoIE, mcp_id)
153 media_id = item.get('id') or item['entityId']
154 title = item.get('title')
155 item_url = item['url']
156 info = {'id': media_id}
157 ext = determine_ext(item_url)
159 info['formats'] = self._extract_m3u8_formats(item_url, media_id, 'mp4')
161 info['url'] = item_url
162 if item.get('audio') is True:
163 info['vcodec'] = 'none'
164 is_live = video_config.get('live') is True
166 image_url = item.get(item.get('imageSrc')) or item.get(item.get('posterImage'))
170 'ext': determine_ext(image_url, 'jpg'),
175 'description': clean_html(item.get('description')),
176 'thumbnails': thumbnails,
181 class NFLIE(NFLBaseIE):
183 _VALID_URL = NFLBaseIE._VALID_URL_BASE + r'(?:videos?|listen|audio)/(?P<id>[^/#?&]+)'
185 'url': 'https://www.nfl.com/videos/baker-mayfield-s-game-changing-plays-from-3-td-game-week-14',
189 'title': "Baker Mayfield
's game-changing plays from 3-TD game Week 14",
190 'description
': 'md5
:85e05a3cc163f8c344340f220521136d
',
191 'upload_date
': '20201215',
192 'timestamp
': 1608009755,
193 'thumbnail
': r're
:^https?
://.*\
.jpg$
',
197 'categories
': 'count
:3',
200 'url
': 'https
://www
.chiefs
.com
/listen
/patrick
-mahomes
-travis
-kelce
-react
-to
-win
-over
-dolphins
-the
-breakdown
',
201 'md5
': '6886b32c24b463038c760ceb55a34566
',
203 'id': 'd87e8790
-3e14
-11eb
-8ceb
-ff05c2867f99
',
205 'title
': 'Patrick Mahomes
, Travis Kelce React to Win Over Dolphins | The Breakdown
',
206 'description
': 'md5
:12ada8ee70e6762658c30e223e095075
',
208 'skip
': 'HTTP Error
404: Not Found
',
210 'url
': 'https
://www
.buffalobills
.com
/video
/buffalo
-bills
-military
-recognition
-week
-14',
211 'only_matching
': True,
213 'url
': 'https
://www
.raiders
.com
/audio
/instant
-reactions
-raiders
-week
-14-loss
-to
-indianapolis
-colts
-espn
-jason
-fitz
',
214 'only_matching
': True,
217 def _real_extract(self, url):
218 display_id = self._match_id(url)
219 webpage = self._download_webpage(url, display_id)
220 return self._parse_video_config(self._search_regex(
221 self._VIDEO_CONFIG_REGEX, webpage, 'video config
'), display_id)
224 class NFLArticleIE(NFLBaseIE):
225 IE_NAME = 'nfl
.com
:article
'
226 _VALID_URL = NFLBaseIE._VALID_URL_BASE + r'news
/(?P
<id>[^
/#?&]+)'
228 'url': 'https://www.buffalobills.com/news/the-only-thing-we-ve-earned-is-the-noise-bills-coaches-discuss-handling-rising-e',
230 'id': 'the-only-thing-we-ve-earned-is-the-noise-bills-coaches-discuss-handling-rising-e',
231 'title': "'The only thing we've earned is the noise' | Bills coaches discuss handling rising expectations",
236 def _real_extract(self
, url
):
237 display_id
= self
._match
_id
(url
)
238 webpage
= self
._download
_webpage
(url
, display_id
)
240 for video_config
in re
.findall(self
._VIDEO
_CONFIG
_REGEX
, webpage
):
241 entries
.append(self
._parse
_video
_config
(video_config
, display_id
))
242 title
= clean_html(get_element_by_class(
243 'nfl-c-article__title', webpage
)) or self
._html
_search
_meta
(
244 ['og:title', 'twitter:title'], webpage
)
245 return self
.playlist_result(entries
, display_id
, title
)
248 class NFLPlusReplayIE(NFLBaseIE
):
249 IE_NAME
= 'nfl.com:plus:replay'
250 _VALID_URL
= r
'https?://(?:www\.)?nfl\.com/plus/games/(?P<slug>[\w-]+)(?:/(?P<id>\d+))?'
252 'url': 'https://www.nfl.com/plus/games/giants-at-vikings-2022-post-1/1572108',
256 'title': 'New York Giants at Minnesota Vikings',
257 'description': 'New York Giants play the Minnesota Vikings at U.S. Bank Stadium on January 15, 2023',
259 'upload_date': '20230116',
260 'timestamp': 1673864520,
262 'categories': ['Game Highlights'],
263 'tags': ['Minnesota Vikings', 'New York Giants', 'Minnesota Vikings vs. New York Giants'],
264 'thumbnail': r
're:^https?://.*\.jpg',
266 'params': {'skip_download': 'm3u8'},
268 'note': 'Subscription required',
269 'url': 'https://www.nfl.com/plus/games/giants-at-vikings-2022-post-1',
272 'id': 'giants-at-vikings-2022-post-1',
275 'note': 'Subscription required',
276 'url': 'https://www.nfl.com/plus/games/giants-at-patriots-2011-pre-4',
279 'id': 'giants-at-patriots-2011-pre-4',
282 'note': 'Subscription required',
283 'url': 'https://www.nfl.com/plus/games/giants-at-patriots-2011-pre-4',
287 'title': 'Giants @ Patriots',
288 'description': 'Giants at Patriots on September 01, 2011',
290 'upload_date': '20210724',
291 'timestamp': 1627085874,
293 'categories': ['Game Highlights'],
294 'tags': ['play-by-play'],
295 'thumbnail': r
're:^https?://.*\.jpg',
298 'skip_download': 'm3u8',
299 'extractor_args': {'nflplusreplay': {'type': ['condensed_game']}},
304 'full_game': 'Full Game',
305 'full_game_spanish': 'Full Game - Spanish',
306 'condensed_game': 'Condensed Game',
310 def _real_extract(self
, url
):
311 slug
, video_id
= self
._match
_valid
_url
(url
).group('slug', 'id')
312 requested_types
= self
._configuration
_arg
('type', ['all'])
313 if 'all' in requested_types
:
314 requested_types
= list(self
._REPLAY
_TYPES
.keys())
315 requested_types
= traverse_obj(self
._REPLAY
_TYPES
, (None, requested_types
))
318 self
._get
_auth
_token
(url
, slug
)
319 headers
= {'Authorization': f
'Bearer {self._TOKEN}'}
320 game_id
= self
._download
_json
(
321 f
'https://api.nfl.com/football/v2/games/externalId/slug/{slug}', slug
,
322 'Downloading game ID', query
={'withExternalIds': 'true'}, headers
=headers
)['id']
323 replays
= self
._download
_json
(
324 'https://api.nfl.com/content/v1/videos/replays', slug
, 'Downloading replays JSON',
325 query
={'gameId': game_id
}, headers
=headers
)
326 if len(requested_types
) == 1:
327 video_id
= traverse_obj(replays
, (
328 'items', lambda _
, v
: v
['subType'] == requested_types
[0], 'mcpPlaybackId'), get_all
=False)
331 return self
.url_result(f
'{self._ANVATO_PREFIX}{video_id}', AnvatoIE
, video_id
)
334 for replay
in traverse_obj(
335 replays
, ('items', lambda _
, v
: v
['mcpPlaybackId'] and v
['subType'] in requested_types
)
337 video_id
= replay
['mcpPlaybackId']
338 yield self
.url_result(f
'{self._ANVATO_PREFIX}{video_id}', AnvatoIE
, video_id
)
340 return self
.playlist_result(entries(), slug
)
343 class NFLPlusEpisodeIE(NFLBaseIE
):
344 IE_NAME
= 'nfl.com:plus:episode'
345 _VALID_URL
= r
'https?://(?:www\.)?nfl\.com/plus/episodes/(?P<id>[\w-]+)'
347 'note': 'Subscription required',
348 'url': 'https://www.nfl.com/plus/episodes/kurt-s-qb-insider-conference-championships',
352 'title': 'Conference Championships',
353 'description': 'md5:944f7fab56f7a37430bf8473f5473857',
355 'upload_date': '20230127',
356 'timestamp': 1674782760,
358 'categories': ['Analysis'],
359 'tags': ['Cincinnati Bengals at Kansas City Chiefs (2022-POST-3)'],
360 'thumbnail': r
're:^https?://.*\.jpg',
362 'params': {'skip_download': 'm3u8'},
365 def _real_extract(self
, url
):
366 slug
= self
._match
_id
(url
)
367 self
._get
_auth
_token
(url
, slug
)
368 video_id
= self
._download
_json
(
369 f
'https://api.nfl.com/content/v1/videos/episodes/{slug}', slug
, headers
={
370 'Authorization': f
'Bearer {self._TOKEN}',
373 return self
.url_result(f
'{self._ANVATO_PREFIX}{video_id}', AnvatoIE
, video_id
)