1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-07-06 05:18:31 +00:00

add buffer argument to _jwt_is_expired

This commit is contained in:
Michaël De Boey 2025-03-16 23:26:14 +01:00
parent 5ffedda327
commit 98a68be9b8
No known key found for this signature in database
6 changed files with 13 additions and 10 deletions

View File

@ -996,8 +996,8 @@ def _guess_encoding_from_content(content_type, webpage_bytes):
return encoding
@staticmethod
def _jwt_is_expired(token):
return jwt_decode_hs256(token)['exp'] - time.time() < 300
def _jwt_is_expired(token, buffer=300):
return jwt_decode_hs256(token)['exp'] - time.time() < buffer
def __check_blocked(self, content):
first_block = content[:512]

View File

@ -86,7 +86,7 @@ class DigitalConcertHallIE(InfoExtractor):
@property
def _access_token_is_expired(self):
return self._jwt_is_expired(self._access_token)
return self._jwt_is_expired(self._access_token, 30)
def _set_access_token(self, value):
self._access_token = value

View File

@ -22,7 +22,7 @@ class IwaraBaseIE(InfoExtractor):
def _is_token_expired(self, token, token_type):
# User token TTL == ~3 weeks, Media token TTL == ~1 hour
if self._jwt_is_expired(token):
if self._jwt_is_expired(token, 120):
self.to_screen(f'{token_type} token has expired')
return True

View File

@ -105,8 +105,11 @@ def _call_login_api(self, endpoint, guest_token, data, note):
'os': ('os', {str}),
})}, data=data)
def _is_token_expired(self, token):
return self._jwt_is_expired(token, 180)
def _perform_login(self, username, password):
if self._ACCESS_TOKEN and not self._jwt_is_expired(self._ACCESS_TOKEN):
if self._ACCESS_TOKEN and not self._is_token_expired(self._ACCESS_TOKEN):
return
UUID_RE = r'[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12}'
@ -181,7 +184,7 @@ def _perform_login(self, username, password):
if JioCinemaBaseIE._REFRESH_TOKEN:
self._cache_token('access')
self.to_screen(f'Logging in as device ID "{JioCinemaBaseIE._DEVICE_ID}"')
if self._jwt_is_expired(JioCinemaBaseIE._ACCESS_TOKEN):
if self._is_token_expired(JioCinemaBaseIE._ACCESS_TOKEN):
self._refresh_token()
@ -246,9 +249,9 @@ def _extract_formats_and_subtitles(self, playback, video_id):
def _real_extract(self, url):
video_id = self._match_id(url)
if not self._ACCESS_TOKEN and self._jwt_is_expired(self._GUEST_TOKEN):
if not self._ACCESS_TOKEN and self._is_token_expired(self._GUEST_TOKEN):
self._fetch_guest_token()
elif self._ACCESS_TOKEN and self._jwt_is_expired(self._ACCESS_TOKEN):
elif self._ACCESS_TOKEN and self._is_token_expired(self._ACCESS_TOKEN):
self._refresh_token()
playback = self._call_api(

View File

@ -351,7 +351,7 @@ class MLBTVIE(InfoExtractor):
@property
def _api_headers(self):
if self._jwt_is_expired(self._access_token):
if self._jwt_is_expired(self._access_token, 120):
self.write_debug('Access token has expired; re-logging in')
self._perform_login(*self._get_login_info())
return {'Authorization': f'Bearer {self._access_token}'}

View File

@ -114,7 +114,7 @@ def _real_initialize(self):
self.raise_login_required()
def _get_auth(self):
if self._jwt_is_expired(self._access_token):
if self._jwt_is_expired(self._access_token, 120):
if not self._refresh_token:
raise ExtractorError(
'Cannot refresh access token, login with yt-dlp or refresh cookies in browser')