Atresplayer PR changes.

This commit is contained in:
Nekmo 2018-07-13 20:07:31 +02:00
parent 12117873e5
commit bbb857cc94

View File

@ -1,11 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import json import json
from ..compat import compat_HTTPError
try:
from urllib.error import HTTPError
except ImportError:
from urllib2 import HTTPError
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
@ -21,14 +17,11 @@ except ImportError:
class AtresPlayerIE(InfoExtractor): class AtresPlayerIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?atresplayer\.com/[^/]+/[^/]+/' \ _VALID_URL = r'https?://(?:www\.)?atresplayer\.com/[^/]+/[^/]+/[^/]+/[^/]+/[^/_]+_(?P<id>[a-zA-Z0-9]+)'
r'[^/]+/[^/]+/[^/_]+_(?P<id>[A-z0-9]+)/?'
_NETRC_MACHINE = 'atresplayer' _NETRC_MACHINE = 'atresplayer'
_TESTS = [ _TESTS = [
{ {
'url': 'https://www.atresplayer.com/lasexta/programas/el-' 'url': 'https://www.atresplayer.com/lasexta/programas/el-intermedio/temporada-12/el-intermedio-21-05-18_5b03068d7ed1a8a94b3faf29/',
'intermedio/temporada-12/el-intermedio-21-05-18_'
'5b03068d7ed1a8a94b3faf29/',
'md5': '3afa3d3cc155264374916f2a23d1d00c', 'md5': '3afa3d3cc155264374916f2a23d1d00c',
'info_dict': { 'info_dict': {
'id': '5b03068d7ed1a8a94b3faf29', 'id': '5b03068d7ed1a8a94b3faf29',
@ -40,19 +33,14 @@ class AtresPlayerIE(InfoExtractor):
'skip': 'required_registered', 'skip': 'required_registered',
}, },
{ {
'url': 'http://www.atresplayer.com/television/series/' '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',
'el-secreto-de-puente-viejo/el-chico-de-los-'
'tres-lunares/capitulo-977-29-12-14_'
'2014122400174.html',
'only_matching': True, 'only_matching': True,
}, },
] ]
_USER_AGENT = 'Dalvik/1.6.0 (Linux; U; Android 4.3; GT-I9300 Build/JSS15J' _USER_AGENT = 'Dalvik/1.6.0 (Linux; U; Android 4.3; GT-I9300 Build/JSS15J'
_PLAYER_URL_TEMPLATE = 'https://api.atresplayer.com/client/v1/page/' \ _PLAYER_URL_TEMPLATE = 'https://api.atresplayer.com/client/v1/page/episode/%s'
'episode/%s' _LOGIN_URL = 'https://api.atresplayer.com/login?redirect=https%3A%2F%2Fwww.atresplayer.com'
_LOGIN_URL = 'https://api.atresplayer.com/login?redirect=https%3A%2F%2F' \
'www.atresplayer.com'
_LOGIN_ACCOUNT_URL = 'https://account.atresmedia.com/api/login' _LOGIN_ACCOUNT_URL = 'https://account.atresmedia.com/api/login'
def _real_initialize(self): def _real_initialize(self):
@ -79,7 +67,7 @@ class AtresPlayerIE(InfoExtractor):
response = self._download_json( response = self._download_json(
request, None, 'post to login form') request, None, 'post to login form')
except ExtractorError as e: except ExtractorError as e:
if isinstance(e.cause, HTTPError): if isinstance(e.cause, compat_HTTPError):
raise self._atres_player_error(e.cause.file.read(), e) raise self._atres_player_error(e.cause.file.read(), e)
else: else:
raise raise
@ -93,7 +81,7 @@ class AtresPlayerIE(InfoExtractor):
except JSONDecodeError: except JSONDecodeError:
return original_exception return original_exception
if isinstance(data, dict) and 'error' in data: if isinstance(data, dict) and 'error' in data:
return ExtractorError('{} returned error: {} ({})'.format( return ExtractorError('{0} returned error: {1} ({2})'.format(
self.IE_NAME, data['error'], data.get( self.IE_NAME, data['error'], data.get(
'error_description', 'There is no description') 'error_description', 'There is no description')
), expected=True) ), expected=True)
@ -125,11 +113,11 @@ class AtresPlayerIE(InfoExtractor):
raise self._atres_player_error(e.exc_info[1].file.read(), e) raise self._atres_player_error(e.exc_info[1].file.read(), e)
for source in video_data['sources']: for source in video_data['sources']:
if source['type'] == "application/dash+xml": if source.get('type') == 'application/dash+xml':
formats.extend(self._extract_mpd_formats( formats.extend(self._extract_mpd_formats(
source['src'], video_id, mpd_id='dash', source['src'], video_id, mpd_id='dash',
fatal=False)) fatal=False))
elif source['type'] == "application/vnd.apple.mpegurl": elif source.get('type') == 'application/vnd.apple.mpegurl':
formats.extend(self._extract_m3u8_formats( formats.extend(self._extract_m3u8_formats(
source['src'], video_id, source['src'], video_id,
fatal=False)) fatal=False))
@ -138,9 +126,9 @@ class AtresPlayerIE(InfoExtractor):
return { return {
'id': video_id, 'id': video_id,
'title': video_data['titulo'], 'title': video_data.get('titulo'),
'description': video_data['descripcion'], 'description': video_data.get('descripcion'),
'thumbnail': video_data['imgPoster'], 'thumbnail': video_data.get('imgPoster'),
'duration': video_data['duration'], 'duration': video_data.get('duration'),
'formats': formats, 'formats': formats,
} }