1 from __future__ import unicode_literals
6 from .common import InfoExtractor
17 class AtresPlayerIE(InfoExtractor):
18 _VALID_URL = r'https?://(?:www\.)?atresplayer\.com/television/[^/]+/[^/]+/[^/]+/(?P<id>.+?)_\d+\.html'
21 'url': 'http://www.atresplayer.com/television/programas/el-club-de-la-comedia/temporada-4/capitulo-10-especial-solidario-nochebuena_2014122100174.html',
22 'md5': 'efd56753cda1bb64df52a3074f62e38a',
24 'id': 'capitulo-10-especial-solidario-nochebuena',
26 'title': 'Especial Solidario de Nochebuena',
27 'description': 'md5:e2d52ff12214fa937107d21064075bf1',
29 'thumbnail': 're:^https?://.*\.jpg$',
33 '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',
34 'only_matching': True,
38 _USER_AGENT = 'Dalvik/1.6.0 (Linux; U; Android 4.3; GT-I9300 Build/JSS15J'
39 _MAGIC = 'QWtMLXs414Yo+c#_+Q#K@NN)'
40 _TIMESTAMP_SHIFT = 30000
42 _TIME_API_URL = 'http://servicios.atresplayer.com/api/admin/time.json'
43 _URL_VIDEO_TEMPLATE = 'https://servicios.atresplayer.com/api/urlVideo/{1}/{0}/{1}|{2}|{3}.json'
44 _PLAYER_URL_TEMPLATE = 'https://servicios.atresplayer.com/episode/getplayer.json?episodePk=%s'
45 _EPISODE_URL_TEMPLATE = 'http://www.atresplayer.com/episodexml/%s'
47 def _real_extract(self, url):
48 video_id = self._match_id(url)
50 webpage = self._download_webpage(url, video_id)
52 episode_id = self._search_regex(
53 r'episode="([^"]+)"', webpage, 'episode id')
55 timestamp = int_or_none(self._download_webpage(
57 video_id, 'Downloading timestamp', fatal=False), 1000, time.time())
58 timestamp_shifted = compat_str(timestamp + self._TIMESTAMP_SHIFT)
59 token = hmac.new(self._MAGIC.encode('utf-8'), episode_id + timestamp_shifted).hexdigest()
62 for fmt in ['windows', 'android_tablet']:
63 request = compat_urllib_request.Request(
64 self._URL_VIDEO_TEMPLATE.format(fmt, episode_id, timestamp_shifted, token))
65 request.add_header('Youtubedl-user-agent', self._USER_AGENT)
67 fmt_json = self._download_json(
68 request, video_id, 'Downloading %s video JSON' % fmt)
70 result = fmt_json.get('resultDes')
71 if result.lower() != 'ok':
73 '%s returned error: %s' % (self.IE_NAME, result), expected=True)
75 for _, video_url in fmt_json['resultObject'].items():
76 if video_url.endswith('/Manifest'):
77 formats.extend(self._extract_f4m_formats(video_url[:-9] + '/manifest.f4m', video_id))
81 'format_id': 'android',
84 self._sort_formats(formats)
86 player = self._download_json(
87 self._PLAYER_URL_TEMPLATE % episode_id,
90 path_data = player.get('pathData')
92 episode = self._download_xml(
93 self._EPISODE_URL_TEMPLATE % path_data,
94 video_id, 'Downloading episode XML')
96 duration = float_or_none(xpath_text(
97 episode, './media/asset/info/technical/contentDuration', 'duration'))
99 art = episode.find('./media/asset/info/art')
100 title = xpath_text(art, './name', 'title')
101 description = xpath_text(art, './description', 'description')
102 thumbnail = xpath_text(episode, './media/asset/files/background', 'thumbnail')
107 'description': description,
108 'thumbnail': thumbnail,
109 'duration': duration,