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.

227 lines
8.1 KiB

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