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:
57 class RTVEALaCartaIE(InfoExtractor):
58 IE_NAME = 'rtve.es:alacarta'
59 IE_DESC = 'RTVE a la carta'
60 _VALID_URL = r'http://www\.rtve\.es/(m/)?alacarta/videos/[^/]+/[^/]+/(?P<id>\d+)'
63 'url': 'http://www.rtve.es/alacarta/videos/balonmano/o-swiss-cup-masculina-final-espana-suecia/2491869/',
64 'md5': '1d49b7e1ca7a7502c56a4bf1b60f1b43',
68 'title': 'Balonmano - Swiss Cup masculina. Final: EspaƱa-Suecia',
71 'note': 'Live stream',
72 'url': 'http://www.rtve.es/alacarta/videos/television/24h-live/1694255/',
78 'skip': 'The f4m manifest can\'t be used yet',
80 'url': 'http://www.rtve.es/m/alacarta/videos/cuentame-como-paso/cuentame-como-paso-t16-ultimo-minuto-nuestra-vida-capitulo-276/2969138/?media=tve',
81 'only_matching': True,
84 def _real_extract(self, url):
85 mobj = re.match(self._VALID_URL, url)
86 video_id = mobj.group('id')
87 info = self._download_json(
88 'http://www.rtve.es/api/videos/%s/config/alacarta_videos.json' % video_id,
89 video_id)['page']['items'][0]
90 png_url = 'http://www.rtve.es/ztnr/movil/thumbnail/default/videos/%s.png' % video_id
91 png = self._download_webpage(png_url, video_id, 'Downloading url information')
92 video_url = _decrypt_url(png)
93 if not video_url.endswith('.f4m'):
94 auth_url = video_url.replace(
95 'resources/', 'auth/resources/'
96 ).replace('.net.rtve', '.multimedia.cdn.rtve')
97 video_path = self._download_webpage(
98 auth_url, video_id, 'Getting video url')
99 # Use mvod.akcdn instead of flash.akamaihd.multimedia.cdn to get
100 # the right Content-Length header and the mp4 format
102 'http://mvod.akcdn.rtve.es/{0}&v=2.6.8'
103 '&fp=MAC%2016,0,0,296&r=MRUGG&g=OEOJWFXNFGCP'.format(video_path)
108 'title': info['title'],
110 'thumbnail': info.get('image'),
115 class RTVELiveIE(InfoExtractor):
116 IE_NAME = 'rtve.es:live'
117 IE_DESC = 'RTVE.es live streams'
118 _VALID_URL = r'http://www\.rtve\.es/(?:deportes/directo|noticias|television)/(?P<id>[a-zA-Z0-9-]+)'
121 'url': 'http://www.rtve.es/noticias/directo-la-1/',
123 'id': 'directo-la-1',
125 'title': 're:^La 1 de TVE [0-9]{4}-[0-9]{2}-[0-9]{2}Z[0-9]{6}$',
128 'skip_download': 'live stream',
132 def _real_extract(self, url):
133 mobj = re.match(self._VALID_URL, url)
134 start_time = time.gmtime()
135 video_id = mobj.group('id')
137 webpage = self._download_webpage(url, video_id)
138 player_url = self._search_regex(
139 r'<param name="movie" value="([^"]+)"/>', webpage, 'player URL')
140 title = remove_end(self._og_search_title(webpage), ' en directo')
141 title += ' ' + time.strftime('%Y-%m-%dZ%H%M%S', start_time)
143 vidplayer_id = self._search_regex(
144 r' id="vidplayer([0-9]+)"', webpage, 'internal video ID')
145 png_url = 'http://www.rtve.es/ztnr/movil/thumbnail/default/videos/%s.png' % vidplayer_id
146 png = self._download_webpage(png_url, video_id, 'Downloading url information')
147 video_url = _decrypt_url(png)
154 'app': 'rtve-live-live?ovpfv=2.1.2',
155 'player_url': player_url,