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.

215 lines
9.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from .once import OnceIE
  5. from ..compat import compat_urllib_parse_unquote
  6. from ..utils import (
  7. ExtractorError,
  8. int_or_none,
  9. )
  10. class VoxMediaVolumeIE(OnceIE):
  11. _VALID_URL = r'https?://volume\.vox-cdn\.com/embed/(?P<id>[0-9a-f]{9})'
  12. def _real_extract(self, url):
  13. video_id = self._match_id(url)
  14. webpage = self._download_webpage(url, video_id)
  15. setup = self._parse_json(self._search_regex(
  16. r'setup\s*=\s*({.+});', webpage, 'setup'), video_id)
  17. video_data = setup.get('video') or {}
  18. info = {
  19. 'id': video_id,
  20. 'title': video_data.get('title_short'),
  21. 'description': video_data.get('description_long') or video_data.get('description_short'),
  22. 'thumbnail': video_data.get('brightcove_thumbnail')
  23. }
  24. asset = setup.get('asset') or setup.get('params') or {}
  25. formats = []
  26. hls_url = asset.get('hls_url')
  27. if hls_url:
  28. formats.extend(self._extract_m3u8_formats(
  29. hls_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
  30. mp4_url = asset.get('mp4_url')
  31. if mp4_url:
  32. tbr = self._search_regex(r'-(\d+)k\.', mp4_url, 'bitrate', default=None)
  33. format_id = 'http'
  34. if tbr:
  35. format_id += '-' + tbr
  36. formats.append({
  37. 'format_id': format_id,
  38. 'url': mp4_url,
  39. 'tbr': int_or_none(tbr),
  40. })
  41. if formats:
  42. self._sort_formats(formats)
  43. info['formats'] = formats
  44. return info
  45. for provider_video_type in ('ooyala', 'youtube', 'brightcove'):
  46. provider_video_id = video_data.get('%s_id' % provider_video_type)
  47. if not provider_video_id:
  48. continue
  49. if provider_video_type == 'brightcove':
  50. info['formats'] = self._extract_once_formats(provider_video_id)
  51. self._sort_formats(info['formats'])
  52. else:
  53. info.update({
  54. '_type': 'url_transparent',
  55. 'url': provider_video_id if provider_video_type == 'youtube' else '%s:%s' % (provider_video_type, provider_video_id),
  56. 'ie_key': provider_video_type.capitalize(),
  57. })
  58. return info
  59. raise ExtractorError('Unable to find provider video id')
  60. class VoxMediaIE(InfoExtractor):
  61. _VALID_URL = r'https?://(?:www\.)?(?:(?:theverge|vox|sbnation|eater|polygon|curbed|racked|funnyordie)\.com|recode\.net)/(?:[^/]+/)*(?P<id>[^/?]+)'
  62. _TESTS = [{
  63. # Volume embed, Youtube
  64. 'url': 'http://www.theverge.com/2014/6/27/5849272/material-world-how-google-discovered-what-software-is-made-of',
  65. 'info_dict': {
  66. 'id': 'j4mLW6x17VM',
  67. 'ext': 'mp4',
  68. 'title': 'Material world: how Google discovered what software is made of',
  69. 'description': 'md5:dfc17e7715e3b542d66e33a109861382',
  70. 'upload_date': '20190710',
  71. 'uploader_id': 'TheVerge',
  72. 'uploader': 'The Verge',
  73. },
  74. 'add_ie': ['Youtube'],
  75. }, {
  76. # Volume embed, Youtube
  77. 'url': 'http://www.theverge.com/2014/10/21/7025853/google-nexus-6-hands-on-photos-video-android-phablet',
  78. 'md5': '4c8f4a0937752b437c3ebc0ed24802b5',
  79. 'info_dict': {
  80. 'id': 'Gy8Md3Eky38',
  81. 'ext': 'mp4',
  82. 'title': 'The Nexus 6: hands-on with Google\'s phablet',
  83. 'description': 'md5:d9f0216e5fb932dd2033d6db37ac3f1d',
  84. 'uploader_id': 'TheVerge',
  85. 'upload_date': '20141021',
  86. 'uploader': 'The Verge',
  87. },
  88. 'add_ie': ['Youtube'],
  89. 'skip': 'similar to the previous test',
  90. }, {
  91. # Volume embed, Youtube
  92. 'url': 'http://www.vox.com/2016/3/31/11336640/mississippi-lgbt-religious-freedom-bill',
  93. 'info_dict': {
  94. 'id': 'YCjDnX-Xzhg',
  95. 'ext': 'mp4',
  96. 'title': "Mississippi's laws are so bad that its anti-LGBTQ law isn't needed to allow discrimination",
  97. 'description': 'md5:fc1317922057de31cd74bce91eb1c66c',
  98. 'uploader_id': 'voxdotcom',
  99. 'upload_date': '20150915',
  100. 'uploader': 'Vox',
  101. },
  102. 'add_ie': ['Youtube'],
  103. 'skip': 'similar to the previous test',
  104. }, {
  105. # youtube embed
  106. 'url': 'http://www.vox.com/2016/3/24/11291692/robot-dance',
  107. 'md5': '83b3080489fb103941e549352d3e0977',
  108. 'info_dict': {
  109. 'id': 'FcNHTJU1ufM',
  110. 'ext': 'mp4',
  111. 'title': 'How "the robot" became the greatest novelty dance of all time',
  112. 'description': 'md5:b081c0d588b8b2085870cda55e6da176',
  113. 'upload_date': '20160324',
  114. 'uploader_id': 'voxdotcom',
  115. 'uploader': 'Vox',
  116. },
  117. 'add_ie': ['Youtube'],
  118. 'skip': 'Page no longer contain videos',
  119. }, {
  120. # SBN.VideoLinkset.entryGroup multiple ooyala embeds
  121. 'url': 'http://www.sbnation.com/college-football-recruiting/2015/2/3/7970291/national-signing-day-rationalizations-itll-be-ok-itll-be-ok',
  122. 'info_dict': {
  123. 'id': 'national-signing-day-rationalizations-itll-be-ok-itll-be-ok',
  124. 'title': '25 lies you will tell yourself on National Signing Day',
  125. 'description': 'It\'s the most self-delusional time of the year, and everyone\'s gonna tell the same lies together!',
  126. },
  127. 'playlist': [{
  128. 'md5': '721fededf2ab74ae4176c8c8cbfe092e',
  129. 'info_dict': {
  130. 'id': 'p3cThlMjE61VDi_SD9JlIteSNPWVDBB9',
  131. 'ext': 'mp4',
  132. 'title': 'Buddy Hield vs Steph Curry (and the world)',
  133. 'description': 'Let’s dissect only the most important Final Four storylines.',
  134. },
  135. }, {
  136. 'md5': 'bf0c5cc115636af028be1bab79217ea9',
  137. 'info_dict': {
  138. 'id': 'BmbmVjMjE6esPHxdALGubTrouQ0jYLHj',
  139. 'ext': 'mp4',
  140. 'title': 'Chasing Cinderella 2016: Syracuse basketball',
  141. 'description': 'md5:e02d56b026d51aa32c010676765a690d',
  142. },
  143. }],
  144. 'skip': 'Page no longer contain videos',
  145. }, {
  146. # volume embed, Brightcove Once
  147. 'url': 'https://www.recode.net/2014/6/17/11628066/post-post-pc-ceo-the-full-code-conference-video-of-microsofts-satya',
  148. 'md5': '2dbc77b8b0bff1894c2fce16eded637d',
  149. 'info_dict': {
  150. 'id': '1231c973d',
  151. 'ext': 'mp4',
  152. 'title': 'Post-Post-PC CEO: The Full Code Conference Video of Microsoft\'s Satya Nadella',
  153. 'description': 'The longtime veteran was chosen earlier this year as the software giant\'s third leader in its history.',
  154. },
  155. 'add_ie': ['VoxMediaVolume'],
  156. }]
  157. def _real_extract(self, url):
  158. display_id = self._match_id(url)
  159. webpage = compat_urllib_parse_unquote(self._download_webpage(url, display_id))
  160. def create_entry(provider_video_id, provider_video_type, title=None, description=None):
  161. video_url = {
  162. 'youtube': '%s',
  163. 'ooyala': 'ooyala:%s',
  164. 'volume': 'http://volume.vox-cdn.com/embed/%s',
  165. }[provider_video_type] % provider_video_id
  166. return {
  167. '_type': 'url_transparent',
  168. 'url': video_url,
  169. 'title': title or self._og_search_title(webpage),
  170. 'description': description or self._og_search_description(webpage),
  171. }
  172. entries = []
  173. entries_data = self._search_regex([
  174. r'Chorus\.VideoContext\.addVideo\((\[{.+}\])\);',
  175. r'var\s+entry\s*=\s*({.+});',
  176. r'SBN\.VideoLinkset\.entryGroup\(\s*(\[.+\])',
  177. ], webpage, 'video data', default=None)
  178. if entries_data:
  179. entries_data = self._parse_json(entries_data, display_id)
  180. if isinstance(entries_data, dict):
  181. entries_data = [entries_data]
  182. for video_data in entries_data:
  183. provider_video_id = video_data.get('provider_video_id')
  184. provider_video_type = video_data.get('provider_video_type')
  185. if provider_video_id and provider_video_type:
  186. entries.append(create_entry(
  187. provider_video_id, provider_video_type,
  188. video_data.get('title'), video_data.get('description')))
  189. provider_video_id = self._search_regex(
  190. r'data-ooyala-id="([^"]+)"', webpage, 'ooyala id', default=None)
  191. if provider_video_id:
  192. entries.append(create_entry(provider_video_id, 'ooyala'))
  193. volume_uuid = self._search_regex(
  194. r'data-volume-uuid="([^"]+)"', webpage, 'volume uuid', default=None)
  195. if volume_uuid:
  196. entries.append(create_entry(volume_uuid, 'volume'))
  197. if len(entries) == 1:
  198. return entries[0]
  199. else:
  200. return self.playlist_result(entries, display_id, self._og_search_title(webpage), self._og_search_description(webpage))