From c51316f8a69fbd0080f2720777d42ab438e254a3 Mon Sep 17 00:00:00 2001 From: sefidel Date: Fri, 19 Jan 2024 18:43:13 +0900 Subject: [PATCH] [ie/abematv] Fix extraction with cache (#8895) Closes #6532 Authored by: sefidel --- yt_dlp/extractor/abematv.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/yt_dlp/extractor/abematv.py b/yt_dlp/extractor/abematv.py index 57ccb928b..0a610e315 100644 --- a/yt_dlp/extractor/abematv.py +++ b/yt_dlp/extractor/abematv.py @@ -136,11 +136,15 @@ def _get_device_token(self): if self._USERTOKEN: return self._USERTOKEN + add_opener(self._downloader, AbemaLicenseHandler(self)) + username, _ = self._get_login_info() - AbemaTVBaseIE._USERTOKEN = username and self.cache.load(self._NETRC_MACHINE, username) + auth_cache = username and self.cache.load(self._NETRC_MACHINE, username, min_ver='2024.01.19') + AbemaTVBaseIE._USERTOKEN = auth_cache and auth_cache.get('usertoken') if AbemaTVBaseIE._USERTOKEN: # try authentication with locally stored token try: + AbemaTVBaseIE._DEVICE_ID = auth_cache.get('device_id') self._get_media_token(True) return except ExtractorError as e: @@ -159,7 +163,6 @@ def _get_device_token(self): }) AbemaTVBaseIE._USERTOKEN = user_data['token'] - add_opener(self._downloader, AbemaLicenseHandler(self)) return self._USERTOKEN def _get_media_token(self, invalidate=False, to_show=True): @@ -255,7 +258,7 @@ class AbemaTVIE(AbemaTVBaseIE): def _perform_login(self, username, password): self._get_device_token() - if self.cache.load(self._NETRC_MACHINE, username) and self._get_media_token(): + if self.cache.load(self._NETRC_MACHINE, username, min_ver='2024.01.19') and self._get_media_token(): self.write_debug('Skipping logging in') return @@ -278,7 +281,11 @@ def _perform_login(self, username, password): AbemaTVBaseIE._USERTOKEN = login_response['token'] self._get_media_token(True) - self.cache.store(self._NETRC_MACHINE, username, AbemaTVBaseIE._USERTOKEN) + auth_cache = { + 'device_id': AbemaTVBaseIE._DEVICE_ID, + 'usertoken': AbemaTVBaseIE._USERTOKEN, + } + self.cache.store(self._NETRC_MACHINE, username, auth_cache) def _real_extract(self, url): # starting download using infojson from this extractor is undefined behavior,