1 from __future__
import unicode_literals
8 from .common
import InfoExtractor
22 class AtresPlayerIE(InfoExtractor
):
23 _VALID_URL
= r
'https?://(?:www\.)?atresplayer\.com/television/[^/]+/[^/]+/[^/]+/(?P<id>.+?)_\d+\.html'
24 _NETRC_MACHINE
= 'atresplayer'
27 'url': 'http://www.atresplayer.com/television/programas/el-club-de-la-comedia/temporada-4/capitulo-10-especial-solidario-nochebuena_2014122100174.html',
28 'md5': 'efd56753cda1bb64df52a3074f62e38a',
30 'id': 'capitulo-10-especial-solidario-nochebuena',
32 'title': 'Especial Solidario de Nochebuena',
33 'description': 'md5:e2d52ff12214fa937107d21064075bf1',
35 'thumbnail': 're:^https?://.*\.jpg$',
37 'skip': 'This video is only available for registered users'
40 'url': 'http://www.atresplayer.com/television/especial/videoencuentros/temporada-1/capitulo-112-david-bustamante_2014121600375.html',
41 'md5': '0d0e918533bbd4b263f2de4d197d4aac',
43 'id': 'capitulo-112-david-bustamante',
45 'title': 'David Bustamante',
46 'description': 'md5:f33f1c0a05be57f6708d4dd83a3b81c6',
48 'thumbnail': 're:^https?://.*\.jpg$',
52 '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',
53 'only_matching': True,
57 _USER_AGENT
= 'Dalvik/1.6.0 (Linux; U; Android 4.3; GT-I9300 Build/JSS15J'
58 _MAGIC
= 'QWtMLXs414Yo+c#_+Q#K@NN)'
59 _TIMESTAMP_SHIFT
= 30000
61 _TIME_API_URL
= 'http://servicios.atresplayer.com/api/admin/time.json'
62 _URL_VIDEO_TEMPLATE
= 'https://servicios.atresplayer.com/api/urlVideo/{1}/{0}/{1}|{2}|{3}.json'
63 _PLAYER_URL_TEMPLATE
= 'https://servicios.atresplayer.com/episode/getplayer.json?episodePk=%s'
64 _EPISODE_URL_TEMPLATE
= 'http://www.atresplayer.com/episodexml/%s'
66 _LOGIN_URL
= 'https://servicios.atresplayer.com/j_spring_security_check'
69 'UNPUBLISHED': 'We\'re sorry, but this video is not yet available.',
70 'DELETED': 'This video has expired and is no longer available for online streaming.',
71 'GEOUNPUBLISHED': 'We\'re sorry, but this video is not available in your region due to right restrictions.',
72 # 'PREMIUM': 'PREMIUM',
75 def _real_initialize(self
):
79 (username
, password
) = self
._get
_login
_info
()
84 'j_username': username
,
85 'j_password': password
,
88 request
= sanitized_Request(
89 self
._LOGIN
_URL
, compat_urllib_parse
.urlencode(login_form
).encode('utf-8'))
90 request
.add_header('Content-Type', 'application/x-www-form-urlencoded')
91 response
= self
._download
_webpage
(
92 request
, None, 'Logging in as %s' % username
)
94 error
= self
._html
_search
_regex
(
95 r
'(?s)<ul class="list_error">(.+?)</ul>', response
, 'error', default
=None)
98 'Unable to login: %s' % error
, expected
=True)
100 def _real_extract(self
, url
):
101 video_id
= self
._match
_id
(url
)
103 webpage
= self
._download
_webpage
(url
, video_id
)
105 episode_id
= self
._search
_regex
(
106 r
'episode="([^"]+)"', webpage
, 'episode id')
108 request
= sanitized_Request(
109 self
._PLAYER
_URL
_TEMPLATE
% episode_id
,
110 headers
={'User-Agent': self._USER_AGENT}
)
111 player
= self
._download
_json
(request
, episode_id
, 'Downloading player JSON')
113 episode_type
= player
.get('typeOfEpisode')
114 error_message
= self
._ERRORS
.get(episode_type
)
116 raise ExtractorError(
117 '%s returned error: %s' % (self
.IE_NAME
, error_message
), expected
=True)
120 video_url
= player
.get('urlVideo')
126 mobj
= re
.search(r
'(?P<bitrate>\d+)K_(?P<width>\d+)x(?P<height>\d+)', video_url
)
129 'width': int_or_none(mobj
.group('width')),
130 'height': int_or_none(mobj
.group('height')),
131 'tbr': int_or_none(mobj
.group('bitrate')),
133 formats
.append(format_info
)
135 m3u8_url
= player
.get('urlVideoHls')
137 m3u8_formats
= self
._extract
_m
3u8_formats
(
138 m3u8_url
, episode_id
, 'mp4', 'm3u8_native', m3u8_id
='hls', fatal
=False)
140 formats
.extend(m3u8_formats
)
142 timestamp
= int_or_none(self
._download
_webpage
(
144 video_id
, 'Downloading timestamp', fatal
=False), 1000, time
.time())
145 timestamp_shifted
= compat_str(timestamp
+ self
._TIMESTAMP
_SHIFT
)
147 self
._MAGIC
.encode('ascii'),
148 (episode_id
+ timestamp_shifted
).encode('utf-8'), hashlib
.md5
151 request
= sanitized_Request(
152 self
._URL
_VIDEO
_TEMPLATE
.format('windows', episode_id
, timestamp_shifted
, token
),
153 headers
={'User-Agent': self._USER_AGENT}
)
155 fmt_json
= self
._download
_json
(
156 request
, video_id
, 'Downloading windows video JSON')
158 result
= fmt_json
.get('resultDes')
159 if result
.lower() != 'ok':
160 raise ExtractorError(
161 '%s returned error: %s' % (self
.IE_NAME
, result
), expected
=True)
163 for format_id
, video_url
in fmt_json
['resultObject'].items():
164 if format_id
== 'token' or not video_url
.startswith('http'):
166 if 'geodeswowsmpra3player' in video_url
:
167 f4m_path
= video_url
.split('smil:', 1)[-1].split('free_', 1)[0]
168 f4m_url
= 'http://drg.antena3.com/{0}hds/es/sd.f4m'.format(f4m_path
)
169 # this videos are protected by DRM, the f4m downloader doesn't support them
172 f4m_url
= video_url
[:-9] + '/manifest.f4m'
173 f4m_formats
= self
._extract
_f
4m
_formats
(f4m_url
, video_id
, f4m_id
='hds', fatal
=False)
175 formats
.extend(f4m_formats
)
176 self
._sort
_formats
(formats
)
178 path_data
= player
.get('pathData')
180 episode
= self
._download
_xml
(
181 self
._EPISODE
_URL
_TEMPLATE
% path_data
, video_id
,
182 'Downloading episode XML')
184 duration
= float_or_none(xpath_text(
185 episode
, './media/asset/info/technical/contentDuration', 'duration'))
187 art
= episode
.find('./media/asset/info/art')
188 title
= xpath_text(art
, './name', 'title')
189 description
= xpath_text(art
, './description', 'description')
190 thumbnail
= xpath_text(episode
, './media/asset/files/background', 'thumbnail')
193 subtitle_url
= xpath_text(episode
, './media/asset/files/subtitle', 'subtitle')
203 'description': description
,
204 'thumbnail': thumbnail
,
205 'duration': duration
,
207 'subtitles': subtitles
,