mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-03-09 12:50:23 -05:00
Move _get_video_token_from_cookie
to InfoExtractor
This commit is contained in:
parent
7c41a4d3df
commit
99710b5694
2 changed files with 9 additions and 9 deletions
|
@ -69,6 +69,7 @@
|
||||||
int_or_none,
|
int_or_none,
|
||||||
join_nonempty,
|
join_nonempty,
|
||||||
js_to_json,
|
js_to_json,
|
||||||
|
jwt_decode_hs256,
|
||||||
mimetype2ext,
|
mimetype2ext,
|
||||||
netrc_from_content,
|
netrc_from_content,
|
||||||
orderedSet,
|
orderedSet,
|
||||||
|
@ -994,6 +995,10 @@ def _guess_encoding_from_content(content_type, webpage_bytes):
|
||||||
|
|
||||||
return encoding
|
return encoding
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _is_jwt_token_expired(token):
|
||||||
|
return jwt_decode_hs256(token)['exp'] - time.time() < 300
|
||||||
|
|
||||||
def __check_blocked(self, content):
|
def __check_blocked(self, content):
|
||||||
first_block = content[:512]
|
first_block = content[:512]
|
||||||
if ('<title>Access to this site is blocked</title>' in content
|
if ('<title>Access to this site is blocked</title>' in content
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
get_element_by_class,
|
get_element_by_class,
|
||||||
get_element_html_by_class,
|
get_element_html_by_class,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
jwt_decode_hs256,
|
|
||||||
jwt_encode_hs256,
|
jwt_encode_hs256,
|
||||||
make_archive_id,
|
make_archive_id,
|
||||||
merge_dicts,
|
merge_dicts,
|
||||||
|
@ -177,10 +176,6 @@ def _real_extract(self, url):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def jwt_is_expired(token):
|
|
||||||
return jwt_decode_hs256(token)['exp'] - time.time() < 300
|
|
||||||
|
|
||||||
|
|
||||||
class VrtNUIE(VRTBaseIE):
|
class VrtNUIE(VRTBaseIE):
|
||||||
IE_DESC = 'VRT MAX'
|
IE_DESC = 'VRT MAX'
|
||||||
_VALID_URL = r'https?://(?:www\.)?vrt\.be/(?:vrtnu|vrtmax)/a-z/(?:[^/]+/){2}(?P<id>[^/?#&]+)'
|
_VALID_URL = r'https?://(?:www\.)?vrt\.be/(?:vrtnu|vrtmax)/a-z/(?:[^/]+/){2}(?P<id>[^/?#&]+)'
|
||||||
|
@ -266,26 +261,26 @@ class VrtNUIE(VRTBaseIE):
|
||||||
|
|
||||||
def _fetch_refresh_token(self):
|
def _fetch_refresh_token(self):
|
||||||
refresh_token = self._get_refresh_token_from_cookie()
|
refresh_token = self._get_refresh_token_from_cookie()
|
||||||
if refresh_token and not jwt_is_expired(refresh_token):
|
if refresh_token and not self._is_jwt_token_expired(refresh_token):
|
||||||
return refresh_token
|
return refresh_token
|
||||||
|
|
||||||
if not self._get_login_info()[0]:
|
if not self._get_login_info()[0]:
|
||||||
return
|
return
|
||||||
|
|
||||||
refresh_token = self.cache.load(self._NETRC_MACHINE, 'refresh_token', default=None)
|
refresh_token = self.cache.load(self._NETRC_MACHINE, 'refresh_token', default=None)
|
||||||
if refresh_token and not jwt_is_expired(refresh_token):
|
if refresh_token and not self._is_jwt_token_expired(refresh_token):
|
||||||
self.write_debug('Restored refresh token from cache')
|
self.write_debug('Restored refresh token from cache')
|
||||||
self._set_cookie('.www.vrt.be', 'vrtnu-site_profile_rt', refresh_token, path='/vrtmax/sso')
|
self._set_cookie('.www.vrt.be', 'vrtnu-site_profile_rt', refresh_token, path='/vrtmax/sso')
|
||||||
return refresh_token
|
return refresh_token
|
||||||
|
|
||||||
def _fetch_video_token(self):
|
def _fetch_video_token(self):
|
||||||
video_token = self._get_video_token_from_cookie()
|
video_token = self._get_video_token_from_cookie()
|
||||||
if video_token and not jwt_is_expired(video_token):
|
if video_token and not self._is_jwt_token_expired(video_token):
|
||||||
return video_token
|
return video_token
|
||||||
|
|
||||||
if self._get_login_info()[0]:
|
if self._get_login_info()[0]:
|
||||||
video_token = self.cache.load(self._NETRC_MACHINE, 'video_token', default=None)
|
video_token = self.cache.load(self._NETRC_MACHINE, 'video_token', default=None)
|
||||||
if video_token and not jwt_is_expired(video_token):
|
if video_token and not self._is_jwt_token_expired(video_token):
|
||||||
self.write_debug('Restored video token from cache')
|
self.write_debug('Restored video token from cache')
|
||||||
self._set_cookie('.www.vrt.be', 'vrtnu-site_profile_vt', video_token)
|
self._set_cookie('.www.vrt.be', 'vrtnu-site_profile_vt', video_token)
|
||||||
return video_token
|
return video_token
|
||||||
|
|
Loading…
Reference in a new issue