Skip to content

Commit

Permalink
[ie/abematv] Fix extraction with cache (yt-dlp#8895)
Browse files Browse the repository at this point in the history
Closes yt-dlp#6532
Authored by: sefidel
  • Loading branch information
sefidel authored Jan 19, 2024
1 parent a281beb commit c51316f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions yt_dlp/extractor/abematv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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

Expand All @@ -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,
Expand Down

0 comments on commit c51316f

Please sign in to comment.