Atresplayer login.
This commit is contained in:
parent
c734b064d0
commit
1a981adbdd
@ -1,7 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
from urllib.error import HTTPError
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
@ -16,6 +16,8 @@ except ImportError:
|
|||||||
JSONDecodeError = ValueError
|
JSONDecodeError = ValueError
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AtresPlayerIE(InfoExtractor):
|
class AtresPlayerIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?atresplayer\.com/[^/]+/[^/]+/[^/]+/[^/]+/[^/_]+_(?P<id>[A-z0-9]+)/?'
|
_VALID_URL = r'https?://(?:www\.)?atresplayer\.com/[^/]+/[^/]+/[^/]+/[^/]+/[^/_]+_(?P<id>[A-z0-9]+)/?'
|
||||||
_NETRC_MACHINE = 'atresplayer'
|
_NETRC_MACHINE = 'atresplayer'
|
||||||
@ -45,34 +47,54 @@ class AtresPlayerIE(InfoExtractor):
|
|||||||
|
|
||||||
_PLAYER_URL_TEMPLATE = 'https://api.atresplayer.com/client/v1/page/episode/%s'
|
_PLAYER_URL_TEMPLATE = 'https://api.atresplayer.com/client/v1/page/episode/%s'
|
||||||
|
|
||||||
_LOGIN_URL = 'https://servicios.atresplayer.com/j_spring_security_check'
|
_LOGIN_URL = 'https://api.atresplayer.com/login?redirect=https%3A%2F%2Fwww.atresplayer.com'
|
||||||
|
_LOGIN_ACCOUNT_URL = 'https://account.atresmedia.com/api/login'
|
||||||
|
|
||||||
|
|
||||||
def _real_initialize(self):
|
def _real_initialize(self):
|
||||||
self._login()
|
self._login()
|
||||||
|
|
||||||
def _login(self):
|
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
|
||||||
|
|
||||||
login_form = {
|
login_form = {
|
||||||
'j_username': username,
|
'username': username,
|
||||||
'j_password': password,
|
'password': password,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self._download_webpage(self._LOGIN_URL, None, 'get login page')
|
||||||
request = sanitized_Request(
|
request = sanitized_Request(
|
||||||
self._LOGIN_URL, urlencode_postdata(login_form))
|
self._LOGIN_ACCOUNT_URL,
|
||||||
|
urlencode_postdata(login_form),
|
||||||
|
login_form,
|
||||||
|
method='post')
|
||||||
request.add_header('Content-Type', 'application/x-www-form-urlencoded')
|
request.add_header('Content-Type', 'application/x-www-form-urlencoded')
|
||||||
response = self._download_webpage(
|
# request.add_header('Content-Type', 'multipart/form-data')
|
||||||
request, None, 'Logging in')
|
try:
|
||||||
|
response = self._download_json(
|
||||||
|
request, None, 'post to login form')
|
||||||
|
except ExtractorError as e:
|
||||||
|
if isinstance(e.cause, HTTPError):
|
||||||
|
self._atres_player_error(e.cause.file.read(), e)
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
self._download_webpage(response['targetUrl'], None, 'Set login session')
|
||||||
|
|
||||||
error = self._html_search_regex(
|
def _atres_player_error(self, body_response, original_exception):
|
||||||
r'(?s)<ul[^>]+class="[^"]*\blist_error\b[^"]*">(.+?)</ul>',
|
try:
|
||||||
response, 'error', default=None)
|
data = json.loads(body_response)
|
||||||
if error:
|
except JSONDecodeError:
|
||||||
raise ExtractorError(
|
raise original_exception
|
||||||
'Unable to login: %s' % error, expected=True)
|
if isinstance(data, dict) and 'error' in data:
|
||||||
|
raise ExtractorError('{} returned error: {} ({})'.format(
|
||||||
|
self.IE_NAME, data['error'], data.get('error_description', 'There is no description')
|
||||||
|
), expected=True)
|
||||||
|
else:
|
||||||
|
raise original_exception
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
@ -93,16 +115,7 @@ class AtresPlayerIE(InfoExtractor):
|
|||||||
except ExtractorError as e:
|
except ExtractorError as e:
|
||||||
if len(e.exc_info) <= 1 or e.exc_info[1].code != 403:
|
if len(e.exc_info) <= 1 or e.exc_info[1].code != 403:
|
||||||
raise
|
raise
|
||||||
try:
|
self._atres_player_error(e.exc_info[1].file.read(), e)
|
||||||
data = json.loads(e.exc_info[1].file.read())
|
|
||||||
except JSONDecodeError:
|
|
||||||
raise e
|
|
||||||
if isinstance(data, dict) and 'error' in data:
|
|
||||||
raise ExtractorError('{} returned error: {} ({})'.format(
|
|
||||||
self.IE_NAME, data['error'], data.get('error_description', 'There is no description')
|
|
||||||
), expected=True)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
for source in video_data['sources']:
|
for source in video_data['sources']:
|
||||||
if source['type'] == "application/dash+xml":
|
if source['type'] == "application/dash+xml":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user