]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/rtve.py
2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
9 from ..compat
import compat_urllib_request
, compat_urlparse
19 def _decrypt_url(png
):
20 encrypted_data
= base64
.b64decode(png
.encode('utf-8'))
21 text_index
= encrypted_data
.find(b
'tEXt')
22 text_chunk
= encrypted_data
[text_index
- 4:]
23 length
= struct_unpack('!I', text_chunk
[:4])[0]
24 # Use bytearray to get integers when iterating in both python 2.x and 3.x
25 data
= bytearray(text_chunk
[8:8 + length
])
26 data
= [chr(b
) for b
in data
if b
!= 0]
27 hash_index
= data
.index('#')
28 alphabet_data
= data
[:hash_index
]
29 url_data
= data
[hash_index
+ 1:]
34 for l
in alphabet_data
:
44 for letter
in url_data
:
61 class RTVEALaCartaIE(InfoExtractor
):
62 IE_NAME
= 'rtve.es:alacarta'
63 IE_DESC
= 'RTVE a la carta'
64 _VALID_URL
= r
'http://www\.rtve\.es/(m/)?alacarta/videos/[^/]+/[^/]+/(?P<id>\d+)'
67 'url': 'http://www.rtve.es/alacarta/videos/balonmano/o-swiss-cup-masculina-final-espana-suecia/2491869/',
68 'md5': '1d49b7e1ca7a7502c56a4bf1b60f1b43',
72 'title': 'Balonmano - Swiss Cup masculina. Final: España-Suecia',
76 'note': 'Live stream',
77 'url': 'http://www.rtve.es/alacarta/videos/television/24h-live/1694255/',
83 'skip': 'The f4m manifest can\'t be used yet',
85 'url': 'http://www.rtve.es/m/alacarta/videos/cuentame-como-paso/cuentame-como-paso-t16-ultimo-minuto-nuestra-vida-capitulo-276/2969138/?media=tve',
86 'only_matching': True,
89 def _real_initialize(self
):
90 user_agent_b64
= base64
.b64encode(std_headers
['User-Agent'].encode('utf-8')).decode('utf-8')
91 manager_info
= self
._download
_json
(
92 'http://www.rtve.es/odin/loki/' + user_agent_b64
,
93 None, 'Fetching manager info')
94 self
._manager
= manager_info
['manager']
96 def _real_extract(self
, url
):
97 mobj
= re
.match(self
._VALID
_URL
, url
)
98 video_id
= mobj
.group('id')
99 info
= self
._download
_json
(
100 'http://www.rtve.es/api/videos/%s/config/alacarta_videos.json' % video_id
,
101 video_id
)['page']['items'][0]
102 if info
['state'] == 'DESPU':
103 raise ExtractorError('The video is no longer available', expected
=True)
104 png_url
= 'http://www.rtve.es/ztnr/movil/thumbnail/%s/videos/%s.png' % (self
._manager
, video_id
)
105 png_request
= compat_urllib_request
.Request(png_url
)
106 png_request
.add_header('Referer', url
)
107 png
= self
._download
_webpage
(png_request
, video_id
, 'Downloading url information')
108 video_url
= _decrypt_url(png
)
109 if not video_url
.endswith('.f4m'):
110 auth_url
= video_url
.replace(
111 'resources/', 'auth/resources/'
112 ).replace('.net.rtve', '.multimedia.cdn.rtve')
113 video_path
= self
._download
_webpage
(
114 auth_url
, video_id
, 'Getting video url')
115 # Use mvod1.akcdn instead of flash.akamaihd.multimedia.cdn to get
116 # the right Content-Length header and the mp4 format
117 video_url
= compat_urlparse
.urljoin(
118 'http://mvod1.akcdn.rtve.es/', video_path
)
121 if info
.get('sbtFile') is not None:
122 subtitles
= self
.extract_subtitles(video_id
, info
['sbtFile'])
126 'title': info
['title'],
128 'thumbnail': info
.get('image'),
130 'subtitles': subtitles
,
131 'duration': float_or_none(info
.get('duration'), scale
=1000),
134 def _get_subtitles(self
, video_id
, sub_file
):
135 subs
= self
._download
_json
(
136 sub_file
+ '.json', video_id
,
137 'Downloading subtitles info')['page']['items']
139 (s
['lang'], [{'ext': 'vtt', 'url': s
['src']}])
143 class RTVEInfantilIE(InfoExtractor
):
144 IE_NAME
= 'rtve.es:infantil'
145 IE_DESC
= 'RTVE infantil'
146 _VALID_URL
= r
'https?://(?:www\.)?rtve\.es/infantil/serie/(?P<show>[^/]*)/video/(?P<short_title>[^/]*)/(?P<id>[0-9]+)/'
149 'url': 'http://www.rtve.es/infantil/serie/cleo/video/maneras-vivir/3040283/',
150 'md5': '915319587b33720b8e0357caaa6617e6',
154 'title': 'Maneras de vivir',
155 'thumbnail': 'http://www.rtve.es/resources/jpg/6/5/1426182947956.JPG',
160 def _real_extract(self
, url
):
161 video_id
= self
._match
_id
(url
)
162 info
= self
._download
_json
(
163 'http://www.rtve.es/api/videos/%s/config/alacarta_videos.json' % video_id
,
164 video_id
)['page']['items'][0]
166 webpage
= self
._download
_webpage
(url
, video_id
)
167 vidplayer_id
= self
._search
_regex
(
168 r
' id="vidplayer([0-9]+)"', webpage
, 'internal video ID')
170 png_url
= 'http://www.rtve.es/ztnr/movil/thumbnail/default/videos/%s.png' % vidplayer_id
171 png
= self
._download
_webpage
(png_url
, video_id
, 'Downloading url information')
172 video_url
= _decrypt_url(png
)
177 'title': info
['title'],
179 'thumbnail': info
.get('image'),
180 'duration': float_or_none(info
.get('duration'), scale
=1000),
184 class RTVELiveIE(InfoExtractor
):
185 IE_NAME
= 'rtve.es:live'
186 IE_DESC
= 'RTVE.es live streams'
187 _VALID_URL
= r
'http://www\.rtve\.es/(?:deportes/directo|noticias|television)/(?P<id>[a-zA-Z0-9-]+)'
190 'url': 'http://www.rtve.es/noticias/directo-la-1/',
192 'id': 'directo-la-1',
194 'title': 're:^La 1 de TVE [0-9]{4}-[0-9]{2}-[0-9]{2}Z[0-9]{6}$',
197 'skip_download': 'live stream',
201 def _real_extract(self
, url
):
202 mobj
= re
.match(self
._VALID
_URL
, url
)
203 start_time
= time
.gmtime()
204 video_id
= mobj
.group('id')
206 webpage
= self
._download
_webpage
(url
, video_id
)
207 player_url
= self
._search
_regex
(
208 r
'<param name="movie" value="([^"]+)"/>', webpage
, 'player URL')
209 title
= remove_end(self
._og
_search
_title
(webpage
), ' en directo')
210 title
+= ' ' + time
.strftime('%Y-%m-%dZ%H%M%S', start_time
)
212 vidplayer_id
= self
._search
_regex
(
213 r
' id="vidplayer([0-9]+)"', webpage
, 'internal video ID')
214 png_url
= 'http://www.rtve.es/ztnr/movil/thumbnail/default/videos/%s.png' % vidplayer_id
215 png
= self
._download
_webpage
(png_url
, video_id
, 'Downloading url information')
216 video_url
= _decrypt_url(png
)
223 'app': 'rtve-live-live?ovpfv=2.1.2',
224 'player_url': player_url
,