]>
Commit | Line | Data |
---|---|---|
6b597516 | 1 | from .common import InfoExtractor |
6d394a66 | 2 | from ..compat import compat_HTTPError |
c8dfe360 | 3 | from ..utils import ( |
6e6bc8da | 4 | ExtractorError, |
6e6bc8da | 5 | int_or_none, |
6e6bc8da | 6 | urlencode_postdata, |
a3498732 S |
7 | ) |
8 | ||
9 | ||
6b597516 | 10 | class AtresPlayerIE(InfoExtractor): |
6d394a66 | 11 | _VALID_URL = r'https?://(?:www\.)?atresplayer\.com/[^/]+/[^/]+/[^/]+/[^/]+/(?P<display_id>.+?)_(?P<id>[0-9a-f]{24})' |
499bfcbf | 12 | _NETRC_MACHINE = 'atresplayer' |
a3498732 S |
13 | _TESTS = [ |
14 | { | |
6d394a66 | 15 | 'url': 'https://www.atresplayer.com/antena3/series/pequenas-coincidencias/temporada-1/capitulo-7-asuntos-pendientes_5d4aa2c57ed1a88fc715a615/', |
a3498732 | 16 | 'info_dict': { |
6d394a66 | 17 | 'id': '5d4aa2c57ed1a88fc715a615', |
a3498732 | 18 | 'ext': 'mp4', |
6d394a66 RA |
19 | 'title': 'Capítulo 7: Asuntos pendientes', |
20 | 'description': 'md5:7634cdcb4d50d5381bedf93efb537fbc', | |
21 | 'duration': 3413, | |
22 | }, | |
61ebb401 | 23 | 'skip': 'This video is only available for registered users' |
24 | }, | |
25 | { | |
6d394a66 RA |
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, | |
a3498732 S |
28 | }, |
29 | { | |
6d394a66 | 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/', |
a3498732 S |
31 | 'only_matching': True, |
32 | }, | |
33 | ] | |
6d394a66 | 34 | _API_BASE = 'https://api.atresplayer.com/' |
61ebb401 | 35 | |
6d394a66 RA |
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 | ||
52efa4b3 | 44 | def _perform_login(self, username, password): |
6d394a66 RA |
45 | self._request_webpage( |
46 | self._API_BASE + 'login', None, 'Downloading login page') | |
c8dfe360 | 47 | |
6d394a66 RA |
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) | |
c8dfe360 | 59 | |
6d394a66 | 60 | self._request_webpage(target_url, None, 'Following Target URL') |
c8dfe360 | 61 | |
a3498732 | 62 | def _real_extract(self, url): |
5ad28e7f | 63 | display_id, video_id = self._match_valid_url(url).groups() |
a3498732 | 64 | |
6d394a66 RA |
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) | |
a3498732 | 70 | |
6d394a66 | 71 | title = episode['titulo'] |
61ebb401 | 72 | |
73 | formats = [] | |
c811e8d8 | 74 | subtitles = {} |
6d394a66 RA |
75 | for source in episode.get('sources', []): |
76 | src = source.get('src') | |
77 | if not src: | |
61ebb401 | 78 | continue |
6d394a66 RA |
79 | src_type = source.get('type') |
80 | if src_type == 'application/vnd.apple.mpegurl': | |
c811e8d8 | 81 | formats, subtitles = self._extract_m3u8_formats( |
6d394a66 | 82 | src, video_id, 'mp4', 'm3u8_native', |
c811e8d8 | 83 | m3u8_id='hls', fatal=False) |
6d394a66 | 84 | elif src_type == 'application/dash+xml': |
c811e8d8 F |
85 | formats, subtitles = self._extract_mpd_formats( |
86 | src, video_id, mpd_id='dash', fatal=False) | |
a3498732 | 87 | |
6d394a66 RA |
88 | heartbeat = episode.get('heartbeat') or {} |
89 | omniture = episode.get('omniture') or {} | |
90 | get_meta = lambda x: heartbeat.get(x) or omniture.get(x) | |
0c172788 | 91 | |
a3498732 | 92 | return { |
6d394a66 | 93 | 'display_id': display_id, |
a3498732 S |
94 | 'id': video_id, |
95 | 'title': title, | |
6d394a66 RA |
96 | 'description': episode.get('descripcion'), |
97 | 'thumbnail': episode.get('imgPoster'), | |
98 | 'duration': int_or_none(episode.get('duration')), | |
a3498732 | 99 | 'formats': formats, |
6d394a66 RA |
100 | 'channel': get_meta('channel'), |
101 | 'season': get_meta('season'), | |
102 | 'episode_number': int_or_none(get_meta('episodeNumber')), | |
c811e8d8 | 103 | 'subtitles': subtitles, |
a3498732 | 104 | } |