]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/rtve.py
2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
15 def _decrypt_url(png
):
16 encrypted_data
= base64
.b64decode(png
)
17 text_index
= encrypted_data
.find(b
'tEXt')
18 text_chunk
= encrypted_data
[text_index
- 4:]
19 length
= struct_unpack('!I', text_chunk
[:4])[0]
20 # Use bytearray to get integers when iterating in both python 2.x and 3.x
21 data
= bytearray(text_chunk
[8:8 + length
])
22 data
= [chr(b
) for b
in data
if b
!= 0]
23 hash_index
= data
.index('#')
24 alphabet_data
= data
[:hash_index
]
25 url_data
= data
[hash_index
+ 1:]
30 for l
in alphabet_data
:
40 for letter
in url_data
:
58 class RTVEALaCartaIE(InfoExtractor
):
59 IE_NAME
= 'rtve.es:alacarta'
60 IE_DESC
= 'RTVE a la carta'
61 _VALID_URL
= r
'http://www\.rtve\.es/alacarta/videos/[^/]+/[^/]+/(?P<id>\d+)'
64 'url': 'http://www.rtve.es/alacarta/videos/balonmano/o-swiss-cup-masculina-final-espana-suecia/2491869/',
65 'md5': '1d49b7e1ca7a7502c56a4bf1b60f1b43',
69 'title': 'Balonmano - Swiss Cup masculina. Final: España-Suecia',
72 'note': 'Live stream',
73 'url': 'http://www.rtve.es/alacarta/videos/television/24h-live/1694255/',
81 def _real_extract(self
, url
):
82 mobj
= re
.match(self
._VALID
_URL
, url
)
83 video_id
= mobj
.group('id')
84 info
= self
._download
_json
(
85 'http://www.rtve.es/api/videos/%s/config/alacarta_videos.json' % video_id
,
86 video_id
)['page']['items'][0]
87 png_url
= 'http://www.rtve.es/ztnr/movil/thumbnail/default/videos/%s.png' % video_id
88 png
= self
._download
_webpage
(png_url
, video_id
, 'Downloading url information')
89 video_url
= _decrypt_url(png
)
93 'title': info
['title'],
95 'thumbnail': info
.get('image'),
100 class RTVELiveIE(InfoExtractor
):
101 IE_NAME
= 'rtve.es:live'
102 IE_DESC
= 'RTVE.es live streams'
103 _VALID_URL
= r
'http://www\.rtve\.es/(?:deportes/directo|noticias|television)/(?P<id>[a-zA-Z0-9-]+)'
106 'url': 'http://www.rtve.es/noticias/directo-la-1/',
108 'id': 'directo-la-1',
110 'title': 're:^La 1 de TVE [0-9]{4}-[0-9]{2}-[0-9]{2}Z[0-9]{6}$',
113 'skip_download': 'live stream',
117 def _real_extract(self
, url
):
118 mobj
= re
.match(self
._VALID
_URL
, url
)
119 start_time
= time
.gmtime()
120 video_id
= mobj
.group('id')
122 webpage
= self
._download
_webpage
(url
, video_id
)
123 player_url
= self
._search
_regex
(
124 r
'<param name="movie" value="([^"]+)"/>', webpage
, 'player URL')
125 title
= remove_end(self
._og
_search
_title
(webpage
), ' en directo')
126 title
+= ' ' + time
.strftime('%Y-%m-%dZ%H%M%S', start_time
)
128 vidplayer_id
= self
._search
_regex
(
129 r
' id="vidplayer([0-9]+)"', webpage
, 'internal video ID')
130 png_url
= 'http://www.rtve.es/ztnr/movil/thumbnail/default/videos/%s.png' % vidplayer_id
131 png
= self
._download
_webpage
(png_url
, video_id
, 'Downloading url information')
132 video_url
= _decrypt_url(png
)
139 'app': 'rtve-live-live?ovpfv=2.1.2',
140 'player_url': player_url
,