]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/atresplayer.py
1 from __future__
import unicode_literals
8 from .common
import InfoExtractor
9 from ..compat
import compat_str
20 class AtresPlayerIE(InfoExtractor
):
21 _VALID_URL
= r
'https?://(?:www\.)?atresplayer\.com/television/[^/]+/[^/]+/[^/]+/(?P<id>.+?)_\d+\.html'
22 _NETRC_MACHINE
= 'atresplayer'
25 'url': 'http://www.atresplayer.com/television/programas/el-club-de-la-comedia/temporada-4/capitulo-10-especial-solidario-nochebuena_2014122100174.html',
26 'md5': 'efd56753cda1bb64df52a3074f62e38a',
28 'id': 'capitulo-10-especial-solidario-nochebuena',
30 'title': 'Especial Solidario de Nochebuena',
31 'description': 'md5:e2d52ff12214fa937107d21064075bf1',
33 'thumbnail': r
're:^https?://.*\.jpg$',
35 'skip': 'This video is only available for registered users'
38 'url': 'http://www.atresplayer.com/television/especial/videoencuentros/temporada-1/capitulo-112-david-bustamante_2014121600375.html',
39 'md5': '6e52cbb513c405e403dbacb7aacf8747',
41 'id': 'capitulo-112-david-bustamante',
43 'title': 'David Bustamante',
44 'description': 'md5:f33f1c0a05be57f6708d4dd83a3b81c6',
46 'thumbnail': r
're:^https?://.*\.jpg$',
50 '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',
51 'only_matching': True,
55 _USER_AGENT
= 'Dalvik/1.6.0 (Linux; U; Android 4.3; GT-I9300 Build/JSS15J'
56 _MAGIC
= 'QWtMLXs414Yo+c#_+Q#K@NN)'
57 _TIMESTAMP_SHIFT
= 30000
59 _TIME_API_URL
= 'http://servicios.atresplayer.com/api/admin/time.json'
60 _URL_VIDEO_TEMPLATE
= 'https://servicios.atresplayer.com/api/urlVideo/{1}/{0}/{1}|{2}|{3}.json'
61 _PLAYER_URL_TEMPLATE
= 'https://servicios.atresplayer.com/episode/getplayer.json?episodePk=%s'
62 _EPISODE_URL_TEMPLATE
= 'http://www.atresplayer.com/episodexml/%s'
64 _LOGIN_URL
= 'https://servicios.atresplayer.com/j_spring_security_check'
67 'UNPUBLISHED': 'We\'re sorry, but this video is not yet available.',
68 'DELETED': 'This video has expired and is no longer available for online streaming.',
69 'GEOUNPUBLISHED': 'We\'re sorry, but this video is not available in your region due to right restrictions.',
70 # 'PREMIUM': 'PREMIUM',
73 def _real_initialize(self
):
77 username
, password
= self
._get
_login
_info
()
82 'j_username': username
,
83 'j_password': password
,
86 request
= sanitized_Request(
87 self
._LOGIN
_URL
, urlencode_postdata(login_form
))
88 request
.add_header('Content-Type', 'application/x-www-form-urlencoded')
89 response
= self
._download
_webpage
(
90 request
, None, 'Logging in')
92 error
= self
._html
_search
_regex
(
93 r
'(?s)<ul[^>]+class="[^"]*\blist_error\b[^"]*">(.+?)</ul>',
94 response
, 'error', default
=None)
97 'Unable to login: %s' % error
, expected
=True)
99 def _real_extract(self
, url
):
100 video_id
= self
._match
_id
(url
)
102 webpage
= self
._download
_webpage
(url
, video_id
)
104 episode_id
= self
._search
_regex
(
105 r
'episode="([^"]+)"', webpage
, 'episode id')
107 request
= sanitized_Request(
108 self
._PLAYER
_URL
_TEMPLATE
% episode_id
,
109 headers
={'User-Agent': self
._USER
_AGENT
})
110 player
= self
._download
_json
(request
, episode_id
, 'Downloading player JSON')
112 episode_type
= player
.get('typeOfEpisode')
113 error_message
= self
._ERRORS
.get(episode_type
)
115 raise ExtractorError(
116 '%s returned error: %s' % (self
.IE_NAME
, error_message
), expected
=True)
119 video_url
= player
.get('urlVideo')
125 mobj
= re
.search(r
'(?P<bitrate>\d+)K_(?P<width>\d+)x(?P<height>\d+)', video_url
)
128 'width': int_or_none(mobj
.group('width')),
129 'height': int_or_none(mobj
.group('height')),
130 'tbr': int_or_none(mobj
.group('bitrate')),
132 formats
.append(format_info
)
134 timestamp
= int_or_none(self
._download
_webpage
(
136 video_id
, 'Downloading timestamp', fatal
=False), 1000, time
.time())
137 timestamp_shifted
= compat_str(timestamp
+ self
._TIMESTAMP
_SHIFT
)
139 self
._MAGIC
.encode('ascii'),
140 (episode_id
+ timestamp_shifted
).encode('utf-8'), hashlib
.md5
143 request
= sanitized_Request(
144 self
._URL
_VIDEO
_TEMPLATE
.format('windows', episode_id
, timestamp_shifted
, token
),
145 headers
={'User-Agent': self
._USER
_AGENT
})
147 fmt_json
= self
._download
_json
(
148 request
, video_id
, 'Downloading windows video JSON')
150 result
= fmt_json
.get('resultDes')
151 if result
.lower() != 'ok':
152 raise ExtractorError(
153 '%s returned error: %s' % (self
.IE_NAME
, result
), expected
=True)
155 for format_id
, video_url
in fmt_json
['resultObject'].items():
156 if format_id
== 'token' or not video_url
.startswith('http'):
158 if 'geodeswowsmpra3player' in video_url
:
159 # f4m_path = video_url.split('smil:', 1)[-1].split('free_', 1)[0]
160 # f4m_url = 'http://drg.antena3.com/{0}hds/es/sd.f4m'.format(f4m_path)
161 # this videos are protected by DRM, the f4m downloader doesn't support them
163 video_url_hd
= video_url
.replace('free_es', 'es')
164 formats
.extend(self
._extract
_f
4m
_formats
(
165 video_url_hd
[:-9] + '/manifest.f4m', video_id
, f4m_id
='hds',
167 formats
.extend(self
._extract
_mpd
_formats
(
168 video_url_hd
[:-9] + '/manifest.mpd', video_id
, mpd_id
='dash',
170 self
._sort
_formats
(formats
)
172 path_data
= player
.get('pathData')
174 episode
= self
._download
_xml
(
175 self
._EPISODE
_URL
_TEMPLATE
% path_data
, video_id
,
176 'Downloading episode XML')
178 duration
= float_or_none(xpath_text(
179 episode
, './media/asset/info/technical/contentDuration', 'duration'))
181 art
= episode
.find('./media/asset/info/art')
182 title
= xpath_text(art
, './name', 'title')
183 description
= xpath_text(art
, './description', 'description')
184 thumbnail
= xpath_text(episode
, './media/asset/files/background', 'thumbnail')
187 subtitle_url
= xpath_text(episode
, './media/asset/files/subtitle', 'subtitle')
197 'description': description
,
198 'thumbnail': thumbnail
,
199 'duration': duration
,
201 'subtitles': subtitles
,