2015-02-15 18:32:40 +01:00
|
|
|
from .common import InfoExtractor
|
2023-07-09 09:53:02 +02:00
|
|
|
from ..networking.exceptions import HTTPError
|
2015-01-15 16:43:35 +01:00
|
|
|
from ..utils import (
|
2016-03-25 21:19:24 +01:00
|
|
|
ExtractorError,
|
|
|
|
int_or_none,
|
|
|
|
urlencode_postdata,
|
2014-12-30 17:28:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2015-02-15 18:32:40 +01:00
|
|
|
class AtresPlayerIE(InfoExtractor):
|
2019-10-16 13:03:46 +02:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?atresplayer\.com/[^/]+/[^/]+/[^/]+/[^/]+/(?P<display_id>.+?)_(?P<id>[0-9a-f]{24})'
|
2015-03-03 12:59:17 +01:00
|
|
|
_NETRC_MACHINE = 'atresplayer'
|
2014-12-30 17:28:07 +01:00
|
|
|
_TESTS = [
|
|
|
|
{
|
2019-10-16 13:03:46 +02:00
|
|
|
'url': 'https://www.atresplayer.com/antena3/series/pequenas-coincidencias/temporada-1/capitulo-7-asuntos-pendientes_5d4aa2c57ed1a88fc715a615/',
|
2014-12-30 17:28:07 +01:00
|
|
|
'info_dict': {
|
2019-10-16 13:03:46 +02:00
|
|
|
'id': '5d4aa2c57ed1a88fc715a615',
|
2014-12-30 17:28:07 +01:00
|
|
|
'ext': 'mp4',
|
2019-10-16 13:03:46 +02:00
|
|
|
'title': 'Capítulo 7: Asuntos pendientes',
|
|
|
|
'description': 'md5:7634cdcb4d50d5381bedf93efb537fbc',
|
|
|
|
'duration': 3413,
|
|
|
|
},
|
2024-06-12 01:09:58 +02:00
|
|
|
'skip': 'This video is only available for registered users',
|
2015-12-21 16:26:40 +01:00
|
|
|
},
|
|
|
|
{
|
2019-10-16 13:03:46 +02:00
|
|
|
'url': 'https://www.atresplayer.com/lasexta/programas/el-club-de-la-comedia/temporada-4/capitulo-10-especial-solidario-nochebuena_5ad08edf986b2855ed47adc4/',
|
|
|
|
'only_matching': True,
|
2014-12-30 17:28:07 +01:00
|
|
|
},
|
|
|
|
{
|
2019-10-16 13:03:46 +02:00
|
|
|
'url': 'https://www.atresplayer.com/antena3/series/el-secreto-de-puente-viejo/el-chico-de-los-tres-lunares/capitulo-977-29-12-14_5ad51046986b2886722ccdea/',
|
2014-12-30 17:28:07 +01:00
|
|
|
'only_matching': True,
|
|
|
|
},
|
|
|
|
]
|
2019-10-16 13:03:46 +02:00
|
|
|
_API_BASE = 'https://api.atresplayer.com/'
|
2015-12-21 16:26:40 +01:00
|
|
|
|
2019-10-16 13:03:46 +02:00
|
|
|
def _handle_error(self, e, code):
|
2023-07-09 09:53:02 +02:00
|
|
|
if isinstance(e.cause, HTTPError) and e.cause.status == code:
|
|
|
|
error = self._parse_json(e.cause.response.read(), None)
|
2019-10-16 13:03:46 +02:00
|
|
|
if error.get('error') == 'required_registered':
|
|
|
|
self.raise_login_required()
|
|
|
|
raise ExtractorError(error['error_description'], expected=True)
|
|
|
|
raise
|
|
|
|
|
2022-03-18 21:53:33 +01:00
|
|
|
def _perform_login(self, username, password):
|
2019-10-16 13:03:46 +02:00
|
|
|
self._request_webpage(
|
|
|
|
self._API_BASE + 'login', None, 'Downloading login page')
|
2015-01-15 16:43:35 +01:00
|
|
|
|
2019-10-16 13:03:46 +02:00
|
|
|
try:
|
|
|
|
target_url = self._download_json(
|
|
|
|
'https://account.atresmedia.com/api/login', None,
|
|
|
|
'Logging in', headers={
|
2024-06-12 01:09:58 +02:00
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
2019-10-16 13:03:46 +02:00
|
|
|
}, data=urlencode_postdata({
|
|
|
|
'username': username,
|
|
|
|
'password': password,
|
|
|
|
}))['targetUrl']
|
|
|
|
except ExtractorError as e:
|
|
|
|
self._handle_error(e, 400)
|
2015-01-15 16:43:35 +01:00
|
|
|
|
2019-10-16 13:03:46 +02:00
|
|
|
self._request_webpage(target_url, None, 'Following Target URL')
|
2015-01-15 16:43:35 +01:00
|
|
|
|
2014-12-30 17:28:07 +01:00
|
|
|
def _real_extract(self, url):
|
2021-08-19 03:41:24 +02:00
|
|
|
display_id, video_id = self._match_valid_url(url).groups()
|
2014-12-30 17:28:07 +01:00
|
|
|
|
2019-10-16 13:03:46 +02:00
|
|
|
try:
|
|
|
|
episode = self._download_json(
|
|
|
|
self._API_BASE + 'client/v1/player/episode/' + video_id, video_id)
|
|
|
|
except ExtractorError as e:
|
|
|
|
self._handle_error(e, 403)
|
2014-12-30 17:28:07 +01:00
|
|
|
|
2019-10-16 13:03:46 +02:00
|
|
|
title = episode['titulo']
|
2015-12-21 16:26:40 +01:00
|
|
|
|
|
|
|
formats = []
|
2021-04-18 16:45:04 +02:00
|
|
|
subtitles = {}
|
2019-10-16 13:03:46 +02:00
|
|
|
for source in episode.get('sources', []):
|
|
|
|
src = source.get('src')
|
|
|
|
if not src:
|
2015-12-21 16:26:40 +01:00
|
|
|
continue
|
2019-10-16 13:03:46 +02:00
|
|
|
src_type = source.get('type')
|
|
|
|
if src_type == 'application/vnd.apple.mpegurl':
|
2021-04-18 16:45:04 +02:00
|
|
|
formats, subtitles = self._extract_m3u8_formats(
|
2019-10-16 13:03:46 +02:00
|
|
|
src, video_id, 'mp4', 'm3u8_native',
|
2021-04-18 16:45:04 +02:00
|
|
|
m3u8_id='hls', fatal=False)
|
2019-10-16 13:03:46 +02:00
|
|
|
elif src_type == 'application/dash+xml':
|
2021-04-18 16:45:04 +02:00
|
|
|
formats, subtitles = self._extract_mpd_formats(
|
|
|
|
src, video_id, mpd_id='dash', fatal=False)
|
2014-12-30 17:28:07 +01:00
|
|
|
|
2019-10-16 13:03:46 +02:00
|
|
|
heartbeat = episode.get('heartbeat') or {}
|
|
|
|
omniture = episode.get('omniture') or {}
|
|
|
|
get_meta = lambda x: heartbeat.get(x) or omniture.get(x)
|
2015-01-23 17:54:29 +01:00
|
|
|
|
2014-12-30 17:28:07 +01:00
|
|
|
return {
|
2019-10-16 13:03:46 +02:00
|
|
|
'display_id': display_id,
|
2014-12-30 17:28:07 +01:00
|
|
|
'id': video_id,
|
|
|
|
'title': title,
|
2019-10-16 13:03:46 +02:00
|
|
|
'description': episode.get('descripcion'),
|
|
|
|
'thumbnail': episode.get('imgPoster'),
|
|
|
|
'duration': int_or_none(episode.get('duration')),
|
2014-12-30 17:28:07 +01:00
|
|
|
'formats': formats,
|
2019-10-16 13:03:46 +02:00
|
|
|
'channel': get_meta('channel'),
|
|
|
|
'season': get_meta('season'),
|
|
|
|
'episode_number': int_or_none(get_meta('episodeNumber')),
|
2021-04-18 16:45:04 +02:00
|
|
|
'subtitles': subtitles,
|
2014-12-30 17:28:07 +01:00
|
|
|
}
|