]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/atresplayer.py
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 timestamp
= int_or_none(self
._download
_webpage
(
137 video_id
, 'Downloading timestamp', fatal
=False), 1000, time
.time())
138 timestamp_shifted
= compat_str(timestamp
+ self
._TIMESTAMP
_SHIFT
)
140 self
._MAGIC
.encode('ascii'),
141 (episode_id
+ timestamp_shifted
).encode('utf-8'), hashlib
.md5
144 request
= sanitized_Request(
145 self
._URL
_VIDEO
_TEMPLATE
.format('windows', episode_id
, timestamp_shifted
, token
),
146 headers
={'User-Agent': self
._USER
_AGENT
})
148 fmt_json
= self
._download
_json
(
149 request
, video_id
, 'Downloading windows video JSON')
151 result
= fmt_json
.get('resultDes')
152 if result
.lower() != 'ok':
153 raise ExtractorError(
154 '%s returned error: %s' % (self
.IE_NAME
, result
), expected
=True)
156 for format_id
, video_url
in fmt_json
['resultObject'].items():
157 if format_id
== 'token' or not video_url
.startswith('http'):
159 if 'geodeswowsmpra3player' in video_url
:
160 f4m_path
= video_url
.split('smil:', 1)[-1].split('free_', 1)[0]
161 f4m_url
= 'http://drg.antena3.com/{0}hds/es/sd.f4m'.format(f4m_path
)
162 # this videos are protected by DRM, the f4m downloader doesn't support them
165 f4m_url
= video_url
[:-9] + '/manifest.f4m'
166 formats
.extend(self
._extract
_f
4m
_formats
(f4m_url
, video_id
, f4m_id
='hds', fatal
=False))
167 self
._sort
_formats
(formats
)
169 path_data
= player
.get('pathData')
171 episode
= self
._download
_xml
(
172 self
._EPISODE
_URL
_TEMPLATE
% path_data
, video_id
,
173 'Downloading episode XML')
175 duration
= float_or_none(xpath_text(
176 episode
, './media/asset/info/technical/contentDuration', 'duration'))
178 art
= episode
.find('./media/asset/info/art')
179 title
= xpath_text(art
, './name', 'title')
180 description
= xpath_text(art
, './description', 'description')
181 thumbnail
= xpath_text(episode
, './media/asset/files/background', 'thumbnail')
184 subtitle_url
= xpath_text(episode
, './media/asset/files/subtitle', 'subtitle')
194 'description': description
,
195 'thumbnail': thumbnail
,
196 'duration': duration
,
198 'subtitles': subtitles
,