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.

255 lines
8.6 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. # encoding: 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_struct_unpack,
  9. )
  10. from ..utils import (
  11. ExtractorError,
  12. float_or_none,
  13. remove_end,
  14. remove_start,
  15. sanitized_Request,
  16. std_headers,
  17. )
  18. def _decrypt_url(png):
  19. encrypted_data = base64.b64decode(png.encode('utf-8'))
  20. text_index = encrypted_data.find(b'tEXt')
  21. text_chunk = encrypted_data[text_index - 4:]
  22. length = compat_struct_unpack('!I', text_chunk[:4])[0]
  23. # Use bytearray to get integers when iterating in both python 2.x and 3.x
  24. data = bytearray(text_chunk[8:8 + length])
  25. data = [chr(b) for b in data if b != 0]
  26. hash_index = data.index('#')
  27. alphabet_data = data[:hash_index]
  28. url_data = data[hash_index + 1:]
  29. alphabet = []
  30. e = 0
  31. d = 0
  32. for l in alphabet_data:
  33. if d == 0:
  34. alphabet.append(l)
  35. d = e = (e + 1) % 4
  36. else:
  37. d -= 1
  38. url = ''
  39. f = 0
  40. e = 3
  41. b = 1
  42. for letter in url_data:
  43. if f == 0:
  44. l = int(letter) * 10
  45. f = 1
  46. else:
  47. if e == 0:
  48. l += int(letter)
  49. url += alphabet[l]
  50. e = (b + 3) % 4
  51. f = 0
  52. b += 1
  53. else:
  54. e -= 1
  55. return url
  56. class RTVEALaCartaIE(InfoExtractor):
  57. IE_NAME = 'rtve.es:alacarta'
  58. IE_DESC = 'RTVE a la carta'
  59. _VALID_URL = r'https?://www\.rtve\.es/(m/)?(alacarta/videos|filmoteca)/[^/]+/[^/]+/(?P<id>\d+)'
  60. _TESTS = [{
  61. 'url': 'http://www.rtve.es/alacarta/videos/balonmano/o-swiss-cup-masculina-final-espana-suecia/2491869/',
  62. 'md5': '1d49b7e1ca7a7502c56a4bf1b60f1b43',
  63. 'info_dict': {
  64. 'id': '2491869',
  65. 'ext': 'mp4',
  66. 'title': 'Balonmano - Swiss Cup masculina. Final: España-Suecia',
  67. 'duration': 5024.566,
  68. },
  69. }, {
  70. 'note': 'Live stream',
  71. 'url': 'http://www.rtve.es/alacarta/videos/television/24h-live/1694255/',
  72. 'info_dict': {
  73. 'id': '1694255',
  74. 'ext': 'flv',
  75. 'title': 'TODO',
  76. },
  77. 'skip': 'The f4m manifest can\'t be used yet',
  78. }, {
  79. 'url': 'http://www.rtve.es/m/alacarta/videos/cuentame-como-paso/cuentame-como-paso-t16-ultimo-minuto-nuestra-vida-capitulo-276/2969138/?media=tve',
  80. 'only_matching': True,
  81. }, {
  82. 'url': 'http://www.rtve.es/filmoteca/no-do/not-1-introduccion-primer-noticiario-espanol/1465256/',
  83. 'only_matching': True,
  84. }]
  85. def _real_initialize(self):
  86. user_agent_b64 = base64.b64encode(std_headers['User-Agent'].encode('utf-8')).decode('utf-8')
  87. manager_info = self._download_json(
  88. 'http://www.rtve.es/odin/loki/' + user_agent_b64,
  89. None, 'Fetching manager info')
  90. self._manager = manager_info['manager']
  91. def _real_extract(self, url):
  92. mobj = re.match(self._VALID_URL, url)
  93. video_id = mobj.group('id')
  94. info = self._download_json(
  95. 'http://www.rtve.es/api/videos/%s/config/alacarta_videos.json' % video_id,
  96. video_id)['page']['items'][0]
  97. if info['state'] == 'DESPU':
  98. raise ExtractorError('The video is no longer available', expected=True)
  99. png_url = 'http://www.rtve.es/ztnr/movil/thumbnail/%s/videos/%s.png' % (self._manager, video_id)
  100. png_request = sanitized_Request(png_url)
  101. png_request.add_header('Referer', url)
  102. png = self._download_webpage(png_request, video_id, 'Downloading url information')
  103. video_url = _decrypt_url(png)
  104. if not video_url.endswith('.f4m'):
  105. if '?' not in video_url:
  106. video_url = video_url.replace('resources/', 'auth/resources/')
  107. video_url = video_url.replace('.net.rtve', '.multimedia.cdn.rtve')
  108. subtitles = None
  109. if info.get('sbtFile') is not None:
  110. subtitles = self.extract_subtitles(video_id, info['sbtFile'])
  111. return {
  112. 'id': video_id,
  113. 'title': info['title'],
  114. 'url': video_url,
  115. 'thumbnail': info.get('image'),
  116. 'page_url': url,
  117. 'subtitles': subtitles,
  118. 'duration': float_or_none(info.get('duration'), scale=1000),
  119. }
  120. def _get_subtitles(self, video_id, sub_file):
  121. subs = self._download_json(
  122. sub_file + '.json', video_id,
  123. 'Downloading subtitles info')['page']['items']
  124. return dict(
  125. (s['lang'], [{'ext': 'vtt', 'url': s['src']}])
  126. for s in subs)
  127. class RTVEInfantilIE(InfoExtractor):
  128. IE_NAME = 'rtve.es:infantil'
  129. IE_DESC = 'RTVE infantil'
  130. _VALID_URL = r'https?://(?:www\.)?rtve\.es/infantil/serie/(?P<show>[^/]*)/video/(?P<short_title>[^/]*)/(?P<id>[0-9]+)/'
  131. _TESTS = [{
  132. 'url': 'http://www.rtve.es/infantil/serie/cleo/video/maneras-vivir/3040283/',
  133. 'md5': '915319587b33720b8e0357caaa6617e6',
  134. 'info_dict': {
  135. 'id': '3040283',
  136. 'ext': 'mp4',
  137. 'title': 'Maneras de vivir',
  138. 'thumbnail': 'http://www.rtve.es/resources/jpg/6/5/1426182947956.JPG',
  139. 'duration': 357.958,
  140. },
  141. }]
  142. def _real_extract(self, url):
  143. video_id = self._match_id(url)
  144. info = self._download_json(
  145. 'http://www.rtve.es/api/videos/%s/config/alacarta_videos.json' % video_id,
  146. video_id)['page']['items'][0]
  147. webpage = self._download_webpage(url, video_id)
  148. vidplayer_id = self._search_regex(
  149. r' id="vidplayer([0-9]+)"', webpage, 'internal video ID')
  150. png_url = 'http://www.rtve.es/ztnr/movil/thumbnail/default/videos/%s.png' % vidplayer_id
  151. png = self._download_webpage(png_url, video_id, 'Downloading url information')
  152. video_url = _decrypt_url(png)
  153. return {
  154. 'id': video_id,
  155. 'ext': 'mp4',
  156. 'title': info['title'],
  157. 'url': video_url,
  158. 'thumbnail': info.get('image'),
  159. 'duration': float_or_none(info.get('duration'), scale=1000),
  160. }
  161. class RTVELiveIE(InfoExtractor):
  162. IE_NAME = 'rtve.es:live'
  163. IE_DESC = 'RTVE.es live streams'
  164. _VALID_URL = r'https?://www\.rtve\.es/directo/(?P<id>[a-zA-Z0-9-]+)'
  165. _TESTS = [{
  166. 'url': 'http://www.rtve.es/directo/la-1/',
  167. 'info_dict': {
  168. 'id': 'la-1',
  169. 'ext': 'mp4',
  170. 'title': 're:^La 1 [0-9]{4}-[0-9]{2}-[0-9]{2}Z[0-9]{6}$',
  171. },
  172. 'params': {
  173. 'skip_download': 'live stream',
  174. }
  175. }]
  176. def _real_extract(self, url):
  177. mobj = re.match(self._VALID_URL, url)
  178. start_time = time.gmtime()
  179. video_id = mobj.group('id')
  180. webpage = self._download_webpage(url, video_id)
  181. title = remove_end(self._og_search_title(webpage), ' en directo en RTVE.es')
  182. title = remove_start(title, 'Estoy viendo ')
  183. title += ' ' + time.strftime('%Y-%m-%dZ%H%M%S', start_time)
  184. vidplayer_id = self._search_regex(
  185. r'playerId=player([0-9]+)', webpage, 'internal video ID')
  186. png_url = 'http://www.rtve.es/ztnr/movil/thumbnail/amonet/videos/%s.png' % vidplayer_id
  187. png = self._download_webpage(png_url, video_id, 'Downloading url information')
  188. m3u8_url = _decrypt_url(png)
  189. formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4')
  190. self._sort_formats(formats)
  191. return {
  192. 'id': video_id,
  193. 'title': title,
  194. 'formats': formats,
  195. 'is_live': True,
  196. }
  197. class RTVETelevisionIE(InfoExtractor):
  198. IE_NAME = 'rtve.es:television'
  199. _VALID_URL = r'https?://www\.rtve\.es/television/[^/]+/[^/]+/(?P<id>\d+).shtml'
  200. _TEST = {
  201. 'url': 'http://www.rtve.es/television/20160628/revolucion-del-movil/1364141.shtml',
  202. 'info_dict': {
  203. 'id': '3069778',
  204. 'ext': 'mp4',
  205. 'title': 'Documentos TV - La revolución del móvil',
  206. 'duration': 3496.948,
  207. },
  208. 'params': {
  209. 'skip_download': True,
  210. },
  211. }
  212. def _real_extract(self, url):
  213. page_id = self._match_id(url)
  214. webpage = self._download_webpage(url, page_id)
  215. alacarta_url = self._search_regex(
  216. r'data-location="alacarta_videos"[^<]+url&quot;:&quot;(http://www\.rtve\.es/alacarta.+?)&',
  217. webpage, 'alacarta url', default=None)
  218. if alacarta_url is None:
  219. raise ExtractorError(
  220. 'The webpage doesn\'t contain any video', expected=True)
  221. return self.url_result(alacarta_url, ie=RTVEALaCartaIE.ie_key())