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.

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