]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/atresplayer.py
1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
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': 're:^https?://.*\.jpg$',
37 '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',
38 'only_matching': True,
42 _USER_AGENT
= 'Dalvik/1.6.0 (Linux; U; Android 4.3; GT-I9300 Build/JSS15J'
43 _MAGIC
= 'QWtMLXs414Yo+c#_+Q#K@NN)'
44 _TIMESTAMP_SHIFT
= 30000
46 _TIME_API_URL
= 'http://servicios.atresplayer.com/api/admin/time.json'
47 _URL_VIDEO_TEMPLATE
= 'https://servicios.atresplayer.com/api/urlVideo/{1}/{0}/{1}|{2}|{3}.json'
48 _PLAYER_URL_TEMPLATE
= 'https://servicios.atresplayer.com/episode/getplayer.json?episodePk=%s'
49 _EPISODE_URL_TEMPLATE
= 'http://www.atresplayer.com/episodexml/%s'
51 _LOGIN_URL
= 'https://servicios.atresplayer.com/j_spring_security_check'
53 def _real_initialize(self
):
57 (username
, password
) = self
._get
_login
_info
()
62 'j_username': username
,
63 'j_password': password
,
66 request
= sanitized_Request(
67 self
._LOGIN
_URL
, compat_urllib_parse
.urlencode(login_form
).encode('utf-8'))
68 request
.add_header('Content-Type', 'application/x-www-form-urlencoded')
69 response
= self
._download
_webpage
(
70 request
, None, 'Logging in as %s' % username
)
72 error
= self
._html
_search
_regex
(
73 r
'(?s)<ul class="list_error">(.+?)</ul>', response
, 'error', default
=None)
76 'Unable to login: %s' % error
, expected
=True)
78 def _real_extract(self
, url
):
79 video_id
= self
._match
_id
(url
)
81 webpage
= self
._download
_webpage
(url
, video_id
)
83 episode_id
= self
._search
_regex
(
84 r
'episode="([^"]+)"', webpage
, 'episode id')
86 timestamp
= int_or_none(self
._download
_webpage
(
88 video_id
, 'Downloading timestamp', fatal
=False), 1000, time
.time())
89 timestamp_shifted
= compat_str(timestamp
+ self
._TIMESTAMP
_SHIFT
)
91 self
._MAGIC
.encode('ascii'),
92 (episode_id
+ timestamp_shifted
).encode('utf-8')
96 for fmt
in ['windows', 'android_tablet']:
97 request
= sanitized_Request(
98 self
._URL
_VIDEO
_TEMPLATE
.format(fmt
, episode_id
, timestamp_shifted
, token
))
99 request
.add_header('User-Agent', self
._USER
_AGENT
)
101 fmt_json
= self
._download
_json
(
102 request
, video_id
, 'Downloading %s video JSON' % fmt
)
104 result
= fmt_json
.get('resultDes')
105 if result
.lower() != 'ok':
106 raise ExtractorError(
107 '%s returned error: %s' % (self
.IE_NAME
, result
), expected
=True)
109 for format_id
, video_url
in fmt_json
['resultObject'].items():
110 if format_id
== 'token' or not video_url
.startswith('http'):
112 if video_url
.endswith('/Manifest'):
113 if 'geodeswowsmpra3player' in video_url
:
114 f4m_path
= video_url
.split('smil:', 1)[-1].split('free_', 1)[0]
115 f4m_url
= 'http://drg.antena3.com/{0}hds/es/sd.f4m'.format(f4m_path
)
116 # this videos are protected by DRM, the f4m downloader doesn't support them
119 f4m_url
= video_url
[:-9] + '/manifest.f4m'
120 formats
.extend(self
._extract
_f
4m
_formats
(f4m_url
, video_id
))
124 'format_id': 'android-%s' % format_id
,
127 self
._sort
_formats
(formats
)
129 player
= self
._download
_json
(
130 self
._PLAYER
_URL
_TEMPLATE
% episode_id
,
133 path_data
= player
.get('pathData')
135 episode
= self
._download
_xml
(
136 self
._EPISODE
_URL
_TEMPLATE
% path_data
,
137 video_id
, 'Downloading episode XML')
139 duration
= float_or_none(xpath_text(
140 episode
, './media/asset/info/technical/contentDuration', 'duration'))
142 art
= episode
.find('./media/asset/info/art')
143 title
= xpath_text(art
, './name', 'title')
144 description
= xpath_text(art
, './description', 'description')
145 thumbnail
= xpath_text(episode
, './media/asset/files/background', 'thumbnail')
148 subtitle_url
= xpath_text(episode
, './media/asset/files/subtitle', 'subtitle')
158 'description': description
,
159 'thumbnail': thumbnail
,
160 'duration': duration
,
162 'subtitles': subtitles
,