1 from .common
import InfoExtractor
2 from ..networking
.exceptions
import HTTPError
10 class AtresPlayerIE(InfoExtractor
):
11 _VALID_URL
= r
'https?://(?:www\.)?atresplayer\.com/[^/]+/[^/]+/[^/]+/[^/]+/(?P<display_id>.+?)_(?P<id>[0-9a-f]{24})'
12 _NETRC_MACHINE
= 'atresplayer'
15 'url': 'https://www.atresplayer.com/antena3/series/pequenas-coincidencias/temporada-1/capitulo-7-asuntos-pendientes_5d4aa2c57ed1a88fc715a615/',
17 'id': '5d4aa2c57ed1a88fc715a615',
19 'title': 'CapĂtulo 7: Asuntos pendientes',
20 'description': 'md5:7634cdcb4d50d5381bedf93efb537fbc',
23 'skip': 'This video is only available for registered users'
26 'url': 'https://www.atresplayer.com/lasexta/programas/el-club-de-la-comedia/temporada-4/capitulo-10-especial-solidario-nochebuena_5ad08edf986b2855ed47adc4/',
27 'only_matching': True,
30 'url': 'https://www.atresplayer.com/antena3/series/el-secreto-de-puente-viejo/el-chico-de-los-tres-lunares/capitulo-977-29-12-14_5ad51046986b2886722ccdea/',
31 'only_matching': True,
34 _API_BASE
= 'https://api.atresplayer.com/'
36 def _handle_error(self
, e
, code
):
37 if isinstance(e
.cause
, HTTPError
) and e
.cause
.status
== code
:
38 error
= self
._parse
_json
(e
.cause
.response
.read(), None)
39 if error
.get('error') == 'required_registered':
40 self
.raise_login_required()
41 raise ExtractorError(error
['error_description'], expected
=True)
44 def _perform_login(self
, username
, password
):
45 self
._request
_webpage
(
46 self
._API
_BASE
+ 'login', None, 'Downloading login page')
49 target_url
= self
._download
_json
(
50 'https://account.atresmedia.com/api/login', None,
51 'Logging in', headers
={
52 'Content-Type': 'application/x-www-form-urlencoded'
53 }, data
=urlencode_postdata({
57 except ExtractorError
as e
:
58 self
._handle
_error
(e
, 400)
60 self
._request
_webpage
(target_url
, None, 'Following Target URL')
62 def _real_extract(self
, url
):
63 display_id
, video_id
= self
._match
_valid
_url
(url
).groups()
66 episode
= self
._download
_json
(
67 self
._API
_BASE
+ 'client/v1/player/episode/' + video_id
, video_id
)
68 except ExtractorError
as e
:
69 self
._handle
_error
(e
, 403)
71 title
= episode
['titulo']
75 for source
in episode
.get('sources', []):
76 src
= source
.get('src')
79 src_type
= source
.get('type')
80 if src_type
== 'application/vnd.apple.mpegurl':
81 formats
, subtitles
= self
._extract
_m
3u8_formats
(
82 src
, video_id
, 'mp4', 'm3u8_native',
83 m3u8_id
='hls', fatal
=False)
84 elif src_type
== 'application/dash+xml':
85 formats
, subtitles
= self
._extract
_mpd
_formats
(
86 src
, video_id
, mpd_id
='dash', fatal
=False)
88 heartbeat
= episode
.get('heartbeat') or {}
89 omniture
= episode
.get('omniture') or {}
90 get_meta
= lambda x
: heartbeat
.get(x
) or omniture
.get(x
)
93 'display_id': display_id
,
96 'description': episode
.get('descripcion'),
97 'thumbnail': episode
.get('imgPoster'),
98 'duration': int_or_none(episode
.get('duration')),
100 'channel': get_meta('channel'),
101 'season': get_meta('season'),
102 'episode_number': int_or_none(get_meta('episodeNumber')),
103 'subtitles': subtitles
,