From 867aa7f776a22b3c23417b44c8184d905debc6bc Mon Sep 17 00:00:00 2001 From: bashonly Date: Fri, 1 Aug 2025 15:28:12 -0500 Subject: [PATCH] [ie/weverse] Fix livestream support Authored by: bashonly --- yt_dlp/extractor/weverse.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/yt_dlp/extractor/weverse.py b/yt_dlp/extractor/weverse.py index c13ab8e23..8d7a54c9f 100644 --- a/yt_dlp/extractor/weverse.py +++ b/yt_dlp/extractor/weverse.py @@ -99,6 +99,10 @@ def _token_is_expired(self, key): return is_expired return not self._access_token_is_valid() + def _set_weverse_auth_cookies(self): + self._set_cookie('.weverse.io', self._ACCESS_TOKEN_KEY, self._oauth_tokens[self._ACCESS_TOKEN_KEY]) + self._set_cookie('.weverse.io', self._REFRESH_TOKEN_KEY, self._oauth_tokens[self._REFRESH_TOKEN_KEY]) + def _refresh_access_token(self): if not self._oauth_tokens.get(self._REFRESH_TOKEN_KEY): self._report_login_error('no_refresh_token') @@ -120,10 +124,9 @@ def _refresh_access_token(self): except ExtractorError as e: if isinstance(e.cause, HTTPError) and e.cause.status == 401: self._oauth_tokens.clear() - if self._oauth_cache_key == 'cookies': - self.cookiejar.clear(domain='.weverse.io', path='/', name=self._ACCESS_TOKEN_KEY) - self.cookiejar.clear(domain='.weverse.io', path='/', name=self._REFRESH_TOKEN_KEY) - else: + self.cookiejar.clear(domain='.weverse.io', path='/', name=self._ACCESS_TOKEN_KEY) + self.cookiejar.clear(domain='.weverse.io', path='/', name=self._REFRESH_TOKEN_KEY) + if self._oauth_cache_key != 'cookies': self.cache.store(self._NETRC_MACHINE, self._oauth_cache_key, self._oauth_tokens) self._report_login_error('expired_refresh_token') raise @@ -133,10 +136,8 @@ def _refresh_access_token(self): self._REFRESH_TOKEN_KEY: ('refreshToken', {str}, {require('refresh token')}), })) - if self._oauth_cache_key == 'cookies': - self._set_cookie('.weverse.io', self._ACCESS_TOKEN_KEY, self._oauth_tokens[self._ACCESS_TOKEN_KEY]) - self._set_cookie('.weverse.io', self._REFRESH_TOKEN_KEY, self._oauth_tokens[self._REFRESH_TOKEN_KEY]) - else: + self._set_weverse_auth_cookies() + if self._oauth_cache_key != 'cookies': self.cache.store(self._NETRC_MACHINE, self._oauth_cache_key, self._oauth_tokens) def _get_authorization_header(self): @@ -169,6 +170,7 @@ def _perform_login(self, username, password): self._oauth_tokens.update(self.cache.load(self._NETRC_MACHINE, self._oauth_cache_key, default={})) if self._is_logged_in and self._access_token_is_valid(): + self._set_weverse_auth_cookies() return rt_key = self._REFRESH_TOKEN_KEY @@ -471,6 +473,8 @@ def _real_extract(self, url): 'channel': channel, 'channel_url': f'https://weverse.io/{channel}', 'formats': formats, + # Needed for livestream HLS AES keys + 'additional_cookies_urls': ['https://video-api.weverse.io/'], 'availability': availability, 'live_status': live_status, **self._parse_post_meta(post),