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.

202 lines
7.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
  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': r'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': r'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="[^"]*\blist_error\b[^"]*">(.+?)</ul>',
  81. response, 'error', default=None)
  82. if error:
  83. raise ExtractorError(
  84. 'Unable to login: %s' % error, expected=True)
  85. def _real_extract(self, url):
  86. video_id = self._match_id(url)
  87. webpage = self._download_webpage(url, video_id)
  88. episode_id = self._search_regex(
  89. r'episode="([^"]+)"', webpage, 'episode id')
  90. request = sanitized_Request(
  91. self._PLAYER_URL_TEMPLATE % episode_id,
  92. headers={'User-Agent': self._USER_AGENT})
  93. player = self._download_json(request, episode_id, 'Downloading player JSON')
  94. episode_type = player.get('typeOfEpisode')
  95. error_message = self._ERRORS.get(episode_type)
  96. if error_message:
  97. raise ExtractorError(
  98. '%s returned error: %s' % (self.IE_NAME, error_message), expected=True)
  99. formats = []
  100. video_url = player.get('urlVideo')
  101. if video_url:
  102. format_info = {
  103. 'url': video_url,
  104. 'format_id': 'http',
  105. }
  106. mobj = re.search(r'(?P<bitrate>\d+)K_(?P<width>\d+)x(?P<height>\d+)', video_url)
  107. if mobj:
  108. format_info.update({
  109. 'width': int_or_none(mobj.group('width')),
  110. 'height': int_or_none(mobj.group('height')),
  111. 'tbr': int_or_none(mobj.group('bitrate')),
  112. })
  113. formats.append(format_info)
  114. timestamp = int_or_none(self._download_webpage(
  115. self._TIME_API_URL,
  116. video_id, 'Downloading timestamp', fatal=False), 1000, time.time())
  117. timestamp_shifted = compat_str(timestamp + self._TIMESTAMP_SHIFT)
  118. token = hmac.new(
  119. self._MAGIC.encode('ascii'),
  120. (episode_id + timestamp_shifted).encode('utf-8'), hashlib.md5
  121. ).hexdigest()
  122. request = sanitized_Request(
  123. self._URL_VIDEO_TEMPLATE.format('windows', episode_id, timestamp_shifted, token),
  124. headers={'User-Agent': self._USER_AGENT})
  125. fmt_json = self._download_json(
  126. request, video_id, 'Downloading windows video JSON')
  127. result = fmt_json.get('resultDes')
  128. if result.lower() != 'ok':
  129. raise ExtractorError(
  130. '%s returned error: %s' % (self.IE_NAME, result), expected=True)
  131. for format_id, video_url in fmt_json['resultObject'].items():
  132. if format_id == 'token' or not video_url.startswith('http'):
  133. continue
  134. if 'geodeswowsmpra3player' in video_url:
  135. f4m_path = video_url.split('smil:', 1)[-1].split('free_', 1)[0]
  136. f4m_url = 'http://drg.antena3.com/{0}hds/es/sd.f4m'.format(f4m_path)
  137. # this videos are protected by DRM, the f4m downloader doesn't support them
  138. continue
  139. video_url_hd = video_url.replace('free_es', 'es')
  140. formats.extend(self._extract_f4m_formats(
  141. video_url_hd[:-9] + '/manifest.f4m', video_id, f4m_id='hds',
  142. fatal=False))
  143. formats.extend(self._extract_mpd_formats(
  144. video_url_hd[:-9] + '/manifest.mpd', video_id, mpd_id='dash',
  145. fatal=False))
  146. self._sort_formats(formats)
  147. path_data = player.get('pathData')
  148. episode = self._download_xml(
  149. self._EPISODE_URL_TEMPLATE % path_data, video_id,
  150. 'Downloading episode XML')
  151. duration = float_or_none(xpath_text(
  152. episode, './media/asset/info/technical/contentDuration', 'duration'))
  153. art = episode.find('./media/asset/info/art')
  154. title = xpath_text(art, './name', 'title')
  155. description = xpath_text(art, './description', 'description')
  156. thumbnail = xpath_text(episode, './media/asset/files/background', 'thumbnail')
  157. subtitles = {}
  158. subtitle_url = xpath_text(episode, './media/asset/files/subtitle', 'subtitle')
  159. if subtitle_url:
  160. subtitles['es'] = [{
  161. 'ext': 'srt',
  162. 'url': subtitle_url,
  163. }]
  164. return {
  165. 'id': video_id,
  166. 'title': title,
  167. 'description': description,
  168. 'thumbnail': thumbnail,
  169. 'duration': duration,
  170. 'formats': formats,
  171. 'subtitles': subtitles,
  172. }