1 from __future__ import unicode_literals
6 from .subtitles import SubtitlesInfoExtractor
10 compat_urllib_request,
20 class AtresPlayerIE(SubtitlesInfoExtractor):
21 _VALID_URL = r'https?://(?:www\.)?atresplayer\.com/television/[^/]+/[^/]+/[^/]+/(?P<id>.+?)_\d+\.html'
24 'url': 'http://www.atresplayer.com/television/programas/el-club-de-la-comedia/temporada-4/capitulo-10-especial-solidario-nochebuena_2014122100174.html',
25 'md5': 'efd56753cda1bb64df52a3074f62e38a',
27 'id': 'capitulo-10-especial-solidario-nochebuena',
29 'title': 'Especial Solidario de Nochebuena',
30 'description': 'md5:e2d52ff12214fa937107d21064075bf1',
32 'thumbnail': 're:^https?://.*\.jpg$',
36 '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',
37 'only_matching': True,
41 _USER_AGENT = 'Dalvik/1.6.0 (Linux; U; Android 4.3; GT-I9300 Build/JSS15J'
42 _MAGIC = 'QWtMLXs414Yo+c#_+Q#K@NN)'
43 _TIMESTAMP_SHIFT = 30000
45 _TIME_API_URL = 'http://servicios.atresplayer.com/api/admin/time.json'
46 _URL_VIDEO_TEMPLATE = 'https://servicios.atresplayer.com/api/urlVideo/{1}/{0}/{1}|{2}|{3}.json'
47 _PLAYER_URL_TEMPLATE = 'https://servicios.atresplayer.com/episode/getplayer.json?episodePk=%s'
48 _EPISODE_URL_TEMPLATE = 'http://www.atresplayer.com/episodexml/%s'
50 _LOGIN_URL = 'https://servicios.atresplayer.com/j_spring_security_check'
52 def _real_initialize(self):
56 (username, password) = self._get_login_info()
61 'j_username': username,
62 'j_password': password,
65 request = compat_urllib_request.Request(
66 self._LOGIN_URL, compat_urllib_parse.urlencode(login_form).encode('utf-8'))
67 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
68 response = self._download_webpage(
69 request, None, 'Logging in as %s' % username)
71 error = self._html_search_regex(
72 r'(?s)<ul class="list_error">(.+?)</ul>', response, 'error', default=None)
75 'Unable to login: %s' % error, expected=True)
77 def _real_extract(self, url):
78 video_id = self._match_id(url)
80 webpage = self._download_webpage(url, video_id)
82 episode_id = self._search_regex(
83 r'episode="([^"]+)"', webpage, 'episode id')
85 timestamp = int_or_none(self._download_webpage(
87 video_id, 'Downloading timestamp', fatal=False), 1000, time.time())
88 timestamp_shifted = compat_str(timestamp + self._TIMESTAMP_SHIFT)
90 self._MAGIC.encode('ascii'),
91 (episode_id + timestamp_shifted).encode('utf-8')
95 for fmt in ['windows', 'android_tablet']:
96 request = compat_urllib_request.Request(
97 self._URL_VIDEO_TEMPLATE.format(fmt, episode_id, timestamp_shifted, token))
98 request.add_header('User-Agent', self._USER_AGENT)
100 fmt_json = self._download_json(
101 request, video_id, 'Downloading %s video JSON' % fmt)
103 result = fmt_json.get('resultDes')
104 if result.lower() != 'ok':
105 raise ExtractorError(
106 '%s returned error: %s' % (self.IE_NAME, result), expected=True)
108 for format_id, video_url in fmt_json['resultObject'].items():
109 if format_id == 'token' or not video_url.startswith('http'):
111 if video_url.endswith('/Manifest'):
112 if 'geodeswowsmpra3player' in video_url:
113 f4m_path = video_url.split('smil:', 1)[-1].split('free_', 1)[0]
114 f4m_url = 'http://drg.antena3.com/{0}hds/es/sd.f4m'.format(f4m_path)
115 # this videos are protected by DRM, the f4m downloader doesn't support them
118 f4m_url = video_url[:-9] + '/manifest.f4m'
119 formats.extend(self._extract_f4m_formats(f4m_url, video_id))
123 'format_id': 'android-%s' % format_id,
126 self._sort_formats(formats)
128 player = self._download_json(
129 self._PLAYER_URL_TEMPLATE % episode_id,
132 path_data = player.get('pathData')
134 episode = self._download_xml(
135 self._EPISODE_URL_TEMPLATE % path_data,
136 video_id, 'Downloading episode XML')
138 duration = float_or_none(xpath_text(
139 episode, './media/asset/info/technical/contentDuration', 'duration'))
141 art = episode.find('./media/asset/info/art')
142 title = xpath_text(art, './name', 'title')
143 description = xpath_text(art, './description', 'description')
144 thumbnail = xpath_text(episode, './media/asset/files/background', 'thumbnail')
147 subtitle = xpath_text(episode, './media/asset/files/subtitle', 'subtitle')
149 subtitles['es'] = subtitle
151 if self._downloader.params.get('listsubtitles', False):
152 self._list_available_subtitles(video_id, subtitles)
158 'description': description,
159 'thumbnail': thumbnail,
160 'duration': duration,
162 'subtitles': self.extract_subtitles(video_id, subtitles),