]>
Commit | Line | Data |
---|---|---|
00011575 | 1 | # coding: utf-8 |
a3498732 S |
2 | from __future__ import unicode_literals |
3 | ||
a3498732 | 4 | |
6b597516 | 5 | from .common import InfoExtractor |
6d394a66 | 6 | from ..compat import compat_HTTPError |
c8dfe360 | 7 | from ..utils import ( |
6e6bc8da | 8 | ExtractorError, |
6e6bc8da | 9 | int_or_none, |
6e6bc8da | 10 | urlencode_postdata, |
a3498732 S |
11 | ) |
12 | ||
13 | ||
6b597516 | 14 | class AtresPlayerIE(InfoExtractor): |
6d394a66 | 15 | _VALID_URL = r'https?://(?:www\.)?atresplayer\.com/[^/]+/[^/]+/[^/]+/[^/]+/(?P<display_id>.+?)_(?P<id>[0-9a-f]{24})' |
499bfcbf | 16 | _NETRC_MACHINE = 'atresplayer' |
a3498732 S |
17 | _TESTS = [ |
18 | { | |
6d394a66 | 19 | 'url': 'https://www.atresplayer.com/antena3/series/pequenas-coincidencias/temporada-1/capitulo-7-asuntos-pendientes_5d4aa2c57ed1a88fc715a615/', |
a3498732 | 20 | 'info_dict': { |
6d394a66 | 21 | 'id': '5d4aa2c57ed1a88fc715a615', |
a3498732 | 22 | 'ext': 'mp4', |
6d394a66 RA |
23 | 'title': 'Capítulo 7: Asuntos pendientes', |
24 | 'description': 'md5:7634cdcb4d50d5381bedf93efb537fbc', | |
25 | 'duration': 3413, | |
26 | }, | |
61ebb401 | 27 | 'skip': 'This video is only available for registered users' |
28 | }, | |
29 | { | |
6d394a66 RA |
30 | 'url': 'https://www.atresplayer.com/lasexta/programas/el-club-de-la-comedia/temporada-4/capitulo-10-especial-solidario-nochebuena_5ad08edf986b2855ed47adc4/', |
31 | 'only_matching': True, | |
a3498732 S |
32 | }, |
33 | { | |
6d394a66 | 34 | 'url': 'https://www.atresplayer.com/antena3/series/el-secreto-de-puente-viejo/el-chico-de-los-tres-lunares/capitulo-977-29-12-14_5ad51046986b2886722ccdea/', |
a3498732 S |
35 | 'only_matching': True, |
36 | }, | |
37 | ] | |
6d394a66 | 38 | _API_BASE = 'https://api.atresplayer.com/' |
61ebb401 | 39 | |
c8dfe360 S |
40 | def _real_initialize(self): |
41 | self._login() | |
42 | ||
6d394a66 RA |
43 | def _handle_error(self, e, code): |
44 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == code: | |
45 | error = self._parse_json(e.cause.read(), None) | |
46 | if error.get('error') == 'required_registered': | |
47 | self.raise_login_required() | |
48 | raise ExtractorError(error['error_description'], expected=True) | |
49 | raise | |
50 | ||
c8dfe360 | 51 | def _login(self): |
68217024 | 52 | username, password = self._get_login_info() |
c8dfe360 S |
53 | if username is None: |
54 | return | |
55 | ||
6d394a66 RA |
56 | self._request_webpage( |
57 | self._API_BASE + 'login', None, 'Downloading login page') | |
c8dfe360 | 58 | |
6d394a66 RA |
59 | try: |
60 | target_url = self._download_json( | |
61 | 'https://account.atresmedia.com/api/login', None, | |
62 | 'Logging in', headers={ | |
63 | 'Content-Type': 'application/x-www-form-urlencoded' | |
64 | }, data=urlencode_postdata({ | |
65 | 'username': username, | |
66 | 'password': password, | |
67 | }))['targetUrl'] | |
68 | except ExtractorError as e: | |
69 | self._handle_error(e, 400) | |
c8dfe360 | 70 | |
6d394a66 | 71 | self._request_webpage(target_url, None, 'Following Target URL') |
c8dfe360 | 72 | |
a3498732 | 73 | def _real_extract(self, url): |
5ad28e7f | 74 | display_id, video_id = self._match_valid_url(url).groups() |
a3498732 | 75 | |
6d394a66 RA |
76 | try: |
77 | episode = self._download_json( | |
78 | self._API_BASE + 'client/v1/player/episode/' + video_id, video_id) | |
79 | except ExtractorError as e: | |
80 | self._handle_error(e, 403) | |
a3498732 | 81 | |
6d394a66 | 82 | title = episode['titulo'] |
61ebb401 | 83 | |
84 | formats = [] | |
c811e8d8 | 85 | subtitles = {} |
6d394a66 RA |
86 | for source in episode.get('sources', []): |
87 | src = source.get('src') | |
88 | if not src: | |
61ebb401 | 89 | continue |
6d394a66 RA |
90 | src_type = source.get('type') |
91 | if src_type == 'application/vnd.apple.mpegurl': | |
c811e8d8 | 92 | formats, subtitles = self._extract_m3u8_formats( |
6d394a66 | 93 | src, video_id, 'mp4', 'm3u8_native', |
c811e8d8 | 94 | m3u8_id='hls', fatal=False) |
6d394a66 | 95 | elif src_type == 'application/dash+xml': |
c811e8d8 F |
96 | formats, subtitles = self._extract_mpd_formats( |
97 | src, video_id, mpd_id='dash', fatal=False) | |
61ebb401 | 98 | self._sort_formats(formats) |
a3498732 | 99 | |
6d394a66 RA |
100 | heartbeat = episode.get('heartbeat') or {} |
101 | omniture = episode.get('omniture') or {} | |
102 | get_meta = lambda x: heartbeat.get(x) or omniture.get(x) | |
0c172788 | 103 | |
a3498732 | 104 | return { |
6d394a66 | 105 | 'display_id': display_id, |
a3498732 S |
106 | 'id': video_id, |
107 | 'title': title, | |
6d394a66 RA |
108 | 'description': episode.get('descripcion'), |
109 | 'thumbnail': episode.get('imgPoster'), | |
110 | 'duration': int_or_none(episode.get('duration')), | |
a3498732 | 111 | 'formats': formats, |
6d394a66 RA |
112 | 'channel': get_meta('channel'), |
113 | 'season': get_meta('season'), | |
114 | 'episode_number': int_or_none(get_meta('episodeNumber')), | |
c811e8d8 | 115 | 'subtitles': subtitles, |
a3498732 | 116 | } |