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:'
67 def _parse_video_config(self
, video_config
, display_id
):
68 video_config
= self
._parse
_json
(video_config
, display_id
)
69 item
= video_config
['playlist'][0]
70 mcp_id
= item
.get('mcpID')
72 info
= self
.url_result(f
'{self._ANVATO_PREFIX}{mcp_id}', AnvatoIE
, mcp_id
)
74 media_id
= item
.get('id') or item
['entityId']
75 title
= item
.get('title')
76 item_url
= item
['url']
77 info
= {'id': media_id}
78 ext
= determine_ext(item_url
)
80 info
['formats'] = self
._extract
_m
3u8_formats
(item_url
, media_id
, 'mp4')
82 info
['url'] = item_url
83 if item
.get('audio') is True:
84 info
['vcodec'] = 'none'
85 is_live
= video_config
.get('live') is True
87 image_url
= item
.get(item
.get('imageSrc')) or item
.get(item
.get('posterImage'))
91 'ext': determine_ext(image_url
, 'jpg'),
96 'description': clean_html(item
.get('description')),
97 'thumbnails': thumbnails
,
102 class NFLIE(NFLBaseIE
):
104 _VALID_URL
= NFLBaseIE
._VALID
_URL
_BASE
+ r
'(?:videos?|listen|audio)/(?P<id>[^/#?&]+)'
106 'url': 'https://www.nfl.com/videos/baker-mayfield-s-game-changing-plays-from-3-td-game-week-14',
110 'title': "Baker Mayfield's game-changing plays from 3-TD game Week 14",
111 'description': 'md5:85e05a3cc163f8c344340f220521136d',
112 'upload_date': '20201215',
113 'timestamp': 1608009755,
114 'thumbnail': r
're:^https?://.*\.jpg$',
118 'categories': 'count:3',
121 'url': 'https://www.chiefs.com/listen/patrick-mahomes-travis-kelce-react-to-win-over-dolphins-the-breakdown',
122 'md5': '6886b32c24b463038c760ceb55a34566',
124 'id': 'd87e8790-3e14-11eb-8ceb-ff05c2867f99',
126 'title': 'Patrick Mahomes, Travis Kelce React to Win Over Dolphins | The Breakdown',
127 'description': 'md5:12ada8ee70e6762658c30e223e095075',
129 'skip': 'HTTP Error 404: Not Found',
131 'url': 'https://www.buffalobills.com/video/buffalo-bills-military-recognition-week-14',
132 'only_matching': True,
134 'url': 'https://www.raiders.com/audio/instant-reactions-raiders-week-14-loss-to-indianapolis-colts-espn-jason-fitz',
135 'only_matching': True,
138 def _real_extract(self
, url
):
139 display_id
= self
._match
_id
(url
)
140 webpage
= self
._download
_webpage
(url
, display_id
)
141 return self
._parse
_video
_config
(self
._search
_regex
(
142 self
._VIDEO
_CONFIG
_REGEX
, webpage
, 'video config'), display_id
)
145 class NFLArticleIE(NFLBaseIE
):
146 IE_NAME
= 'nfl.com:article'
147 _VALID_URL
= NFLBaseIE
._VALID
_URL
_BASE
+ r
'news/(?P<id>[^/#?&]+)'
149 'url': 'https://www.buffalobills.com/news/the-only-thing-we-ve-earned-is-the-noise-bills-coaches-discuss-handling-rising-e',
151 'id': 'the-only-thing-we-ve-earned-is-the-noise-bills-coaches-discuss-handling-rising-e',
152 'title': "'The only thing we've earned is the noise' | Bills coaches discuss handling rising expectations",
157 def _real_extract(self
, url
):
158 display_id
= self
._match
_id
(url
)
159 webpage
= self
._download
_webpage
(url
, display_id
)
161 for video_config
in re
.findall(self
._VIDEO
_CONFIG
_REGEX
, webpage
):
162 entries
.append(self
._parse
_video
_config
(video_config
, display_id
))
163 title
= clean_html(get_element_by_class(
164 'nfl-c-article__title', webpage
)) or self
._html
_search
_meta
(
165 ['og:title', 'twitter:title'], webpage
)
166 return self
.playlist_result(entries
, display_id
, title
)
169 class NFLPlusReplayIE(NFLBaseIE
):
170 IE_NAME
= 'nfl.com:plus:replay'
171 _VALID_URL
= r
'https?://(?:www\.)?nfl.com/plus/games/[\w-]+/(?P<id>\d+)'
173 'url': 'https://www.nfl.com/plus/games/giants-at-vikings-2022-post-1/1572108',
177 'title': 'New York Giants at Minnesota Vikings',
178 'description': 'New York Giants play the Minnesota Vikings at U.S. Bank Stadium on January 15, 2023',
180 'upload_date': '20230116',
181 'timestamp': 1673864520,
183 'categories': ['Game Highlights'],
184 'tags': ['Minnesota Vikings', 'New York Giants', 'Minnesota Vikings vs. New York Giants'],
185 'thumbnail': r
're:^https?://.*\.jpg',
187 'params': {'skip_download': 'm3u8'}
,
190 def _real_extract(self
, url
):
191 video_id
= self
._match
_id
(url
)
192 return self
.url_result(f
'{self._ANVATO_PREFIX}{video_id}', AnvatoIE
, video_id
)
195 class NFLPlusEpisodeIE(NFLBaseIE
):
196 IE_NAME
= 'nfl.com:plus:episode'
197 _VALID_URL
= r
'https?://(?:www\.)?nfl.com/plus/episodes/(?P<id>[\w-]+)'
199 'note': 'premium content',
200 'url': 'https://www.nfl.com/plus/episodes/kurt-s-qb-insider-conference-championships',
204 'title': 'Kurt\'s QB Insider: Conference Championships',
205 'description': 'md5:944f7fab56f7a37430bf8473f5473857',
207 'upload_date': '20230127',
208 'timestamp': 1674782760,
210 'categories': ['Analysis'],
211 'tags': ['Cincinnati Bengals at Kansas City Chiefs (2022-POST-3)'],
212 'thumbnail': r
're:^https?://.*\.jpg',
214 'params': {'skip_download': 'm3u8'}
,
218 'clientKey': '4cFUW6DmwJpzT9L7LrG3qRAcABG5s04g',
219 'clientSecret': 'CZuvCL49d9OwfGsR',
220 'deviceId': str(uuid
.uuid4()),
221 'deviceInfo': base64
.b64encode(json
.dumps({
226 }, separators
=(',', ':')).encode()).decode(),
227 'networkType': 'other',
228 'nflClaimGroupsToAdd': [],
229 'nflClaimGroupsToRemove': [],
237 def _get_account_info(self
, url
, video_id
):
238 cookies
= self
._get
_cookies
('https://www.nfl.com/')
239 login_token
= traverse_obj(cookies
, (
240 (f
'glt_{self._API_KEY}', f
'gig_loginToken_{self._API_KEY}',
241 lambda k
, _
: k
.startswith('glt_') or k
.startswith('gig_loginToken_')),
242 {lambda x: x.value}
), get_all
=False)
244 self
.raise_login_required()
246 account
= self
._download
_json
(
247 'https://auth-id.nfl.com/accounts.getAccountInfo', video_id
,
248 note
='Downloading account info', data
=urlencode_postdata({
249 'include': 'profile,data',
251 'APIKey': self
._API
_KEY
,
253 'login_token': login_token
,
254 'authMode': 'cookie',
256 'sdkBuild': traverse_obj(cookies
, (
257 'gig_canary_ver', {lambda x: x.value.partition('-')[0]}
), default
='13642'),
259 }), headers
={'Content-Type': 'application/x-www-form-urlencoded'}
)
261 self
._ACCOUNT
_INFO
= traverse_obj(account
, {
262 'signatureTimestamp': 'signatureTimestamp',
264 'uidSignature': 'UIDSignature',
267 if len(self
._ACCOUNT
_INFO
) != 3:
268 raise ExtractorError('Failed to retrieve account info with provided cookies', expected
=True)
270 def _get_auth_token(self
, url
, video_id
):
271 if not self
._ACCOUNT
_INFO
:
272 self
._get
_account
_info
(url
, video_id
)
274 token
= self
._download
_json
(
275 'https://api.nfl.com/identity/v3/token%s' % (
276 '/refresh' if self
._ACCOUNT
_INFO
.get('refreshToken') else ''),
277 video_id
, headers
={'Content-Type': 'application/json'}
, note
='Downloading access token',
278 data
=json
.dumps({**self._CLIENT_DATA, **self._ACCOUNT_INFO}
, separators
=(',', ':')).encode())
280 self
._TOKEN
= token
['accessToken']
281 self
._TOKEN
_EXPIRY
= token
['expiresIn']
282 self
._ACCOUNT
_INFO
['refreshToken'] = token
['refreshToken']
284 def _real_extract(self
, url
):
285 slug
= self
._match
_id
(url
)
287 if not self
._API
_KEY
:
288 webpage
= self
._download
_webpage
(url
, slug
, fatal
=False) or ''
289 self
._API
_KEY
= self
._search
_regex
(
290 r
'window\.gigyaApiKey=["\'](\w
+)["\'];', webpage, 'API key',
291 default='3_Qa8TkWpIB8ESCBT8tY2TukbVKgO5F6BJVc7N1oComdwFzI7H2L9NOWdm11i_BY9f')
293 if not self._TOKEN or self._TOKEN_EXPIRY <= int(time.time()):
294 self._get_auth_token(url, slug)
296 video_id = self._download_json(
297 f'https://api.nfl.com/content/v1/videos/episodes/{slug}', slug, headers={
298 'Authorization': f'Bearer {self._TOKEN}',
301 return self.url_result(f'{self._ANVATO_PREFIX}{video_id}', AnvatoIE, video_id)