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.

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