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.

199 lines
7.5 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
  1. from __future__ import unicode_literals
  2. import time
  3. import hmac
  4. import hashlib
  5. import re
  6. from .common import InfoExtractor
  7. from ..compat import (
  8. compat_str,
  9. compat_urllib_parse,
  10. )
  11. from ..utils import (
  12. int_or_none,
  13. float_or_none,
  14. sanitized_Request,
  15. xpath_text,
  16. ExtractorError,
  17. )
  18. class AtresPlayerIE(InfoExtractor):
  19. _VALID_URL = r'https?://(?:www\.)?atresplayer\.com/television/[^/]+/[^/]+/[^/]+/(?P<id>.+?)_\d+\.html'
  20. _NETRC_MACHINE = 'atresplayer'
  21. _TESTS = [
  22. {
  23. 'url': 'http://www.atresplayer.com/television/programas/el-club-de-la-comedia/temporada-4/capitulo-10-especial-solidario-nochebuena_2014122100174.html',
  24. 'md5': 'efd56753cda1bb64df52a3074f62e38a',
  25. 'info_dict': {
  26. 'id': 'capitulo-10-especial-solidario-nochebuena',
  27. 'ext': 'mp4',
  28. 'title': 'Especial Solidario de Nochebuena',
  29. 'description': 'md5:e2d52ff12214fa937107d21064075bf1',
  30. 'duration': 5527.6,
  31. 'thumbnail': 're:^https?://.*\.jpg$',
  32. },
  33. 'skip': 'This video is only available for registered users'
  34. },
  35. {
  36. 'url': 'http://www.atresplayer.com/television/especial/videoencuentros/temporada-1/capitulo-112-david-bustamante_2014121600375.html',
  37. 'md5': '0d0e918533bbd4b263f2de4d197d4aac',
  38. 'info_dict': {
  39. 'id': 'capitulo-112-david-bustamante',
  40. 'ext': 'flv',
  41. 'title': 'David Bustamante',
  42. 'description': 'md5:f33f1c0a05be57f6708d4dd83a3b81c6',
  43. 'duration': 1439.0,
  44. 'thumbnail': 're:^https?://.*\.jpg$',
  45. },
  46. },
  47. {
  48. 'url': 'http://www.atresplayer.com/television/series/el-secreto-de-puente-viejo/el-chico-de-los-tres-lunares/capitulo-977-29-12-14_2014122400174.html',
  49. 'only_matching': True,
  50. },
  51. ]
  52. _USER_AGENT = 'Dalvik/1.6.0 (Linux; U; Android 4.3; GT-I9300 Build/JSS15J'
  53. _MAGIC = 'QWtMLXs414Yo+c#_+Q#K@NN)'
  54. _TIMESTAMP_SHIFT = 30000
  55. _TIME_API_URL = 'http://servicios.atresplayer.com/api/admin/time.json'
  56. _URL_VIDEO_TEMPLATE = 'https://servicios.atresplayer.com/api/urlVideo/{1}/{0}/{1}|{2}|{3}.json'
  57. _PLAYER_URL_TEMPLATE = 'https://servicios.atresplayer.com/episode/getplayer.json?episodePk=%s'
  58. _EPISODE_URL_TEMPLATE = 'http://www.atresplayer.com/episodexml/%s'
  59. _LOGIN_URL = 'https://servicios.atresplayer.com/j_spring_security_check'
  60. _ERRORS = {
  61. 'UNPUBLISHED': 'We\'re sorry, but this video is not yet available.',
  62. 'DELETED': 'This video has expired and is no longer available for online streaming.',
  63. 'GEOUNPUBLISHED': 'We\'re sorry, but this video is not available in your region due to right restrictions.',
  64. # 'PREMIUM': 'PREMIUM',
  65. }
  66. def _real_initialize(self):
  67. self._login()
  68. def _login(self):
  69. (username, password) = self._get_login_info()
  70. if username is None:
  71. return
  72. login_form = {
  73. 'j_username': username,
  74. 'j_password': password,
  75. }
  76. request = sanitized_Request(
  77. self._LOGIN_URL, compat_urllib_parse.urlencode(login_form).encode('utf-8'))
  78. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  79. response = self._download_webpage(
  80. request, None, 'Logging in as %s' % username)
  81. error = self._html_search_regex(
  82. r'(?s)<ul class="list_error">(.+?)</ul>', response, 'error', default=None)
  83. if error:
  84. raise ExtractorError(
  85. 'Unable to login: %s' % error, expected=True)
  86. def _real_extract(self, url):
  87. video_id = self._match_id(url)
  88. webpage = self._download_webpage(url, video_id)
  89. episode_id = self._search_regex(
  90. r'episode="([^"]+)"', webpage, 'episode id')
  91. request = sanitized_Request(
  92. self._PLAYER_URL_TEMPLATE % episode_id,
  93. headers={'User-Agent': self._USER_AGENT})
  94. player = self._download_json(request, episode_id, 'Downloading player JSON')
  95. episode_type = player.get('typeOfEpisode')
  96. error_message = self._ERRORS.get(episode_type)
  97. if error_message:
  98. raise ExtractorError(
  99. '%s returned error: %s' % (self.IE_NAME, error_message), expected=True)
  100. formats = []
  101. video_url = player.get('urlVideo')
  102. if video_url:
  103. format_info = {
  104. 'url': video_url,
  105. 'format_id': 'http',
  106. }
  107. mobj = re.search(r'(?P<bitrate>\d+)K_(?P<width>\d+)x(?P<height>\d+)', video_url)
  108. if mobj:
  109. format_info.update({
  110. 'width': int_or_none(mobj.group('width')),
  111. 'height': int_or_none(mobj.group('height')),
  112. 'tbr': int_or_none(mobj.group('bitrate')),
  113. })
  114. formats.append(format_info)
  115. timestamp = int_or_none(self._download_webpage(
  116. self._TIME_API_URL,
  117. video_id, 'Downloading timestamp', fatal=False), 1000, time.time())
  118. timestamp_shifted = compat_str(timestamp + self._TIMESTAMP_SHIFT)
  119. token = hmac.new(
  120. self._MAGIC.encode('ascii'),
  121. (episode_id + timestamp_shifted).encode('utf-8'), hashlib.md5
  122. ).hexdigest()
  123. request = sanitized_Request(
  124. self._URL_VIDEO_TEMPLATE.format('windows', episode_id, timestamp_shifted, token),
  125. headers={'User-Agent': self._USER_AGENT})
  126. fmt_json = self._download_json(
  127. request, video_id, 'Downloading windows video JSON')
  128. result = fmt_json.get('resultDes')
  129. if result.lower() != 'ok':
  130. raise ExtractorError(
  131. '%s returned error: %s' % (self.IE_NAME, result), expected=True)
  132. for format_id, video_url in fmt_json['resultObject'].items():
  133. if format_id == 'token' or not video_url.startswith('http'):
  134. continue
  135. if 'geodeswowsmpra3player' in video_url:
  136. f4m_path = video_url.split('smil:', 1)[-1].split('free_', 1)[0]
  137. f4m_url = 'http://drg.antena3.com/{0}hds/es/sd.f4m'.format(f4m_path)
  138. # this videos are protected by DRM, the f4m downloader doesn't support them
  139. continue
  140. else:
  141. f4m_url = video_url[:-9] + '/manifest.f4m'
  142. formats.extend(self._extract_f4m_formats(f4m_url, video_id, f4m_id='hds', fatal=False))
  143. self._sort_formats(formats)
  144. path_data = player.get('pathData')
  145. episode = self._download_xml(
  146. self._EPISODE_URL_TEMPLATE % path_data, video_id,
  147. 'Downloading episode XML')
  148. duration = float_or_none(xpath_text(
  149. episode, './media/asset/info/technical/contentDuration', 'duration'))
  150. art = episode.find('./media/asset/info/art')
  151. title = xpath_text(art, './name', 'title')
  152. description = xpath_text(art, './description', 'description')
  153. thumbnail = xpath_text(episode, './media/asset/files/background', 'thumbnail')
  154. subtitles = {}
  155. subtitle_url = xpath_text(episode, './media/asset/files/subtitle', 'subtitle')
  156. if subtitle_url:
  157. subtitles['es'] = [{
  158. 'ext': 'srt',
  159. 'url': subtitle_url,
  160. }]
  161. return {
  162. 'id': video_id,
  163. 'title': title,
  164. 'description': description,
  165. 'thumbnail': thumbnail,
  166. 'duration': duration,
  167. 'formats': formats,
  168. 'subtitles': subtitles,
  169. }