]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/rtve.py
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
13 class RTVEALaCartaIE(InfoExtractor
):
14 IE_NAME
= 'rtve.es:alacarta'
15 IE_DESC
= 'RTVE a la carta'
16 _VALID_URL
= r
'http://www\.rtve\.es/alacarta/videos/[^/]+/[^/]+/(?P<id>\d+)'
19 'url': 'http://www.rtve.es/alacarta/videos/balonmano/o-swiss-cup-masculina-final-espana-suecia/2491869/',
20 'md5': '1d49b7e1ca7a7502c56a4bf1b60f1b43',
24 'title': 'Balonmano - Swiss Cup masculina. Final: EspaƱa-Suecia',
28 def _decrypt_url(self
, png
):
29 encrypted_data
= base64
.b64decode(png
)
30 text_index
= encrypted_data
.find(b
'tEXt')
31 text_chunk
= encrypted_data
[text_index
-4:]
32 length
= struct_unpack('!I', text_chunk
[:4])[0]
33 # Use bytearray to get integers when iterating in both python 2.x and 3.x
34 data
= bytearray(text_chunk
[8:8+length
])
35 data
= [chr(b
) for b
in data
if b
!= 0]
36 hash_index
= data
.index('#')
37 alphabet_data
= data
[:hash_index
]
38 url_data
= data
[hash_index
+1:]
43 for l
in alphabet_data
:
53 for letter
in url_data
:
69 def _real_extract(self
, url
):
70 mobj
= re
.match(self
._VALID
_URL
, url
)
71 video_id
= mobj
.group('id')
72 info
= self
._download
_json
(
73 'http://www.rtve.es/api/videos/%s/config/alacarta_videos.json' % video_id
,
74 video_id
)['page']['items'][0]
75 png_url
= 'http://www.rtve.es/ztnr/movil/thumbnail/default/videos/%s.png' % video_id
76 png
= self
._download
_webpage
(png_url
, video_id
, 'Downloading url information')
77 video_url
= self
._decrypt
_url
(png
)
81 'title': info
['title'],
83 'thumbnail': info
['image'],