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.

257 lines
9.2 KiB

12 years ago
12 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
12 years ago
12 years ago
12 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 re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_etree_fromstring,
  6. compat_urlparse,
  7. )
  8. from ..utils import (
  9. ExtractorError,
  10. int_or_none,
  11. sanitized_Request,
  12. )
  13. class VevoIE(InfoExtractor):
  14. """
  15. Accepts urls from vevo.com or in the format 'vevo:{id}'
  16. (currently used by MTVIE and MySpaceIE)
  17. """
  18. _VALID_URL = r'''(?x)
  19. (?:https?://www\.vevo\.com/watch/(?:[^/]+/(?:[^/]+/)?)?|
  20. https?://cache\.vevo\.com/m/html/embed\.html\?video=|
  21. https?://videoplayer\.vevo\.com/embed/embedded\?videoId=|
  22. vevo:)
  23. (?P<id>[^&?#]+)'''
  24. _TESTS = [{
  25. 'url': 'http://www.vevo.com/watch/hurts/somebody-to-die-for/GB1101300280',
  26. "md5": "95ee28ee45e70130e3ab02b0f579ae23",
  27. 'info_dict': {
  28. 'id': 'GB1101300280',
  29. 'ext': 'mp4',
  30. "upload_date": "20130624",
  31. "uploader": "Hurts",
  32. "title": "Somebody to Die For",
  33. "duration": 230.12,
  34. "width": 1920,
  35. "height": 1080,
  36. # timestamp and upload_date are often incorrect; seem to change randomly
  37. 'timestamp': int,
  38. }
  39. }, {
  40. 'note': 'v3 SMIL format',
  41. 'url': 'http://www.vevo.com/watch/cassadee-pope/i-wish-i-could-break-your-heart/USUV71302923',
  42. 'md5': 'f6ab09b034f8c22969020b042e5ac7fc',
  43. 'info_dict': {
  44. 'id': 'USUV71302923',
  45. 'ext': 'mp4',
  46. 'upload_date': '20140219',
  47. 'uploader': 'Cassadee Pope',
  48. 'title': 'I Wish I Could Break Your Heart',
  49. 'duration': 226.101,
  50. 'age_limit': 0,
  51. 'timestamp': int,
  52. }
  53. }, {
  54. 'note': 'Age-limited video',
  55. 'url': 'https://www.vevo.com/watch/justin-timberlake/tunnel-vision-explicit/USRV81300282',
  56. 'info_dict': {
  57. 'id': 'USRV81300282',
  58. 'ext': 'mp4',
  59. 'age_limit': 18,
  60. 'title': 'Tunnel Vision (Explicit)',
  61. 'uploader': 'Justin Timberlake',
  62. 'upload_date': 're:2013070[34]',
  63. 'timestamp': int,
  64. },
  65. 'params': {
  66. 'skip_download': 'true',
  67. }
  68. }, {
  69. 'note': 'No video_info',
  70. 'url': 'http://www.vevo.com/watch/k-camp-1/Till-I-Die/USUV71503000',
  71. 'md5': '8b83cc492d72fc9cf74a02acee7dc1b0',
  72. 'info_dict': {
  73. 'id': 'USUV71503000',
  74. 'ext': 'mp4',
  75. 'title': 'Till I Die - K Camp ft. T.I.',
  76. 'duration': 193,
  77. },
  78. 'expected_warnings': ['Unable to download SMIL file'],
  79. }]
  80. _SMIL_BASE_URL = 'http://smil.lvl3.vevo.com/'
  81. def _real_initialize(self):
  82. req = sanitized_Request(
  83. 'http://www.vevo.com/auth', data=b'')
  84. webpage = self._download_webpage(
  85. req, None,
  86. note='Retrieving oauth token',
  87. errnote='Unable to retrieve oauth token',
  88. fatal=False)
  89. if webpage is False:
  90. self._oauth_token = None
  91. else:
  92. if 'THIS PAGE IS CURRENTLY UNAVAILABLE IN YOUR REGION' in webpage:
  93. raise ExtractorError('%s said: This page is currently unavailable in your region.' % self.IE_NAME, expected=True)
  94. self._oauth_token = self._search_regex(
  95. r'access_token":\s*"([^"]+)"',
  96. webpage, 'access token', fatal=False)
  97. def _formats_from_json(self, video_info):
  98. if not video_info:
  99. return []
  100. last_version = {'version': -1}
  101. for version in video_info['videoVersions']:
  102. # These are the HTTP downloads, other types are for different manifests
  103. if version['sourceType'] == 2:
  104. if version['version'] > last_version['version']:
  105. last_version = version
  106. if last_version['version'] == -1:
  107. raise ExtractorError('Unable to extract last version of the video')
  108. renditions = compat_etree_fromstring(last_version['data'])
  109. formats = []
  110. # Already sorted from worst to best quality
  111. for rend in renditions.findall('rendition'):
  112. attr = rend.attrib
  113. format_note = '%(videoCodec)s@%(videoBitrate)4sk, %(audioCodec)s@%(audioBitrate)3sk' % attr
  114. formats.append({
  115. 'url': attr['url'],
  116. 'format_id': attr['name'],
  117. 'format_note': format_note,
  118. 'height': int(attr['frameheight']),
  119. 'width': int(attr['frameWidth']),
  120. })
  121. return formats
  122. def _formats_from_smil(self, smil_doc):
  123. formats = []
  124. els = smil_doc.findall('.//{http://www.w3.org/2001/SMIL20/Language}video')
  125. for el in els:
  126. src = el.attrib['src']
  127. m = re.match(r'''(?xi)
  128. (?P<ext>[a-z0-9]+):
  129. (?P<path>
  130. [/a-z0-9]+ # The directory and main part of the URL
  131. _(?P<cbr>[0-9]+)k
  132. _(?P<width>[0-9]+)x(?P<height>[0-9]+)
  133. _(?P<vcodec>[a-z0-9]+)
  134. _(?P<vbr>[0-9]+)
  135. _(?P<acodec>[a-z0-9]+)
  136. _(?P<abr>[0-9]+)
  137. \.[a-z0-9]+ # File extension
  138. )''', src)
  139. if not m:
  140. continue
  141. format_url = self._SMIL_BASE_URL + m.group('path')
  142. formats.append({
  143. 'url': format_url,
  144. 'format_id': 'SMIL_' + m.group('cbr'),
  145. 'vcodec': m.group('vcodec'),
  146. 'acodec': m.group('acodec'),
  147. 'vbr': int(m.group('vbr')),
  148. 'abr': int(m.group('abr')),
  149. 'ext': m.group('ext'),
  150. 'width': int(m.group('width')),
  151. 'height': int(m.group('height')),
  152. })
  153. return formats
  154. def _download_api_formats(self, video_id, video_url):
  155. if not self._oauth_token:
  156. self._downloader.report_warning(
  157. 'No oauth token available, skipping API HLS download')
  158. return []
  159. api_url = compat_urlparse.urljoin(video_url, '//apiv2.vevo.com/video/%s/streams/hls?token=%s' % (
  160. video_id, self._oauth_token))
  161. api_data = self._download_json(
  162. api_url, video_id,
  163. note='Downloading HLS formats',
  164. errnote='Failed to download HLS format list', fatal=False)
  165. if api_data is None:
  166. return []
  167. m3u8_url = api_data[0]['url']
  168. return self._extract_m3u8_formats(
  169. m3u8_url, video_id, entry_protocol='m3u8_native', ext='mp4',
  170. preference=0)
  171. def _real_extract(self, url):
  172. video_id = self._match_id(url)
  173. webpage = None
  174. json_url = 'http://videoplayer.vevo.com/VideoService/AuthenticateVideo?isrc=%s' % video_id
  175. response = self._download_json(json_url, video_id)
  176. video_info = response['video'] or {}
  177. if not video_info and response.get('statusCode') != 909:
  178. if 'statusMessage' in response:
  179. raise ExtractorError('%s said: %s' % (self.IE_NAME, response['statusMessage']), expected=True)
  180. raise ExtractorError('Unable to extract videos')
  181. if not video_info:
  182. if url.startswith('vevo:'):
  183. raise ExtractorError('Please specify full Vevo URL for downloading', expected=True)
  184. webpage = self._download_webpage(url, video_id)
  185. title = video_info.get('title') or self._og_search_title(webpage)
  186. formats = self._formats_from_json(video_info)
  187. is_explicit = video_info.get('isExplicit')
  188. if is_explicit is True:
  189. age_limit = 18
  190. elif is_explicit is False:
  191. age_limit = 0
  192. else:
  193. age_limit = None
  194. # Download via HLS API
  195. formats.extend(self._download_api_formats(video_id, url))
  196. # Download SMIL
  197. smil_blocks = sorted((
  198. f for f in video_info.get('videoVersions', [])
  199. if f['sourceType'] == 13),
  200. key=lambda f: f['version'])
  201. smil_url = '%s/Video/V2/VFILE/%s/%sr.smil' % (
  202. self._SMIL_BASE_URL, video_id, video_id.lower())
  203. if smil_blocks:
  204. smil_url_m = self._search_regex(
  205. r'url="([^"]+)"', smil_blocks[-1]['data'], 'SMIL URL',
  206. default=None)
  207. if smil_url_m is not None:
  208. smil_url = smil_url_m
  209. if smil_url:
  210. smil_doc = self._download_smil(smil_url, video_id, fatal=False)
  211. if smil_doc:
  212. formats.extend(self._formats_from_smil(smil_doc))
  213. self._sort_formats(formats)
  214. timestamp = int_or_none(self._search_regex(
  215. r'/Date\((\d+)\)/',
  216. video_info['launchDate'], 'launch date', fatal=False),
  217. scale=1000) if video_info else None
  218. duration = video_info.get('duration') or int_or_none(
  219. self._html_search_meta('video:duration', webpage))
  220. return {
  221. 'id': video_id,
  222. 'title': title,
  223. 'formats': formats,
  224. 'thumbnail': video_info.get('imageUrl'),
  225. 'timestamp': timestamp,
  226. 'uploader': video_info['mainArtists'][0]['artistName'] if video_info else None,
  227. 'duration': duration,
  228. 'age_limit': age_limit,
  229. }