2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
20 def _decrypt_url(png
):
21 encrypted_data
= base64
.b64decode(png
.encode('utf-8'))
22 text_index
= encrypted_data
.find(b
'tEXt')
23 text_chunk
= encrypted_data
[text_index
- 4:]
24 length
= struct_unpack('!I', text_chunk
[:4])[0]
25 # Use bytearray to get integers when iterating in both python 2.x and 3.x
26 data
= bytearray(text_chunk
[8:8 + length
])
27 data
= [chr(b
) for b
in data
if b
!= 0]
28 hash_index
= data
.index('#')
29 alphabet_data
= data
[:hash_index
]
30 url_data
= data
[hash_index
+ 1:]
35 for l
in alphabet_data
:
45 for letter
in url_data
:
62 class RTVEALaCartaIE(InfoExtractor
):
63 IE_NAME
= 'rtve.es:alacarta'
64 IE_DESC
= 'RTVE a la carta'
65 _VALID_URL
= r
'https?://www\.rtve\.es/(m/)?alacarta/videos/[^/]+/[^/]+/(?P<id>\d+)'
68 'url': 'http://www.rtve.es/alacarta/videos/balonmano/o-swiss-cup-masculina-final-espana-suecia/2491869/',
69 'md5': '1d49b7e1ca7a7502c56a4bf1b60f1b43',
73 'title': 'Balonmano - Swiss Cup masculina. Final: EspaƱa-Suecia',
77 'note': 'Live stream',
78 'url': 'http://www.rtve.es/alacarta/videos/television/24h-live/1694255/',
84 'skip': 'The f4m manifest can\'t be used yet',
86 'url': 'http://www.rtve.es/m/alacarta/videos/cuentame-como-paso/cuentame-como-paso-t16-ultimo-minuto-nuestra-vida-capitulo-276/2969138/?media=tve',
87 'only_matching': True,
90 def _real_initialize(self
):
91 user_agent_b64
= base64
.b64encode(std_headers
['User-Agent'].encode('utf-8')).decode('utf-8')
92 manager_info
= self
._download
_json
(
93 'http://www.rtve.es/odin/loki/' + user_agent_b64
,
94 None, 'Fetching manager info')
95 self
._manager
= manager_info
['manager']
97 def _real_extract(self
, url
):
98 mobj
= re
.match(self
._VALID
_URL
, url
)
99 video_id
= mobj
.group('id')
100 info
= self
._download
_json
(
101 'http://www.rtve.es/api/videos/%s/config/alacarta_videos.json' % video_id
,
102 video_id
)['page']['items'][0]
103 if info
['state'] == 'DESPU':
104 raise ExtractorError('The video is no longer available', expected
=True)
105 png_url
= 'http://www.rtve.es/ztnr/movil/thumbnail/%s/videos/%s.png' % (self
._manager
, video_id
)
106 png_request
= sanitized_Request(png_url
)
107 png_request
.add_header('Referer', url
)
108 png
= self
._download
_webpage
(png_request
, video_id
, 'Downloading url information')
109 video_url
= _decrypt_url(png
)
110 if not video_url
.endswith('.f4m'):
111 video_url
= video_url
.replace(
112 'resources/', 'auth/resources/'
113 ).replace('.net.rtve', '.multimedia.cdn.rtve')
116 if info
.get('sbtFile') is not None:
117 subtitles
= self
.extract_subtitles(video_id
, info
['sbtFile'])
121 'title': info
['title'],
123 'thumbnail': info
.get('image'),
125 'subtitles': subtitles
,
126 'duration': float_or_none(info
.get('duration'), scale
=1000),
129 def _get_subtitles(self
, video_id
, sub_file
):
130 subs
= self
._download
_json
(
131 sub_file
+ '.json', video_id
,
132 'Downloading subtitles info')['page']['items']
134 (s
['lang'], [{'ext': 'vtt', 'url': s['src']}
])
138 class RTVEInfantilIE(InfoExtractor
):
139 IE_NAME
= 'rtve.es:infantil'
140 IE_DESC
= 'RTVE infantil'
141 _VALID_URL
= r
'https?://(?:www\.)?rtve\.es/infantil/serie/(?P<show>[^/]*)/video/(?P<short_title>[^/]*)/(?P<id>[0-9]+)/'
144 'url': 'http://www.rtve.es/infantil/serie/cleo/video/maneras-vivir/3040283/',
145 'md5': '915319587b33720b8e0357caaa6617e6',
149 'title': 'Maneras de vivir',
150 'thumbnail': 'http://www.rtve.es/resources/jpg/6/5/1426182947956.JPG',
155 def _real_extract(self
, url
):
156 video_id
= self
._match
_id
(url
)
157 info
= self
._download
_json
(
158 'http://www.rtve.es/api/videos/%s/config/alacarta_videos.json' % video_id
,
159 video_id
)['page']['items'][0]
161 webpage
= self
._download
_webpage
(url
, video_id
)
162 vidplayer_id
= self
._search
_regex
(
163 r
' id="vidplayer([0-9]+)"', webpage
, 'internal video ID')
165 png_url
= 'http://www.rtve.es/ztnr/movil/thumbnail/default/videos/%s.png' % vidplayer_id
166 png
= self
._download
_webpage
(png_url
, video_id
, 'Downloading url information')
167 video_url
= _decrypt_url(png
)
172 'title': info
['title'],
174 'thumbnail': info
.get('image'),
175 'duration': float_or_none(info
.get('duration'), scale
=1000),
179 class RTVELiveIE(InfoExtractor
):
180 IE_NAME
= 'rtve.es:live'
181 IE_DESC
= 'RTVE.es live streams'
182 _VALID_URL
= r
'https?://www\.rtve\.es/directo/(?P<id>[a-zA-Z0-9-]+)'
185 'url': 'http://www.rtve.es/directo/la-1/',
189 'title': 're:^La 1 [0-9]{4}-[0-9]{2}-[0-9]{2}Z[0-9]{6}$',
192 'skip_download': 'live stream',
196 def _real_extract(self
, url
):
197 mobj
= re
.match(self
._VALID
_URL
, url
)
198 start_time
= time
.gmtime()
199 video_id
= mobj
.group('id')
201 webpage
= self
._download
_webpage
(url
, video_id
)
202 title
= remove_end(self
._og
_search
_title
(webpage
), ' en directo en RTVE.es')
203 title
= remove_start(title
, 'Estoy viendo ')
204 title
+= ' ' + time
.strftime('%Y-%m-%dZ%H%M%S', start_time
)
206 vidplayer_id
= self
._search
_regex
(
207 r
'playerId=player([0-9]+)', webpage
, 'internal video ID')
208 png_url
= 'http://www.rtve.es/ztnr/movil/thumbnail/amonet/videos/%s.png' % vidplayer_id
209 png
= self
._download
_webpage
(png_url
, video_id
, 'Downloading url information')
210 m3u8_url
= _decrypt_url(png
)
211 formats
= self
._extract
_m
3u8_formats
(m3u8_url
, video_id
, ext
='mp4')