2014-12-30 22:28:07 +06:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2018-06-04 03:43:30 +02:00
|
|
|
import json
|
2018-07-13 20:07:31 +02:00
|
|
|
from ..compat import compat_HTTPError
|
2014-12-30 22:28:07 +06:00
|
|
|
|
2015-02-15 18:32:40 +01:00
|
|
|
from .common import InfoExtractor
|
2015-01-15 21:43:35 +06:00
|
|
|
from ..utils import (
|
2016-03-26 02:19:24 +06:00
|
|
|
ExtractorError,
|
2015-11-21 22:18:17 +06:00
|
|
|
sanitized_Request,
|
2016-03-26 02:19:24 +06:00
|
|
|
urlencode_postdata,
|
2014-12-30 22:28:07 +06:00
|
|
|
)
|
|
|
|
|
2018-06-04 03:43:30 +02:00
|
|
|
try:
|
|
|
|
from json import JSONDecodeError
|
|
|
|
except ImportError:
|
|
|
|
JSONDecodeError = ValueError
|
|
|
|
|
2014-12-30 22:28:07 +06:00
|
|
|
|
2015-02-15 18:32:40 +01:00
|
|
|
class AtresPlayerIE(InfoExtractor):
|
2018-07-13 20:07:31 +02:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?atresplayer\.com/[^/]+/[^/]+/[^/]+/[^/]+/[^/_]+_(?P<id>[a-zA-Z0-9]+)'
|
2015-03-03 12:59:17 +01:00
|
|
|
_NETRC_MACHINE = 'atresplayer'
|
2014-12-30 22:28:07 +06:00
|
|
|
_TESTS = [
|
|
|
|
{
|
2018-07-13 20:07:31 +02:00
|
|
|
'url': 'https://www.atresplayer.com/lasexta/programas/el-intermedio/temporada-12/el-intermedio-21-05-18_5b03068d7ed1a8a94b3faf29/',
|
2018-06-04 02:08:59 +02:00
|
|
|
'md5': '3afa3d3cc155264374916f2a23d1d00c',
|
2014-12-30 22:28:07 +06:00
|
|
|
'info_dict': {
|
2018-06-12 23:36:00 +02:00
|
|
|
'id': '5b03068d7ed1a8a94b3faf29',
|
2018-06-04 03:05:43 +02:00
|
|
|
'ext': 'm3u8',
|
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
'skip_download': True,
|
2015-12-21 16:26:40 +01:00
|
|
|
},
|
2018-06-12 23:36:00 +02:00
|
|
|
'skip': 'required_registered',
|
2014-12-30 22:28:07 +06:00
|
|
|
},
|
|
|
|
{
|
2018-07-13 20:07:31 +02:00
|
|
|
'url': 'http://www.atresplayer.com/television/series/el-secreto-de-puente-viejo/el-chico-de-los-tres-lunares/capitulo-977-29-12-14_2014122400174.html',
|
2014-12-30 22:28:07 +06:00
|
|
|
'only_matching': True,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
_USER_AGENT = 'Dalvik/1.6.0 (Linux; U; Android 4.3; GT-I9300 Build/JSS15J'
|
2018-07-13 20:07:31 +02:00
|
|
|
_PLAYER_URL_TEMPLATE = 'https://api.atresplayer.com/client/v1/page/episode/%s'
|
|
|
|
_LOGIN_URL = 'https://api.atresplayer.com/login?redirect=https%3A%2F%2Fwww.atresplayer.com'
|
2018-06-04 05:03:09 +02:00
|
|
|
_LOGIN_ACCOUNT_URL = 'https://account.atresmedia.com/api/login'
|
2015-01-15 21:43:35 +06:00
|
|
|
|
|
|
|
def _real_initialize(self):
|
|
|
|
self._login()
|
|
|
|
|
|
|
|
def _login(self):
|
2018-05-26 16:12:44 +01:00
|
|
|
username, password = self._get_login_info()
|
2015-01-15 21:43:35 +06:00
|
|
|
if username is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
login_form = {
|
2018-06-04 05:03:09 +02:00
|
|
|
'username': username,
|
|
|
|
'password': password,
|
2015-01-15 21:43:35 +06:00
|
|
|
}
|
|
|
|
|
2018-06-04 05:03:09 +02:00
|
|
|
self._download_webpage(self._LOGIN_URL, None, 'get login page')
|
2015-11-21 22:18:17 +06:00
|
|
|
request = sanitized_Request(
|
2018-06-04 05:03:09 +02:00
|
|
|
self._LOGIN_ACCOUNT_URL,
|
|
|
|
urlencode_postdata(login_form),
|
|
|
|
login_form,
|
|
|
|
method='post')
|
2015-01-15 21:43:35 +06:00
|
|
|
request.add_header('Content-Type', 'application/x-www-form-urlencoded')
|
2018-06-04 05:03:09 +02:00
|
|
|
try:
|
|
|
|
response = self._download_json(
|
|
|
|
request, None, 'post to login form')
|
|
|
|
except ExtractorError as e:
|
2018-07-13 20:07:31 +02:00
|
|
|
if isinstance(e.cause, compat_HTTPError):
|
2018-06-12 23:36:00 +02:00
|
|
|
raise self._atres_player_error(e.cause.file.read(), e)
|
2018-06-04 05:03:09 +02:00
|
|
|
else:
|
|
|
|
raise
|
|
|
|
else:
|
2018-06-12 23:49:13 +02:00
|
|
|
self._download_webpage(response['targetUrl'], None,
|
|
|
|
'Set login session')
|
2015-01-15 21:43:35 +06:00
|
|
|
|
2018-06-04 05:03:09 +02:00
|
|
|
def _atres_player_error(self, body_response, original_exception):
|
|
|
|
try:
|
|
|
|
data = json.loads(body_response)
|
|
|
|
except JSONDecodeError:
|
2018-06-12 23:36:00 +02:00
|
|
|
return original_exception
|
2018-06-04 05:03:09 +02:00
|
|
|
if isinstance(data, dict) and 'error' in data:
|
2018-07-13 20:07:31 +02:00
|
|
|
return ExtractorError('{0} returned error: {1} ({2})'.format(
|
2018-06-12 23:49:13 +02:00
|
|
|
self.IE_NAME, data['error'], data.get(
|
|
|
|
'error_description', 'There is no description')
|
2018-06-04 05:03:09 +02:00
|
|
|
), expected=True)
|
|
|
|
else:
|
2018-06-12 23:36:00 +02:00
|
|
|
return original_exception
|
2015-01-15 21:43:35 +06:00
|
|
|
|
2014-12-30 22:28:07 +06:00
|
|
|
def _real_extract(self, url):
|
|
|
|
video_id = self._match_id(url)
|
|
|
|
|
2015-12-21 16:26:40 +01:00
|
|
|
request = sanitized_Request(
|
2018-06-04 03:05:43 +02:00
|
|
|
self._PLAYER_URL_TEMPLATE % video_id,
|
2015-12-21 16:26:40 +01:00
|
|
|
headers={'User-Agent': self._USER_AGENT})
|
2018-06-12 23:49:13 +02:00
|
|
|
player = self._download_json(request, video_id,
|
|
|
|
'Downloading player JSON')
|
2015-12-21 16:26:40 +01:00
|
|
|
|
|
|
|
formats = []
|
|
|
|
video_url = player.get('urlVideo')
|
2014-12-30 22:28:07 +06:00
|
|
|
|
2015-12-21 16:26:40 +01:00
|
|
|
request = sanitized_Request(
|
2018-04-27 18:40:08 +02:00
|
|
|
video_url,
|
2015-12-21 16:26:40 +01:00
|
|
|
headers={'User-Agent': self._USER_AGENT})
|
2018-06-04 03:43:30 +02:00
|
|
|
try:
|
2018-06-12 23:49:13 +02:00
|
|
|
video_data = self._download_json(request, video_id,
|
|
|
|
'Downloading video JSON',
|
|
|
|
fatal=True)
|
2018-06-04 03:43:30 +02:00
|
|
|
except ExtractorError as e:
|
|
|
|
if len(e.exc_info) <= 1 or e.exc_info[1].code != 403:
|
|
|
|
raise
|
2018-06-12 23:36:00 +02:00
|
|
|
raise self._atres_player_error(e.exc_info[1].file.read(), e)
|
2018-04-27 18:40:08 +02:00
|
|
|
|
|
|
|
for source in video_data['sources']:
|
2018-07-13 20:07:31 +02:00
|
|
|
if source.get('type') == 'application/dash+xml':
|
2018-04-27 18:40:08 +02:00
|
|
|
formats.extend(self._extract_mpd_formats(
|
|
|
|
source['src'], video_id, mpd_id='dash',
|
|
|
|
fatal=False))
|
2018-07-13 20:07:31 +02:00
|
|
|
elif source.get('type') == 'application/vnd.apple.mpegurl':
|
2018-04-27 18:40:08 +02:00
|
|
|
formats.extend(self._extract_m3u8_formats(
|
|
|
|
source['src'], video_id,
|
|
|
|
fatal=False))
|
|
|
|
|
2015-12-21 16:26:40 +01:00
|
|
|
self._sort_formats(formats)
|
2014-12-30 22:28:07 +06:00
|
|
|
|
|
|
|
return {
|
|
|
|
'id': video_id,
|
2018-07-13 20:07:31 +02:00
|
|
|
'title': video_data.get('titulo'),
|
|
|
|
'description': video_data.get('descripcion'),
|
|
|
|
'thumbnail': video_data.get('imgPoster'),
|
|
|
|
'duration': video_data.get('duration'),
|
2014-12-30 22:28:07 +06:00
|
|
|
'formats': formats,
|
|
|
|
}
|