1 from __future__ import unicode_literals
6 from .common import InfoExtractor
10 compat_urllib_request,
20 class AtresPlayerIE(InfoExtractor):
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('Youtubedl-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 _, video_url in fmt_json['resultObject'].items():
109 if video_url.endswith('/Manifest'):
110 formats.extend(self._extract_f4m_formats(video_url[:-9] + '/manifest.f4m', video_id))
114 'format_id': 'android',
117 self._sort_formats(formats)
119 player = self._download_json(
120 self._PLAYER_URL_TEMPLATE % episode_id,
123 path_data = player.get('pathData')
125 episode = self._download_xml(
126 self._EPISODE_URL_TEMPLATE % path_data,
127 video_id, 'Downloading episode XML')
129 duration = float_or_none(xpath_text(
130 episode, './media/asset/info/technical/contentDuration', 'duration'))
132 art = episode.find('./media/asset/info/art')
133 title = xpath_text(art, './name', 'title')
134 description = xpath_text(art, './description', 'description')
135 thumbnail = xpath_text(episode, './media/asset/files/background', 'thumbnail')
140 'description': description,
141 'thumbnail': thumbnail,
142 'duration': duration,