mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-09-06 02:49:35 +02:00
parent
1d3586d0d5
commit
7c74a01584
@ -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,
|
||||||
post_url = extract_attributes(login_form_str).get('action')
|
'device_id': 'whatvalueshouldbeforweb',
|
||||||
if not post_url:
|
'device_type': 'com.crunchyroll.static',
|
||||||
post_url = self._LOGIN_URL
|
'access_token': 'giKq5eY27ny3cqz',
|
||||||
elif not post_url.startswith('http'):
|
'referer': self._LOGIN_URL
|
||||||
post_url = compat_urlparse.urljoin(self._LOGIN_URL, post_url)
|
|
||||||
|
|
||||||
login_form = self._form_hidden_inputs(self._LOGIN_FORM, login_page)
|
|
||||||
|
|
||||||
login_form.update({
|
|
||||||
'login_form[name]': username,
|
|
||||||
'login_form[password]': password,
|
|
||||||
})
|
})
|
||||||
|
if upsell_response['code'] != 'ok':
|
||||||
|
raise ExtractorError('Could not get session id')
|
||||||
|
session_id = upsell_response['data']['session_id']
|
||||||
|
|
||||||
response = self._download_webpage(
|
login_response = self._download_json(
|
||||||
post_url, None, 'Logging in', 'Wrong login info',
|
f'{self._API_BASE}/login.1.json', None, 'Logging in',
|
||||||
data=urlencode_postdata(login_form),
|
data=compat_urllib_parse_urlencode({
|
||||||
headers={'Content-Type': 'application/x-www-form-urlencoded'})
|
'account': username,
|
||||||
|
'password': password,
|
||||||
# Successful login
|
'session_id': session_id
|
||||||
if is_logged(response):
|
}).encode('ascii'))
|
||||||
return
|
if login_response['code'] != 'ok':
|
||||||
|
raise ExtractorError('Login failed. Bad username or password?', expected=True)
|
||||||
error = self._html_search_regex(
|
if not self._get_cookies(self._LOGIN_URL).get('etp_rt'):
|
||||||
'(?s)<ul[^>]+class=["\']messages["\'][^>]*>(.+?)</ul>',
|
raise ExtractorError('Login succeeded but did not set etp_rt cookie')
|
||||||
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 New Issue
Block a user