]>
Commit | Line | Data |
---|---|---|
a3498732 S |
1 | from __future__ import unicode_literals |
2 | ||
3 | import time | |
4 | import hmac | |
61ebb401 | 5 | import hashlib |
6 | import re | |
a3498732 | 7 | |
6b597516 | 8 | from .common import InfoExtractor |
6e6bc8da | 9 | from ..compat import compat_str |
c8dfe360 | 10 | from ..utils import ( |
6e6bc8da | 11 | ExtractorError, |
a3498732 | 12 | float_or_none, |
6e6bc8da | 13 | int_or_none, |
5c2266df | 14 | sanitized_Request, |
6e6bc8da | 15 | urlencode_postdata, |
a3498732 | 16 | xpath_text, |
a3498732 S |
17 | ) |
18 | ||
19 | ||
6b597516 | 20 | class AtresPlayerIE(InfoExtractor): |
a3498732 | 21 | _VALID_URL = r'https?://(?:www\.)?atresplayer\.com/television/[^/]+/[^/]+/[^/]+/(?P<id>.+?)_\d+\.html' |
499bfcbf | 22 | _NETRC_MACHINE = 'atresplayer' |
a3498732 S |
23 | _TESTS = [ |
24 | { | |
25 | 'url': 'http://www.atresplayer.com/television/programas/el-club-de-la-comedia/temporada-4/capitulo-10-especial-solidario-nochebuena_2014122100174.html', | |
26 | 'md5': 'efd56753cda1bb64df52a3074f62e38a', | |
27 | 'info_dict': { | |
28 | 'id': 'capitulo-10-especial-solidario-nochebuena', | |
29 | 'ext': 'mp4', | |
30 | 'title': 'Especial Solidario de Nochebuena', | |
31 | 'description': 'md5:e2d52ff12214fa937107d21064075bf1', | |
32 | 'duration': 5527.6, | |
ec85ded8 | 33 | 'thumbnail': r're:^https?://.*\.jpg$', |
a3498732 | 34 | }, |
61ebb401 | 35 | 'skip': 'This video is only available for registered users' |
36 | }, | |
37 | { | |
38 | 'url': 'http://www.atresplayer.com/television/especial/videoencuentros/temporada-1/capitulo-112-david-bustamante_2014121600375.html', | |
a1577749 | 39 | 'md5': '6e52cbb513c405e403dbacb7aacf8747', |
61ebb401 | 40 | 'info_dict': { |
41 | 'id': 'capitulo-112-david-bustamante', | |
42 | 'ext': 'flv', | |
43 | 'title': 'David Bustamante', | |
44 | 'description': 'md5:f33f1c0a05be57f6708d4dd83a3b81c6', | |
45 | 'duration': 1439.0, | |
ec85ded8 | 46 | 'thumbnail': r're:^https?://.*\.jpg$', |
61ebb401 | 47 | }, |
a3498732 S |
48 | }, |
49 | { | |
50 | 'url': 'http://www.atresplayer.com/television/series/el-secreto-de-puente-viejo/el-chico-de-los-tres-lunares/capitulo-977-29-12-14_2014122400174.html', | |
51 | 'only_matching': True, | |
52 | }, | |
53 | ] | |
54 | ||
55 | _USER_AGENT = 'Dalvik/1.6.0 (Linux; U; Android 4.3; GT-I9300 Build/JSS15J' | |
56 | _MAGIC = 'QWtMLXs414Yo+c#_+Q#K@NN)' | |
57 | _TIMESTAMP_SHIFT = 30000 | |
58 | ||
59 | _TIME_API_URL = 'http://servicios.atresplayer.com/api/admin/time.json' | |
60 | _URL_VIDEO_TEMPLATE = 'https://servicios.atresplayer.com/api/urlVideo/{1}/{0}/{1}|{2}|{3}.json' | |
61 | _PLAYER_URL_TEMPLATE = 'https://servicios.atresplayer.com/episode/getplayer.json?episodePk=%s' | |
62 | _EPISODE_URL_TEMPLATE = 'http://www.atresplayer.com/episodexml/%s' | |
63 | ||
c8dfe360 S |
64 | _LOGIN_URL = 'https://servicios.atresplayer.com/j_spring_security_check' |
65 | ||
61ebb401 | 66 | _ERRORS = { |
67 | 'UNPUBLISHED': 'We\'re sorry, but this video is not yet available.', | |
68 | 'DELETED': 'This video has expired and is no longer available for online streaming.', | |
69 | 'GEOUNPUBLISHED': 'We\'re sorry, but this video is not available in your region due to right restrictions.', | |
70 | # 'PREMIUM': 'PREMIUM', | |
71 | } | |
72 | ||
c8dfe360 S |
73 | def _real_initialize(self): |
74 | self._login() | |
75 | ||
76 | def _login(self): | |
68217024 | 77 | username, password = self._get_login_info() |
c8dfe360 S |
78 | if username is None: |
79 | return | |
80 | ||
81 | login_form = { | |
82 | 'j_username': username, | |
83 | 'j_password': password, | |
84 | } | |
85 | ||
5c2266df | 86 | request = sanitized_Request( |
6e6bc8da | 87 | self._LOGIN_URL, urlencode_postdata(login_form)) |
c8dfe360 S |
88 | request.add_header('Content-Type', 'application/x-www-form-urlencoded') |
89 | response = self._download_webpage( | |
e4d95865 | 90 | request, None, 'Logging in') |
c8dfe360 S |
91 | |
92 | error = self._html_search_regex( | |
1088d76d | 93 | r'(?s)<ul[^>]+class="[^"]*\blist_error\b[^"]*">(.+?)</ul>', |
94 | response, 'error', default=None) | |
c8dfe360 S |
95 | if error: |
96 | raise ExtractorError( | |
97 | 'Unable to login: %s' % error, expected=True) | |
98 | ||
a3498732 S |
99 | def _real_extract(self, url): |
100 | video_id = self._match_id(url) | |
101 | ||
102 | webpage = self._download_webpage(url, video_id) | |
103 | ||
104 | episode_id = self._search_regex( | |
105 | r'episode="([^"]+)"', webpage, 'episode id') | |
106 | ||
61ebb401 | 107 | request = sanitized_Request( |
108 | self._PLAYER_URL_TEMPLATE % episode_id, | |
109 | headers={'User-Agent': self._USER_AGENT}) | |
110 | player = self._download_json(request, episode_id, 'Downloading player JSON') | |
111 | ||
112 | episode_type = player.get('typeOfEpisode') | |
113 | error_message = self._ERRORS.get(episode_type) | |
114 | if error_message: | |
115 | raise ExtractorError( | |
116 | '%s returned error: %s' % (self.IE_NAME, error_message), expected=True) | |
117 | ||
118 | formats = [] | |
119 | video_url = player.get('urlVideo') | |
120 | if video_url: | |
121 | format_info = { | |
122 | 'url': video_url, | |
123 | 'format_id': 'http', | |
124 | } | |
125 | mobj = re.search(r'(?P<bitrate>\d+)K_(?P<width>\d+)x(?P<height>\d+)', video_url) | |
126 | if mobj: | |
127 | format_info.update({ | |
128 | 'width': int_or_none(mobj.group('width')), | |
129 | 'height': int_or_none(mobj.group('height')), | |
130 | 'tbr': int_or_none(mobj.group('bitrate')), | |
131 | }) | |
132 | formats.append(format_info) | |
133 | ||
a3498732 S |
134 | timestamp = int_or_none(self._download_webpage( |
135 | self._TIME_API_URL, | |
136 | video_id, 'Downloading timestamp', fatal=False), 1000, time.time()) | |
137 | timestamp_shifted = compat_str(timestamp + self._TIMESTAMP_SHIFT) | |
e83eebb1 S |
138 | token = hmac.new( |
139 | self._MAGIC.encode('ascii'), | |
61ebb401 | 140 | (episode_id + timestamp_shifted).encode('utf-8'), hashlib.md5 |
e83eebb1 | 141 | ).hexdigest() |
a3498732 | 142 | |
61ebb401 | 143 | request = sanitized_Request( |
144 | self._URL_VIDEO_TEMPLATE.format('windows', episode_id, timestamp_shifted, token), | |
145 | headers={'User-Agent': self._USER_AGENT}) | |
a3498732 | 146 | |
61ebb401 | 147 | fmt_json = self._download_json( |
148 | request, video_id, 'Downloading windows video JSON') | |
149 | ||
150 | result = fmt_json.get('resultDes') | |
151 | if result.lower() != 'ok': | |
152 | raise ExtractorError( | |
153 | '%s returned error: %s' % (self.IE_NAME, result), expected=True) | |
154 | ||
155 | for format_id, video_url in fmt_json['resultObject'].items(): | |
156 | if format_id == 'token' or not video_url.startswith('http'): | |
157 | continue | |
158 | if 'geodeswowsmpra3player' in video_url: | |
5b7cc56b S |
159 | # f4m_path = video_url.split('smil:', 1)[-1].split('free_', 1)[0] |
160 | # f4m_url = 'http://drg.antena3.com/{0}hds/es/sd.f4m'.format(f4m_path) | |
61ebb401 | 161 | # this videos are protected by DRM, the f4m downloader doesn't support them |
162 | continue | |
c7301e67 S |
163 | video_url_hd = video_url.replace('free_es', 'es') |
164 | formats.extend(self._extract_f4m_formats( | |
165 | video_url_hd[:-9] + '/manifest.f4m', video_id, f4m_id='hds', | |
166 | fatal=False)) | |
167 | formats.extend(self._extract_mpd_formats( | |
168 | video_url_hd[:-9] + '/manifest.mpd', video_id, mpd_id='dash', | |
169 | fatal=False)) | |
61ebb401 | 170 | self._sort_formats(formats) |
a3498732 S |
171 | |
172 | path_data = player.get('pathData') | |
173 | ||
174 | episode = self._download_xml( | |
61ebb401 | 175 | self._EPISODE_URL_TEMPLATE % path_data, video_id, |
176 | 'Downloading episode XML') | |
a3498732 S |
177 | |
178 | duration = float_or_none(xpath_text( | |
179 | episode, './media/asset/info/technical/contentDuration', 'duration')) | |
180 | ||
181 | art = episode.find('./media/asset/info/art') | |
182 | title = xpath_text(art, './name', 'title') | |
183 | description = xpath_text(art, './description', 'description') | |
184 | thumbnail = xpath_text(episode, './media/asset/files/background', 'thumbnail') | |
185 | ||
0c172788 | 186 | subtitles = {} |
6b597516 JMF |
187 | subtitle_url = xpath_text(episode, './media/asset/files/subtitle', 'subtitle') |
188 | if subtitle_url: | |
189 | subtitles['es'] = [{ | |
190 | 'ext': 'srt', | |
191 | 'url': subtitle_url, | |
192 | }] | |
0c172788 | 193 | |
a3498732 S |
194 | return { |
195 | 'id': video_id, | |
196 | 'title': title, | |
197 | 'description': description, | |
198 | 'thumbnail': thumbnail, | |
199 | 'duration': duration, | |
200 | 'formats': formats, | |
6b597516 | 201 | 'subtitles': subtitles, |
a3498732 | 202 | } |