mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-17 23:04:00 -05:00
parent
1d3586d0d5
commit
7c74a01584
1 changed files with 26 additions and 44 deletions
|
@ -35,7 +35,6 @@
|
||||||
sanitized_Request,
|
sanitized_Request,
|
||||||
traverse_obj,
|
traverse_obj,
|
||||||
try_get,
|
try_get,
|
||||||
urlencode_postdata,
|
|
||||||
xpath_text,
|
xpath_text,
|
||||||
)
|
)
|
||||||
from ..aes import (
|
from ..aes import (
|
||||||
|
@ -44,8 +43,8 @@
|
||||||
|
|
||||||
|
|
||||||
class CrunchyrollBaseIE(InfoExtractor):
|
class CrunchyrollBaseIE(InfoExtractor):
|
||||||
_LOGIN_URL = 'https://www.crunchyroll.com/login'
|
_LOGIN_URL = 'https://www.crunchyroll.com/welcome/login'
|
||||||
_LOGIN_FORM = 'login_form'
|
_API_BASE = 'https://api.crunchyroll.com'
|
||||||
_NETRC_MACHINE = 'crunchyroll'
|
_NETRC_MACHINE = 'crunchyroll'
|
||||||
|
|
||||||
def _call_rpc_api(self, method, video_id, note=None, data=None):
|
def _call_rpc_api(self, method, video_id, note=None, data=None):
|
||||||
|
@ -62,50 +61,33 @@ def _login(self):
|
||||||
username, password = self._get_login_info()
|
username, password = self._get_login_info()
|
||||||
if username is None:
|
if username is None:
|
||||||
return
|
return
|
||||||
|
if self._get_cookies(self._LOGIN_URL).get('etp_rt'):
|
||||||
login_page = self._download_webpage(
|
|
||||||
self._LOGIN_URL, None, 'Downloading login page')
|
|
||||||
|
|
||||||
def is_logged(webpage):
|
|
||||||
return 'href="/logout"' in webpage
|
|
||||||
|
|
||||||
# Already logged in
|
|
||||||
if is_logged(login_page):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
login_form_str = self._search_regex(
|
upsell_response = self._download_json(
|
||||||
r'(?P<form><form[^>]+?id=(["\'])%s\2[^>]*>)' % self._LOGIN_FORM,
|
f'{self._API_BASE}/get_upsell_data.0.json', None, 'Getting session id',
|
||||||
login_page, 'login form', group='form')
|
query={
|
||||||
|
'sess_id': 1,
|
||||||
|
'device_id': 'whatvalueshouldbeforweb',
|
||||||
|
'device_type': 'com.crunchyroll.static',
|
||||||
|
'access_token': 'giKq5eY27ny3cqz',
|
||||||
|
'referer': self._LOGIN_URL
|
||||||
|
})
|
||||||
|
if upsell_response['code'] != 'ok':
|
||||||
|
raise ExtractorError('Could not get session id')
|
||||||
|
session_id = upsell_response['data']['session_id']
|
||||||
|
|
||||||
post_url = extract_attributes(login_form_str).get('action')
|
login_response = self._download_json(
|
||||||
if not post_url:
|
f'{self._API_BASE}/login.1.json', None, 'Logging in',
|
||||||
post_url = self._LOGIN_URL
|
data=compat_urllib_parse_urlencode({
|
||||||
elif not post_url.startswith('http'):
|
'account': username,
|
||||||
post_url = compat_urlparse.urljoin(self._LOGIN_URL, post_url)
|
'password': password,
|
||||||
|
'session_id': session_id
|
||||||
login_form = self._form_hidden_inputs(self._LOGIN_FORM, login_page)
|
}).encode('ascii'))
|
||||||
|
if login_response['code'] != 'ok':
|
||||||
login_form.update({
|
raise ExtractorError('Login failed. Bad username or password?', expected=True)
|
||||||
'login_form[name]': username,
|
if not self._get_cookies(self._LOGIN_URL).get('etp_rt'):
|
||||||
'login_form[password]': password,
|
raise ExtractorError('Login succeeded but did not set etp_rt cookie')
|
||||||
})
|
|
||||||
|
|
||||||
response = self._download_webpage(
|
|
||||||
post_url, None, 'Logging in', 'Wrong login info',
|
|
||||||
data=urlencode_postdata(login_form),
|
|
||||||
headers={'Content-Type': 'application/x-www-form-urlencoded'})
|
|
||||||
|
|
||||||
# Successful login
|
|
||||||
if is_logged(response):
|
|
||||||
return
|
|
||||||
|
|
||||||
error = self._html_search_regex(
|
|
||||||
'(?s)<ul[^>]+class=["\']messages["\'][^>]*>(.+?)</ul>',
|
|
||||||
response, 'error message', default=None)
|
|
||||||
if error:
|
|
||||||
raise ExtractorError('Unable to login: %s' % error, expected=True)
|
|
||||||
|
|
||||||
raise ExtractorError('Unable to log in')
|
|
||||||
|
|
||||||
def _real_initialize(self):
|
def _real_initialize(self):
|
||||||
self._login()
|
self._login()
|
||||||
|
|
Loading…
Reference in a new issue