X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Fextractor%2Fatresplayer.py;h=50e47ba0ae033dac996a28a216e0574174239781;hb=5c2266df4b9aeb7881ed8c026a038e2a25e43734;hp=72e83bfc2c1b4fa45080538e4c87339a7a8c530a;hpb=bc694039e47cc871c98abacdf1c0a2e5a257a8a4;p=youtube-dl diff --git a/youtube_dl/extractor/atresplayer.py b/youtube_dl/extractor/atresplayer.py index 72e83bfc2..50e47ba0a 100644 --- a/youtube_dl/extractor/atresplayer.py +++ b/youtube_dl/extractor/atresplayer.py @@ -4,11 +4,14 @@ import time import hmac from .common import InfoExtractor -from ..utils import ( +from ..compat import ( compat_str, - compat_urllib_request, + compat_urllib_parse, +) +from ..utils import ( int_or_none, float_or_none, + sanitized_Request, xpath_text, ExtractorError, ) @@ -16,6 +19,7 @@ from ..utils import ( class AtresPlayerIE(InfoExtractor): _VALID_URL = r'https?://(?:www\.)?atresplayer\.com/television/[^/]+/[^/]+/[^/]+/(?P.+?)_\d+\.html' + _NETRC_MACHINE = 'atresplayer' _TESTS = [ { 'url': 'http://www.atresplayer.com/television/programas/el-club-de-la-comedia/temporada-4/capitulo-10-especial-solidario-nochebuena_2014122100174.html', @@ -44,6 +48,33 @@ class AtresPlayerIE(InfoExtractor): _PLAYER_URL_TEMPLATE = 'https://servicios.atresplayer.com/episode/getplayer.json?episodePk=%s' _EPISODE_URL_TEMPLATE = 'http://www.atresplayer.com/episodexml/%s' + _LOGIN_URL = 'https://servicios.atresplayer.com/j_spring_security_check' + + def _real_initialize(self): + self._login() + + def _login(self): + (username, password) = self._get_login_info() + if username is None: + return + + login_form = { + 'j_username': username, + 'j_password': password, + } + + request = sanitized_Request( + self._LOGIN_URL, compat_urllib_parse.urlencode(login_form).encode('utf-8')) + request.add_header('Content-Type', 'application/x-www-form-urlencoded') + response = self._download_webpage( + request, None, 'Logging in as %s' % username) + + error = self._html_search_regex( + r'(?s)', response, 'error', default=None) + if error: + raise ExtractorError( + 'Unable to login: %s' % error, expected=True) + def _real_extract(self, url): video_id = self._match_id(url) @@ -63,9 +94,9 @@ class AtresPlayerIE(InfoExtractor): formats = [] for fmt in ['windows', 'android_tablet']: - request = compat_urllib_request.Request( + request = sanitized_Request( self._URL_VIDEO_TEMPLATE.format(fmt, episode_id, timestamp_shifted, token)) - request.add_header('Youtubedl-user-agent', self._USER_AGENT) + request.add_header('User-Agent', self._USER_AGENT) fmt_json = self._download_json( request, video_id, 'Downloading %s video JSON' % fmt) @@ -75,13 +106,22 @@ class AtresPlayerIE(InfoExtractor): raise ExtractorError( '%s returned error: %s' % (self.IE_NAME, result), expected=True) - for _, video_url in fmt_json['resultObject'].items(): + for format_id, video_url in fmt_json['resultObject'].items(): + if format_id == 'token' or not video_url.startswith('http'): + continue if video_url.endswith('/Manifest'): - formats.extend(self._extract_f4m_formats(video_url[:-9] + '/manifest.f4m', video_id)) + if 'geodeswowsmpra3player' in video_url: + f4m_path = video_url.split('smil:', 1)[-1].split('free_', 1)[0] + f4m_url = 'http://drg.antena3.com/{0}hds/es/sd.f4m'.format(f4m_path) + # this videos are protected by DRM, the f4m downloader doesn't support them + continue + else: + f4m_url = video_url[:-9] + '/manifest.f4m' + formats.extend(self._extract_f4m_formats(f4m_url, video_id)) else: formats.append({ 'url': video_url, - 'format_id': 'android', + 'format_id': 'android-%s' % format_id, 'preference': 1, }) self._sort_formats(formats) @@ -104,6 +144,14 @@ class AtresPlayerIE(InfoExtractor): description = xpath_text(art, './description', 'description') thumbnail = xpath_text(episode, './media/asset/files/background', 'thumbnail') + subtitles = {} + subtitle_url = xpath_text(episode, './media/asset/files/subtitle', 'subtitle') + if subtitle_url: + subtitles['es'] = [{ + 'ext': 'srt', + 'url': subtitle_url, + }] + return { 'id': video_id, 'title': title, @@ -111,4 +159,5 @@ class AtresPlayerIE(InfoExtractor): 'thumbnail': thumbnail, 'duration': duration, 'formats': formats, + 'subtitles': subtitles, }