Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Weverse preview endpoint if no auth provided #7924

Merged
merged 3 commits into from Aug 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions yt_dlp/extractor/weverse.py
Expand Up @@ -70,10 +70,8 @@ def _real_initialize(self):
return

token = try_call(lambda: self._get_cookies('https://weverse.io/')['we2_access_token'].value)
if not token:
self.raise_login_required()

WeverseBaseIE._API_HEADERS['Authorization'] = f'Bearer {token}'
if token:
WeverseBaseIE._API_HEADERS['Authorization'] = f'Bearer {token}'

def _call_api(self, ep, video_id, data=None, note='Downloading API JSON'):
# Ref: https://ssl.pstatic.net/static/wevweb/2_3_2_11101725/public/static/js/2488.a09b41ff.chunk.js
Expand Down Expand Up @@ -101,11 +99,14 @@ def _call_api(self, ep, video_id, data=None, note='Downloading API JSON'):
self.raise_login_required(
'Session token has expired. Log in again or refresh cookies in browser')
elif isinstance(e.cause, HTTPError) and e.cause.status == 403:
raise ExtractorError('Your account does not have access to this content', expected=True)
if 'Authorization' in self._API_HEADERS:
raise ExtractorError('Your account does not have access to this content', expected=True)
self.raise_login_required()
raise

def _call_post_api(self, video_id):
return self._call_api(f'/post/v1.0/post-{video_id}?fieldSet=postV1', video_id)
path = '' if 'Authorization' in self._API_HEADERS else '/preview'
return self._call_api(f'/post/v1.0/post-{video_id}{path}?fieldSet=postV1', video_id)

def _get_community_id(self, channel):
return str(self._call_api(
Expand Down