diff --git a/yt_dlp/extractor/common.py b/yt_dlp/extractor/common.py index 84bdea80bf..306ad737f8 100644 --- a/yt_dlp/extractor/common.py +++ b/yt_dlp/extractor/common.py @@ -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] diff --git a/yt_dlp/extractor/digitalconcerthall.py b/yt_dlp/extractor/digitalconcerthall.py index a19b96a66d..1c0ff4a7d6 100644 --- a/yt_dlp/extractor/digitalconcerthall.py +++ b/yt_dlp/extractor/digitalconcerthall.py @@ -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 diff --git a/yt_dlp/extractor/iwara.py b/yt_dlp/extractor/iwara.py index 32c5aea891..f79f835767 100644 --- a/yt_dlp/extractor/iwara.py +++ b/yt_dlp/extractor/iwara.py @@ -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 diff --git a/yt_dlp/extractor/jiocinema.py b/yt_dlp/extractor/jiocinema.py index 3d9957f5f5..e8858695ea 100644 --- a/yt_dlp/extractor/jiocinema.py +++ b/yt_dlp/extractor/jiocinema.py @@ -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( diff --git a/yt_dlp/extractor/mlb.py b/yt_dlp/extractor/mlb.py index c8f4fcf7e8..f6a8617d4e 100644 --- a/yt_dlp/extractor/mlb.py +++ b/yt_dlp/extractor/mlb.py @@ -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}'} diff --git a/yt_dlp/extractor/qdance.py b/yt_dlp/extractor/qdance.py index 3faab0465e..46934cfd6b 100644 --- a/yt_dlp/extractor/qdance.py +++ b/yt_dlp/extractor/qdance.py @@ -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')