You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

292 lines
9.8 KiB

Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import base64
  4. import re
  5. import time
  6. from .common import InfoExtractor
  7. from ..compat import (
  8. compat_b64decode,
  9. compat_struct_unpack,
  10. )
  11. from ..utils import (
  12. determine_ext,
  13. ExtractorError,
  14. float_or_none,
  15. remove_end,
  16. remove_start,
  17. sanitized_Request,
  18. std_headers,
  19. )
  20. def _decrypt_url(png):
  21. encrypted_data = compat_b64decode(png)
  22. text_index = encrypted_data.find(b'tEXt')
  23. text_chunk = encrypted_data[text_index - 4:]
  24. length = compat_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:]
  31. if url_data[0] == 'H' and url_data[3] == '%':
  32. # remove useless HQ%% at the start
  33. url_data = url_data[4:]
  34. alphabet = []
  35. e = 0
  36. d = 0
  37. for l in alphabet_data:
  38. if d == 0:
  39. alphabet.append(l)
  40. d = e = (e + 1) % 4
  41. else:
  42. d -= 1
  43. url = ''
  44. f = 0
  45. e = 3
  46. b = 1
  47. for letter in url_data:
  48. if f == 0:
  49. l = int(letter) * 10
  50. f = 1
  51. else:
  52. if e == 0:
  53. l += int(letter)
  54. url += alphabet[l]
  55. e = (b + 3) % 4
  56. f = 0
  57. b += 1
  58. else:
  59. e -= 1
  60. return url
  61. class RTVEALaCartaIE(InfoExtractor):
  62. IE_NAME = 'rtve.es:alacarta'
  63. IE_DESC = 'RTVE a la carta'
  64. _VALID_URL = r'https?://(?:www\.)?rtve\.es/(m/)?(alacarta/videos|filmoteca)/[^/]+/[^/]+/(?P<id>\d+)'
  65. _TESTS = [{
  66. 'url': 'http://www.rtve.es/alacarta/videos/balonmano/o-swiss-cup-masculina-final-espana-suecia/2491869/',
  67. 'md5': '1d49b7e1ca7a7502c56a4bf1b60f1b43',
  68. 'info_dict': {
  69. 'id': '2491869',
  70. 'ext': 'mp4',
  71. 'title': 'Balonmano - Swiss Cup masculina. Final: España-Suecia',
  72. 'duration': 5024.566,
  73. },
  74. }, {
  75. 'note': 'Live stream',
  76. 'url': 'http://www.rtve.es/alacarta/videos/television/24h-live/1694255/',
  77. 'info_dict': {
  78. 'id': '1694255',
  79. 'ext': 'flv',
  80. 'title': 'TODO',
  81. },
  82. 'skip': 'The f4m manifest can\'t be used yet',
  83. }, {
  84. 'url': 'http://www.rtve.es/alacarta/videos/servir-y-proteger/servir-proteger-capitulo-104/4236788/',
  85. 'md5': 'e55e162379ad587e9640eda4f7353c0f',
  86. 'info_dict': {
  87. 'id': '4236788',
  88. 'ext': 'mp4',
  89. 'title': 'Servir y proteger - Capítulo 104 ',
  90. 'duration': 3222.0,
  91. },
  92. 'params': {
  93. 'skip_download': True, # requires ffmpeg
  94. },
  95. }, {
  96. 'url': 'http://www.rtve.es/m/alacarta/videos/cuentame-como-paso/cuentame-como-paso-t16-ultimo-minuto-nuestra-vida-capitulo-276/2969138/?media=tve',
  97. 'only_matching': True,
  98. }, {
  99. 'url': 'http://www.rtve.es/filmoteca/no-do/not-1-introduccion-primer-noticiario-espanol/1465256/',
  100. 'only_matching': True,
  101. }]
  102. def _real_initialize(self):
  103. user_agent_b64 = base64.b64encode(std_headers['User-Agent'].encode('utf-8')).decode('utf-8')
  104. manager_info = self._download_json(
  105. 'http://www.rtve.es/odin/loki/' + user_agent_b64,
  106. None, 'Fetching manager info')
  107. self._manager = manager_info['manager']
  108. def _real_extract(self, url):
  109. mobj = re.match(self._VALID_URL, url)
  110. video_id = mobj.group('id')
  111. info = self._download_json(
  112. 'http://www.rtve.es/api/videos/%s/config/alacarta_videos.json' % video_id,
  113. video_id)['page']['items'][0]
  114. if info['state'] == 'DESPU':
  115. raise ExtractorError('The video is no longer available', expected=True)
  116. title = info['title']
  117. png_url = 'http://www.rtve.es/ztnr/movil/thumbnail/%s/videos/%s.png' % (self._manager, video_id)
  118. png_request = sanitized_Request(png_url)
  119. png_request.add_header('Referer', url)
  120. png = self._download_webpage(png_request, video_id, 'Downloading url information')
  121. video_url = _decrypt_url(png)
  122. ext = determine_ext(video_url)
  123. formats = []
  124. if not video_url.endswith('.f4m') and ext != 'm3u8':
  125. if '?' not in video_url:
  126. video_url = video_url.replace('resources/', 'auth/resources/')
  127. video_url = video_url.replace('.net.rtve', '.multimedia.cdn.rtve')
  128. if ext == 'm3u8':
  129. formats.extend(self._extract_m3u8_formats(
  130. video_url, video_id, ext='mp4', entry_protocol='m3u8_native',
  131. m3u8_id='hls', fatal=False))
  132. elif ext == 'f4m':
  133. formats.extend(self._extract_f4m_formats(
  134. video_url, video_id, f4m_id='hds', fatal=False))
  135. else:
  136. formats.append({
  137. 'url': video_url,
  138. })
  139. self._sort_formats(formats)
  140. subtitles = None
  141. if info.get('sbtFile') is not None:
  142. subtitles = self.extract_subtitles(video_id, info['sbtFile'])
  143. return {
  144. 'id': video_id,
  145. 'title': title,
  146. 'formats': formats,
  147. 'thumbnail': info.get('image'),
  148. 'page_url': url,
  149. 'subtitles': subtitles,
  150. 'duration': float_or_none(info.get('duration'), scale=1000),
  151. }
  152. def _get_subtitles(self, video_id, sub_file):
  153. subs = self._download_json(
  154. sub_file + '.json', video_id,
  155. 'Downloading subtitles info')['page']['items']
  156. return dict(
  157. (s['lang'], [{'ext': 'vtt', 'url': s['src']}])
  158. for s in subs)
  159. class RTVEInfantilIE(InfoExtractor):
  160. IE_NAME = 'rtve.es:infantil'
  161. IE_DESC = 'RTVE infantil'
  162. _VALID_URL = r'https?://(?:www\.)?rtve\.es/infantil/serie/(?P<show>[^/]*)/video/(?P<short_title>[^/]*)/(?P<id>[0-9]+)/'
  163. _TESTS = [{
  164. 'url': 'http://www.rtve.es/infantil/serie/cleo/video/maneras-vivir/3040283/',
  165. 'md5': '915319587b33720b8e0357caaa6617e6',
  166. 'info_dict': {
  167. 'id': '3040283',
  168. 'ext': 'mp4',
  169. 'title': 'Maneras de vivir',
  170. 'thumbnail': 'http://www.rtve.es/resources/jpg/6/5/1426182947956.JPG',
  171. 'duration': 357.958,
  172. },
  173. }]
  174. def _real_extract(self, url):
  175. video_id = self._match_id(url)
  176. info = self._download_json(
  177. 'http://www.rtve.es/api/videos/%s/config/alacarta_videos.json' % video_id,
  178. video_id)['page']['items'][0]
  179. webpage = self._download_webpage(url, video_id)
  180. vidplayer_id = self._search_regex(
  181. r' id="vidplayer([0-9]+)"', webpage, 'internal video ID')
  182. png_url = 'http://www.rtve.es/ztnr/movil/thumbnail/default/videos/%s.png' % vidplayer_id
  183. png = self._download_webpage(png_url, video_id, 'Downloading url information')
  184. video_url = _decrypt_url(png)
  185. return {
  186. 'id': video_id,
  187. 'ext': 'mp4',
  188. 'title': info['title'],
  189. 'url': video_url,
  190. 'thumbnail': info.get('image'),
  191. 'duration': float_or_none(info.get('duration'), scale=1000),
  192. }
  193. class RTVELiveIE(InfoExtractor):
  194. IE_NAME = 'rtve.es:live'
  195. IE_DESC = 'RTVE.es live streams'
  196. _VALID_URL = r'https?://(?:www\.)?rtve\.es/directo/(?P<id>[a-zA-Z0-9-]+)'
  197. _TESTS = [{
  198. 'url': 'http://www.rtve.es/directo/la-1/',
  199. 'info_dict': {
  200. 'id': 'la-1',
  201. 'ext': 'mp4',
  202. 'title': 're:^La 1 [0-9]{4}-[0-9]{2}-[0-9]{2}Z[0-9]{6}$',
  203. },
  204. 'params': {
  205. 'skip_download': 'live stream',
  206. }
  207. }]
  208. def _real_extract(self, url):
  209. mobj = re.match(self._VALID_URL, url)
  210. start_time = time.gmtime()
  211. video_id = mobj.group('id')
  212. webpage = self._download_webpage(url, video_id)
  213. title = remove_end(self._og_search_title(webpage), ' en directo en RTVE.es')
  214. title = remove_start(title, 'Estoy viendo ')
  215. title += ' ' + time.strftime('%Y-%m-%dZ%H%M%S', start_time)
  216. vidplayer_id = self._search_regex(
  217. (r'playerId=player([0-9]+)',
  218. r'class=["\'].*?\blive_mod\b.*?["\'][^>]+data-assetid=["\'](\d+)',
  219. r'data-id=["\'](\d+)'),
  220. webpage, 'internal video ID')
  221. png_url = 'http://www.rtve.es/ztnr/movil/thumbnail/amonet/videos/%s.png' % vidplayer_id
  222. png = self._download_webpage(png_url, video_id, 'Downloading url information')
  223. m3u8_url = _decrypt_url(png)
  224. formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4')
  225. self._sort_formats(formats)
  226. return {
  227. 'id': video_id,
  228. 'title': title,
  229. 'formats': formats,
  230. 'is_live': True,
  231. }
  232. class RTVETelevisionIE(InfoExtractor):
  233. IE_NAME = 'rtve.es:television'
  234. _VALID_URL = r'https?://(?:www\.)?rtve\.es/television/[^/]+/[^/]+/(?P<id>\d+).shtml'
  235. _TEST = {
  236. 'url': 'http://www.rtve.es/television/20160628/revolucion-del-movil/1364141.shtml',
  237. 'info_dict': {
  238. 'id': '3069778',
  239. 'ext': 'mp4',
  240. 'title': 'Documentos TV - La revolución del móvil',
  241. 'duration': 3496.948,
  242. },
  243. 'params': {
  244. 'skip_download': True,
  245. },
  246. }
  247. def _real_extract(self, url):
  248. page_id = self._match_id(url)
  249. webpage = self._download_webpage(url, page_id)
  250. alacarta_url = self._search_regex(
  251. r'data-location="alacarta_videos"[^<]+url&quot;:&quot;(http://www\.rtve\.es/alacarta.+?)&',
  252. webpage, 'alacarta url', default=None)
  253. if alacarta_url is None:
  254. raise ExtractorError(
  255. 'The webpage doesn\'t contain any video', expected=True)
  256. return self.url_result(alacarta_url, ie=RTVEALaCartaIE.ie_key())