import time from .common import InfoExtractor from ..utils import ( ExtractorError, clean_html, clean_podcast_url, int_or_none, jwt_decode_hs256, jwt_encode, parse_iso8601, try_call, update_url, url_or_none, urljoin, ) from ..utils.traversal import traverse_obj class AppleBaseIE(InfoExtractor): """Subclasses must set _BASE_URL and _JWT_KEY_ID""" _jwt_cache = {} @staticmethod def _jwt_is_expired(token): return jwt_decode_hs256(token)['exp'] - time.time() < 120 def _get_token(self, webpage, episode_id): if self._jwt_cache.get(self._BASE_URL) and not self._jwt_is_expired(self._jwt_cache[self._BASE_URL]): return self._jwt js_path = self._search_regex( r'