4 from .common
import InfoExtractor
20 class RTVEALaCartaIE(InfoExtractor
):
21 IE_NAME
= 'rtve.es:alacarta'
22 IE_DESC
= 'RTVE a la carta'
23 _VALID_URL
= r
'https?://(?:www\.)?rtve\.es/(m/)?(alacarta/videos|filmoteca)/[^/]+/[^/]+/(?P<id>\d+)'
26 'url': 'http://www.rtve.es/alacarta/videos/balonmano/o-swiss-cup-masculina-final-espana-suecia/2491869/',
27 'md5': '1d49b7e1ca7a7502c56a4bf1b60f1b43',
31 'title': 'Balonmano - Swiss Cup masculina. Final: España-Suecia',
33 'series': 'Balonmano',
35 'expected_warnings': ['Failed to download MPD manifest', 'Failed to download m3u8 information'],
37 'note': 'Live stream',
38 'url': 'http://www.rtve.es/alacarta/videos/television/24h-live/1694255/',
42 'title': 're:^24H LIVE [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
46 'skip_download': 'live stream',
49 'url': 'http://www.rtve.es/alacarta/videos/servir-y-proteger/servir-proteger-capitulo-104/4236788/',
50 'md5': 'd850f3c8731ea53952ebab489cf81cbf',
54 'title': 'Servir y proteger - Capítulo 104',
57 'expected_warnings': ['Failed to download MPD manifest', 'Failed to download m3u8 information'],
59 'url': 'http://www.rtve.es/m/alacarta/videos/cuentame-como-paso/cuentame-como-paso-t16-ultimo-minuto-nuestra-vida-capitulo-276/2969138/?media=tve',
60 'only_matching': True,
62 'url': 'http://www.rtve.es/filmoteca/no-do/not-1-introduccion-primer-noticiario-espanol/1465256/',
63 'only_matching': True,
66 def _real_initialize(self
):
67 user_agent_b64
= base64
.b64encode(self
.get_param('http_headers')['User-Agent'].encode('utf-8')).decode('utf-8')
68 self
._manager
= self
._download
_json
(
69 'http://www.rtve.es/odin/loki/' + user_agent_b64
,
70 None, 'Fetching manager info')['manager']
73 def _decrypt_url(png
):
74 encrypted_data
= io
.BytesIO(compat_b64decode(png
)[8:])
76 length
= compat_struct_unpack('!I', encrypted_data
.read(4))[0]
77 chunk_type
= encrypted_data
.read(4)
78 if chunk_type
== b
'IEND':
80 data
= encrypted_data
.read(length
)
81 if chunk_type
== b
'tEXt':
82 alphabet_data
, text
= data
.split(b
'\0')
83 quality
, url_data
= text
.split(b
'%%')
87 for l
in alphabet_data
.decode('iso-8859-1'):
97 for letter
in url_data
.decode('iso-8859-1'):
111 yield quality
.decode(), url
112 encrypted_data
.read(4) # CRC
114 def _extract_png_formats(self
, video_id
):
115 png
= self
._download
_webpage
(
116 'http://www.rtve.es/ztnr/movil/thumbnail/%s/videos/%s.png' % (self
._manager
, video_id
),
117 video_id
, 'Downloading url information', query
={'q': 'v2'}
)
118 q
= qualities(['Media', 'Alta', 'HQ', 'HD_READY', 'HD_FULL'])
120 for quality
, video_url
in self
._decrypt
_url
(png
):
121 ext
= determine_ext(video_url
)
123 formats
.extend(self
._extract
_m
3u8_formats
(
124 video_url
, video_id
, 'mp4', 'm3u8_native',
125 m3u8_id
='hls', fatal
=False))
127 formats
.extend(self
._extract
_mpd
_formats
(
128 video_url
, video_id
, 'dash', fatal
=False))
131 'format_id': quality
,
132 'quality': q(quality
),
135 self
._sort
_formats
(formats
)
138 def _real_extract(self
, url
):
139 video_id
= self
._match
_id
(url
)
140 info
= self
._download
_json
(
141 'http://www.rtve.es/api/videos/%s/config/alacarta_videos.json' % video_id
,
142 video_id
)['page']['items'][0]
143 if info
['state'] == 'DESPU':
144 raise ExtractorError('The video is no longer available', expected
=True)
145 title
= info
['title'].strip()
146 formats
= self
._extract
_png
_formats
(video_id
)
149 sbt_file
= info
.get('sbtFile')
151 subtitles
= self
.extract_subtitles(video_id
, sbt_file
)
153 is_live
= info
.get('live') is True
159 'thumbnail': info
.get('image'),
160 'subtitles': subtitles
,
161 'duration': float_or_none(info
.get('duration'), 1000),
163 'series': info
.get('programTitle'),
166 def _get_subtitles(self
, video_id
, sub_file
):
167 subs
= self
._download
_json
(
168 sub_file
+ '.json', video_id
,
169 'Downloading subtitles info')['page']['items']
171 (s
['lang'], [{'ext': 'vtt', 'url': s['src']}
])
175 class RTVEAudioIE(RTVEALaCartaIE
):
176 IE_NAME
= 'rtve.es:audio'
177 IE_DESC
= 'RTVE audio'
178 _VALID_URL
= r
'https?://(?:www\.)?rtve\.es/(alacarta|play)/audios/[^/]+/[^/]+/(?P<id>[0-9]+)'
181 'url': 'https://www.rtve.es/alacarta/audios/a-hombros-de-gigantes/palabra-ingeniero-codigos-informaticos-27-04-21/5889192/',
182 'md5': 'ae06d27bff945c4e87a50f89f6ce48ce',
186 'title': 'Códigos informáticos',
187 'thumbnail': r
're:https?://.+/1598856591583.jpg',
189 'series': 'A hombros de gigantes',
192 'url': 'https://www.rtve.es/play/audios/en-radio-3/ignatius-farray/5791165/',
193 'md5': '072855ab89a9450e0ba314c717fa5ebc',
197 'title': 'Ignatius Farray',
198 'thumbnail': r
're:https?://.+/1613243011863.jpg',
199 'duration': 3559.559,
200 'series': 'En Radio 3'
203 'url': 'https://www.rtve.es/play/audios/frankenstein-o-el-moderno-prometeo/capitulo-26-ultimo-muerte-victor-juan-jose-plans-mary-shelley/6082623/',
204 'md5': '0eadab248cc8dd193fa5765712e84d5c',
208 'title': 'Capítulo 26 y último: La muerte de Victor',
209 'thumbnail': r
're:https?://.+/1632147445707.jpg',
210 'duration': 3174.086,
211 'series': 'Frankenstein o el moderno Prometeo'
215 def _extract_png_formats(self
, audio_id
):
217 This function retrieves media related png thumbnail which obfuscate
218 valuable information about the media. This information is decrypted
219 via base class _decrypt_url function providing media quality and
222 png
= self
._download
_webpage
(
223 'http://www.rtve.es/ztnr/movil/thumbnail/%s/audios/%s.png' %
224 (self
._manager
, audio_id
),
225 audio_id
, 'Downloading url information', query
={'q': 'v2'}
)
226 q
= qualities(['Media', 'Alta', 'HQ', 'HD_READY', 'HD_FULL'])
228 for quality
, audio_url
in self
._decrypt
_url
(png
):
229 ext
= determine_ext(audio_url
)
231 formats
.extend(self
._extract
_m
3u8_formats
(
232 audio_url
, audio_id
, 'mp4', 'm3u8_native',
233 m3u8_id
='hls', fatal
=False))
235 formats
.extend(self
._extract
_mpd
_formats
(
236 audio_url
, audio_id
, 'dash', fatal
=False))
239 'format_id': quality
,
240 'quality': q(quality
),
243 self
._sort
_formats
(formats
)
246 def _real_extract(self
, url
):
247 audio_id
= self
._match
_id
(url
)
248 info
= self
._download
_json
(
249 'https://www.rtve.es/api/audios/%s.json' % audio_id
,
250 audio_id
)['page']['items'][0]
254 'title': info
['title'].strip(),
255 'thumbnail': info
.get('thumbnail'),
256 'duration': float_or_none(info
.get('duration'), 1000),
257 'series': try_get(info
, lambda x
: x
['programInfo']['title']),
258 'formats': self
._extract
_png
_formats
(audio_id
),
262 class RTVEInfantilIE(RTVEALaCartaIE
):
263 IE_NAME
= 'rtve.es:infantil'
264 IE_DESC
= 'RTVE infantil'
265 _VALID_URL
= r
'https?://(?:www\.)?rtve\.es/infantil/serie/[^/]+/video/[^/]+/(?P<id>[0-9]+)/'
268 'url': 'http://www.rtve.es/infantil/serie/cleo/video/maneras-vivir/3040283/',
269 'md5': '5747454717aedf9f9fdf212d1bcfc48d',
273 'title': 'Maneras de vivir',
274 'thumbnail': r
're:https?://.+/1426182947956\.JPG',
277 'expected_warnings': ['Failed to download MPD manifest', 'Failed to download m3u8 information'],
281 class RTVELiveIE(RTVEALaCartaIE
):
282 IE_NAME
= 'rtve.es:live'
283 IE_DESC
= 'RTVE.es live streams'
284 _VALID_URL
= r
'https?://(?:www\.)?rtve\.es/directo/(?P<id>[a-zA-Z0-9-]+)'
287 'url': 'http://www.rtve.es/directo/la-1/',
291 'title': 're:^La 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
294 'skip_download': 'live stream',
298 def _real_extract(self
, url
):
299 mobj
= self
._match
_valid
_url
(url
)
300 video_id
= mobj
.group('id')
302 webpage
= self
._download
_webpage
(url
, video_id
)
303 title
= remove_end(self
._og
_search
_title
(webpage
), ' en directo en RTVE.es')
304 title
= remove_start(title
, 'Estoy viendo ')
306 vidplayer_id
= self
._search
_regex
(
307 (r
'playerId=player([0-9]+)',
308 r
'class=["\'].*?
\blive
_mod
\b.*?
["\'][^>]+data-assetid=["\'](\d
+)',
309 r'data
-id=["\'](\d+)'),
310 webpage, 'internal video ID')
315 'formats': self._extract_png_formats(vidplayer_id),
320 class RTVETelevisionIE(InfoExtractor):
321 IE_NAME = 'rtve.es:television'
322 _VALID_URL = r'https?://(?:www\.)?rtve\.es/television/[^/]+/[^/]+/(?P<id>\d+).shtml'
325 'url': 'http://www.rtve.es/television/20160628/revolucion-del-movil/1364141.shtml',
329 'title': 'Documentos TV - La revolución del móvil',
330 'duration': 3496.948,
333 'skip_download': True,
337 def _real_extract(self, url):
338 page_id = self._match_id(url)
339 webpage = self._download_webpage(url, page_id)
341 alacarta_url = self._search_regex(
342 r'data-location="alacarta_videos
"[^<]+url":"(http://www\.rtve\.es/alacarta.+?)&',
343 webpage, 'alacarta url', default=None)
344 if alacarta_url is None:
345 raise ExtractorError(
346 'The webpage doesn\'t contain any video', expected=True)
348 return self.url_result(alacarta_url, ie=RTVEALaCartaIE.ie_key())