5 from .common
import InfoExtractor
17 class RTVEALaCartaIE(InfoExtractor
):
18 IE_NAME
= 'rtve.es:alacarta'
19 IE_DESC
= 'RTVE a la carta'
20 _VALID_URL
= r
'https?://(?:www\.)?rtve\.es/(m/)?(alacarta/videos|filmoteca)/[^/]+/[^/]+/(?P<id>\d+)'
23 'url': 'http://www.rtve.es/alacarta/videos/balonmano/o-swiss-cup-masculina-final-espana-suecia/2491869/',
24 'md5': '1d49b7e1ca7a7502c56a4bf1b60f1b43',
28 'title': 'Balonmano - Swiss Cup masculina. Final: España-Suecia',
30 'series': 'Balonmano',
32 'expected_warnings': ['Failed to download MPD manifest', 'Failed to download m3u8 information'],
34 'note': 'Live stream',
35 'url': 'http://www.rtve.es/alacarta/videos/television/24h-live/1694255/',
39 'title': 're:^24H LIVE [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
43 'skip_download': 'live stream',
46 'url': 'http://www.rtve.es/alacarta/videos/servir-y-proteger/servir-proteger-capitulo-104/4236788/',
47 'md5': 'd850f3c8731ea53952ebab489cf81cbf',
51 'title': 'Servir y proteger - Capítulo 104',
54 'expected_warnings': ['Failed to download MPD manifest', 'Failed to download m3u8 information'],
56 'url': 'http://www.rtve.es/m/alacarta/videos/cuentame-como-paso/cuentame-como-paso-t16-ultimo-minuto-nuestra-vida-capitulo-276/2969138/?media=tve',
57 'only_matching': True,
59 'url': 'http://www.rtve.es/filmoteca/no-do/not-1-introduccion-primer-noticiario-espanol/1465256/',
60 'only_matching': True,
63 def _real_initialize(self
):
64 user_agent_b64
= base64
.b64encode(self
.get_param('http_headers')['User-Agent'].encode()).decode('utf-8')
65 self
._manager
= self
._download
_json
(
66 'http://www.rtve.es/odin/loki/' + user_agent_b64
,
67 None, 'Fetching manager info')['manager']
70 def _decrypt_url(png
):
71 encrypted_data
= io
.BytesIO(base64
.b64decode(png
)[8:])
73 length
= struct
.unpack('!I', encrypted_data
.read(4))[0]
74 chunk_type
= encrypted_data
.read(4)
75 if chunk_type
== b
'IEND':
77 data
= encrypted_data
.read(length
)
78 if chunk_type
== b
'tEXt':
79 alphabet_data
, text
= data
.split(b
'\0')
80 quality
, url_data
= text
.split(b
'%%')
84 for l
in alphabet_data
.decode('iso-8859-1'):
94 for letter
in url_data
.decode('iso-8859-1'):
108 yield quality
.decode(), url
109 encrypted_data
.read(4) # CRC
111 def _extract_png_formats(self
, video_id
):
112 png
= self
._download
_webpage
(
113 f
'http://www.rtve.es/ztnr/movil/thumbnail/{self._manager}/videos/{video_id}.png',
114 video_id
, 'Downloading url information', query
={'q': 'v2'})
115 q
= qualities(['Media', 'Alta', 'HQ', 'HD_READY', 'HD_FULL'])
117 for quality
, video_url
in self
._decrypt
_url
(png
):
118 ext
= determine_ext(video_url
)
120 formats
.extend(self
._extract
_m
3u8_formats
(
121 video_url
, video_id
, 'mp4', 'm3u8_native',
122 m3u8_id
='hls', fatal
=False))
124 formats
.extend(self
._extract
_mpd
_formats
(
125 video_url
, video_id
, 'dash', fatal
=False))
128 'format_id': quality
,
129 'quality': q(quality
),
134 def _real_extract(self
, url
):
135 video_id
= self
._match
_id
(url
)
136 info
= self
._download
_json
(
137 f
'http://www.rtve.es/api/videos/{video_id}/config/alacarta_videos.json',
138 video_id
)['page']['items'][0]
139 if info
['state'] == 'DESPU':
140 raise ExtractorError('The video is no longer available', expected
=True)
141 title
= info
['title'].strip()
142 formats
= self
._extract
_png
_formats
(video_id
)
145 sbt_file
= info
.get('sbtFile')
147 subtitles
= self
.extract_subtitles(video_id
, sbt_file
)
149 is_live
= info
.get('live') is True
155 'thumbnail': info
.get('image'),
156 'subtitles': subtitles
,
157 'duration': float_or_none(info
.get('duration'), 1000),
159 'series': info
.get('programTitle'),
162 def _get_subtitles(self
, video_id
, sub_file
):
163 subs
= self
._download
_json
(
164 sub_file
+ '.json', video_id
,
165 'Downloading subtitles info')['page']['items']
167 (s
['lang'], [{'ext': 'vtt', 'url': s
['src']}])
171 class RTVEAudioIE(RTVEALaCartaIE
): # XXX: Do not subclass from concrete IE
172 IE_NAME
= 'rtve.es:audio'
173 IE_DESC
= 'RTVE audio'
174 _VALID_URL
= r
'https?://(?:www\.)?rtve\.es/(alacarta|play)/audios/[^/]+/[^/]+/(?P<id>[0-9]+)'
177 'url': 'https://www.rtve.es/alacarta/audios/a-hombros-de-gigantes/palabra-ingeniero-codigos-informaticos-27-04-21/5889192/',
178 'md5': 'ae06d27bff945c4e87a50f89f6ce48ce',
182 'title': 'Códigos informáticos',
183 'thumbnail': r
're:https?://.+/1598856591583.jpg',
185 'series': 'A hombros de gigantes',
188 'url': 'https://www.rtve.es/play/audios/en-radio-3/ignatius-farray/5791165/',
189 'md5': '072855ab89a9450e0ba314c717fa5ebc',
193 'title': 'Ignatius Farray',
194 'thumbnail': r
're:https?://.+/1613243011863.jpg',
195 'duration': 3559.559,
196 'series': 'En Radio 3',
199 'url': 'https://www.rtve.es/play/audios/frankenstein-o-el-moderno-prometeo/capitulo-26-ultimo-muerte-victor-juan-jose-plans-mary-shelley/6082623/',
200 'md5': '0eadab248cc8dd193fa5765712e84d5c',
204 'title': 'Capítulo 26 y último: La muerte de Victor',
205 'thumbnail': r
're:https?://.+/1632147445707.jpg',
206 'duration': 3174.086,
207 'series': 'Frankenstein o el moderno Prometeo',
211 def _extract_png_formats(self
, audio_id
):
213 This function retrieves media related png thumbnail which obfuscate
214 valuable information about the media. This information is decrypted
215 via base class _decrypt_url function providing media quality and
218 png
= self
._download
_webpage
(
219 f
'http://www.rtve.es/ztnr/movil/thumbnail/{self._manager}/audios/{audio_id}.png',
220 audio_id
, 'Downloading url information', query
={'q': 'v2'})
221 q
= qualities(['Media', 'Alta', 'HQ', 'HD_READY', 'HD_FULL'])
223 for quality
, audio_url
in self
._decrypt
_url
(png
):
224 ext
= determine_ext(audio_url
)
226 formats
.extend(self
._extract
_m
3u8_formats
(
227 audio_url
, audio_id
, 'mp4', 'm3u8_native',
228 m3u8_id
='hls', fatal
=False))
230 formats
.extend(self
._extract
_mpd
_formats
(
231 audio_url
, audio_id
, 'dash', fatal
=False))
234 'format_id': quality
,
235 'quality': q(quality
),
240 def _real_extract(self
, url
):
241 audio_id
= self
._match
_id
(url
)
242 info
= self
._download
_json
(
243 f
'https://www.rtve.es/api/audios/{audio_id}.json',
244 audio_id
)['page']['items'][0]
248 'title': info
['title'].strip(),
249 'thumbnail': info
.get('thumbnail'),
250 'duration': float_or_none(info
.get('duration'), 1000),
251 'series': try_get(info
, lambda x
: x
['programInfo']['title']),
252 'formats': self
._extract
_png
_formats
(audio_id
),
256 class RTVEInfantilIE(RTVEALaCartaIE
): # XXX: Do not subclass from concrete IE
257 IE_NAME
= 'rtve.es:infantil'
258 IE_DESC
= 'RTVE infantil'
259 _VALID_URL
= r
'https?://(?:www\.)?rtve\.es/infantil/serie/[^/]+/video/[^/]+/(?P<id>[0-9]+)/'
262 'url': 'http://www.rtve.es/infantil/serie/cleo/video/maneras-vivir/3040283/',
263 'md5': '5747454717aedf9f9fdf212d1bcfc48d',
267 'title': 'Maneras de vivir',
268 'thumbnail': r
're:https?://.+/1426182947956\.JPG',
271 'expected_warnings': ['Failed to download MPD manifest', 'Failed to download m3u8 information'],
275 class RTVELiveIE(RTVEALaCartaIE
): # XXX: Do not subclass from concrete IE
276 IE_NAME
= 'rtve.es:live'
277 IE_DESC
= 'RTVE.es live streams'
278 _VALID_URL
= r
'https?://(?:www\.)?rtve\.es/directo/(?P<id>[a-zA-Z0-9-]+)'
281 'url': 'http://www.rtve.es/directo/la-1/',
285 'title': 're:^La 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
288 'skip_download': 'live stream',
292 def _real_extract(self
, url
):
293 mobj
= self
._match
_valid
_url
(url
)
294 video_id
= mobj
.group('id')
296 webpage
= self
._download
_webpage
(url
, video_id
)
297 title
= remove_end(self
._og
_search
_title
(webpage
), ' en directo en RTVE.es')
298 title
= remove_start(title
, 'Estoy viendo ')
300 vidplayer_id
= self
._search
_regex
(
301 (r
'playerId=player([0-9]+)',
302 r
'class=["\'].*?
\blive
_mod
\b.*?
["\'][^>]+data-assetid=["\'](\d
+)',
303 r'data
-id=["\'](\d+)'),
304 webpage, 'internal video ID')
309 'formats': self._extract_png_formats(vidplayer_id),
314 class RTVETelevisionIE(InfoExtractor):
315 IE_NAME = 'rtve.es:television'
316 _VALID_URL = r'https?://(?:www\.)?rtve\.es/television/[^/]+/[^/]+/(?P<id>\d+).shtml'
319 'url': 'http://www.rtve.es/television/20160628/revolucion-del-movil/1364141.shtml',
323 'title': 'Documentos TV - La revolución del móvil',
324 'duration': 3496.948,
327 'skip_download': True,
331 def _real_extract(self, url):
332 page_id = self._match_id(url)
333 webpage = self._download_webpage(url, page_id)
335 alacarta_url = self._search_regex(
336 r'data-location="alacarta_videos
"[^<]+url":"(http://www\.rtve\.es/alacarta.+?)&',
337 webpage, 'alacarta url', default=None)
338 if alacarta_url is None:
339 raise ExtractorError(
340 'The webpage doesn\'t contain any video', expected=True)
342 return self.url_result(alacarta_url, ie=RTVEALaCartaIE.ie_key())