]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..compat import compat_HTTPError | |
3 | from ..utils import ( | |
4 | ExtractorError, | |
5 | int_or_none, | |
6 | urlencode_postdata, | |
7 | ) | |
8 | ||
9 | ||
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' | |
13 | _TESTS = [ | |
14 | { | |
15 | 'url': 'https://www.atresplayer.com/antena3/series/pequenas-coincidencias/temporada-1/capitulo-7-asuntos-pendientes_5d4aa2c57ed1a88fc715a615/', | |
16 | 'info_dict': { | |
17 | 'id': '5d4aa2c57ed1a88fc715a615', | |
18 | 'ext': 'mp4', | |
19 | 'title': 'CapĂtulo 7: Asuntos pendientes', | |
20 | 'description': 'md5:7634cdcb4d50d5381bedf93efb537fbc', | |
21 | 'duration': 3413, | |
22 | }, | |
23 | 'skip': 'This video is only available for registered users' | |
24 | }, | |
25 | { | |
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, | |
28 | }, | |
29 | { | |
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, | |
32 | }, | |
33 | ] | |
34 | _API_BASE = 'https://api.atresplayer.com/' | |
35 | ||
36 | def _handle_error(self, e, code): | |
37 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == code: | |
38 | error = self._parse_json(e.cause.read(), None) | |
39 | if error.get('error') == 'required_registered': | |
40 | self.raise_login_required() | |
41 | raise ExtractorError(error['error_description'], expected=True) | |
42 | raise | |
43 | ||
44 | def _perform_login(self, username, password): | |
45 | self._request_webpage( | |
46 | self._API_BASE + 'login', None, 'Downloading login page') | |
47 | ||
48 | try: | |
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({ | |
54 | 'username': username, | |
55 | 'password': password, | |
56 | }))['targetUrl'] | |
57 | except ExtractorError as e: | |
58 | self._handle_error(e, 400) | |
59 | ||
60 | self._request_webpage(target_url, None, 'Following Target URL') | |
61 | ||
62 | def _real_extract(self, url): | |
63 | display_id, video_id = self._match_valid_url(url).groups() | |
64 | ||
65 | try: | |
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) | |
70 | ||
71 | title = episode['titulo'] | |
72 | ||
73 | formats = [] | |
74 | subtitles = {} | |
75 | for source in episode.get('sources', []): | |
76 | src = source.get('src') | |
77 | if not src: | |
78 | continue | |
79 | src_type = source.get('type') | |
80 | if src_type == 'application/vnd.apple.mpegurl': | |
81 | formats, subtitles = self._extract_m3u8_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) | |
87 | ||
88 | heartbeat = episode.get('heartbeat') or {} | |
89 | omniture = episode.get('omniture') or {} | |
90 | get_meta = lambda x: heartbeat.get(x) or omniture.get(x) | |
91 | ||
92 | return { | |
93 | 'display_id': display_id, | |
94 | 'id': video_id, | |
95 | 'title': title, | |
96 | 'description': episode.get('descripcion'), | |
97 | 'thumbnail': episode.get('imgPoster'), | |
98 | 'duration': int_or_none(episode.get('duration')), | |
99 | 'formats': formats, | |
100 | 'channel': get_meta('channel'), | |
101 | 'season': get_meta('season'), | |
102 | 'episode_number': int_or_none(get_meta('episodeNumber')), | |
103 | 'subtitles': subtitles, | |
104 | } |