From baba0a95edb19f02de2de2cd2b8a3abd82af5abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Mon, 17 Mar 2025 00:01:48 +0100 Subject: [PATCH] use `jwt_is_expired` in `NFL` extractor --- yt_dlp/extractor/nfl.py | 6 ++---- yt_dlp/utils/_utils.py | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/yt_dlp/extractor/nfl.py b/yt_dlp/extractor/nfl.py index 59213a44b..29f5bd371 100644 --- a/yt_dlp/extractor/nfl.py +++ b/yt_dlp/extractor/nfl.py @@ -1,7 +1,6 @@ import base64 import json import re -import time import uuid from .anvato import AnvatoIE @@ -12,6 +11,7 @@ determine_ext, get_element_by_class, int_or_none, + jwt_is_expired, make_archive_id, url_or_none, urlencode_postdata, @@ -84,7 +84,6 @@ class NFLBaseIE(InfoExtractor): _API_KEY = '3_Qa8TkWpIB8ESCBT8tY2TukbVKgO5F6BJVc7N1oComdwFzI7H2L9NOWdm11i_BY9f' _TOKEN = None - _TOKEN_EXPIRY = 0 def _get_account_info(self): cookies = self._get_cookies('https://auth-id.nfl.com/') @@ -123,7 +122,7 @@ def _get_account_info(self): raise ExtractorError('Failed to retrieve account info with provided cookies', expected=True) def _get_auth_token(self): - if self._TOKEN and self._TOKEN_EXPIRY > int(time.time() + 30): + if self._TOKEN and jwt_is_expired(self._TOKEN, 30, 'expiresIn'): return token = self._download_json( @@ -133,7 +132,6 @@ def _get_auth_token(self): data=json.dumps({**self._CLIENT_DATA, **self._ACCOUNT_INFO}, separators=(',', ':')).encode()) self._TOKEN = token['accessToken'] - self._TOKEN_EXPIRY = token['expiresIn'] self._ACCOUNT_INFO['refreshToken'] = token['refreshToken'] def _extract_video(self, mcp_id, is_live=False): diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py index 2a5766d8a..bc03389e0 100644 --- a/yt_dlp/utils/_utils.py +++ b/yt_dlp/utils/_utils.py @@ -4763,8 +4763,8 @@ def jwt_decode_hs256(jwt): return json.loads(base64.urlsafe_b64decode(f'{payload_b64}===')) -def jwt_is_expired(token, buffer=300): - return jwt_decode_hs256(token)['exp'] - time.time() < buffer +def jwt_is_expired(token, buffer=300, key='exp'): + return jwt_decode_hs256(token)[key] - time.time() < buffer WINDOWS_VT_MODE = False if os.name == 'nt' else None