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.

182 lines
7.9 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 ExtractorError
  7. class VoxMediaVolumeIE(OnceIE):
  8. _VALID_URL = r'https?://volume\.vox-cdn\.com/embed/(?P<id>[0-9a-f]{9})'
  9. def _real_extract(self, url):
  10. video_id = self._match_id(url)
  11. webpage = self._download_webpage(url, video_id)
  12. video_data = self._parse_json(self._search_regex(
  13. r'Volume\.createVideo\(({.+})\s*,\s*{.*}\s*,\s*\[.*\]\s*,\s*{.*}\);', webpage, 'video data'), video_id)
  14. for provider_video_type in ('ooyala', 'youtube', 'brightcove'):
  15. provider_video_id = video_data.get('%s_id' % provider_video_type)
  16. if not provider_video_id:
  17. continue
  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. if provider_video_type == 'brightcove':
  25. info['formats'] = self._extract_once_formats(provider_video_id)
  26. self._sort_formats(info['formats'])
  27. else:
  28. info.update({
  29. '_type': 'url_transparent',
  30. 'url': provider_video_id if provider_video_type == 'youtube' else '%s:%s' % (provider_video_type, provider_video_id),
  31. 'ie_key': provider_video_type.capitalize(),
  32. })
  33. return info
  34. raise ExtractorError('Unable to find provider video id')
  35. class VoxMediaIE(InfoExtractor):
  36. _VALID_URL = r'https?://(?:www\.)?(?:(?:theverge|vox|sbnation|eater|polygon|curbed|racked)\.com|recode\.net)/(?:[^/]+/)*(?P<id>[^/?]+)'
  37. _TESTS = [{
  38. 'url': 'http://www.theverge.com/2014/6/27/5849272/material-world-how-google-discovered-what-software-is-made-of',
  39. 'info_dict': {
  40. 'id': '11eXZobjrG8DCSTgrNjVinU-YmmdYjhe',
  41. 'ext': 'mp4',
  42. 'title': 'Google\'s new material design direction',
  43. 'description': 'md5:2f44f74c4d14a1f800ea73e1c6832ad2',
  44. },
  45. 'params': {
  46. # m3u8 download
  47. 'skip_download': True,
  48. },
  49. 'add_ie': ['Ooyala'],
  50. }, {
  51. # data-ooyala-id
  52. 'url': 'http://www.theverge.com/2014/10/21/7025853/google-nexus-6-hands-on-photos-video-android-phablet',
  53. 'md5': 'd744484ff127884cd2ba09e3fa604e4b',
  54. 'info_dict': {
  55. 'id': 'RkZXU4cTphOCPDMZg5oEounJyoFI0g-B',
  56. 'ext': 'mp4',
  57. 'title': 'The Nexus 6: hands-on with Google\'s phablet',
  58. 'description': 'md5:87a51fe95ff8cea8b5bdb9ac7ae6a6af',
  59. },
  60. 'add_ie': ['Ooyala'],
  61. 'skip': 'Video Not Found',
  62. }, {
  63. # volume embed
  64. 'url': 'http://www.vox.com/2016/3/31/11336640/mississippi-lgbt-religious-freedom-bill',
  65. 'info_dict': {
  66. 'id': 'wydzk3dDpmRz7PQoXRsTIX6XTkPjYL0b',
  67. 'ext': 'mp4',
  68. 'title': 'The new frontier of LGBTQ civil rights, explained',
  69. 'description': 'md5:0dc58e94a465cbe91d02950f770eb93f',
  70. },
  71. 'params': {
  72. # m3u8 download
  73. 'skip_download': True,
  74. },
  75. 'add_ie': ['Ooyala'],
  76. }, {
  77. # youtube embed
  78. 'url': 'http://www.vox.com/2016/3/24/11291692/robot-dance',
  79. 'md5': '83b3080489fb103941e549352d3e0977',
  80. 'info_dict': {
  81. 'id': 'FcNHTJU1ufM',
  82. 'ext': 'mp4',
  83. 'title': 'How "the robot" became the greatest novelty dance of all time',
  84. 'description': 'md5:b081c0d588b8b2085870cda55e6da176',
  85. 'upload_date': '20160324',
  86. 'uploader_id': 'voxdotcom',
  87. 'uploader': 'Vox',
  88. },
  89. 'add_ie': ['Youtube'],
  90. }, {
  91. # SBN.VideoLinkset.entryGroup multiple ooyala embeds
  92. 'url': 'http://www.sbnation.com/college-football-recruiting/2015/2/3/7970291/national-signing-day-rationalizations-itll-be-ok-itll-be-ok',
  93. 'info_dict': {
  94. 'id': 'national-signing-day-rationalizations-itll-be-ok-itll-be-ok',
  95. 'title': '25 lies you will tell yourself on National Signing Day',
  96. 'description': 'It\'s the most self-delusional time of the year, and everyone\'s gonna tell the same lies together!',
  97. },
  98. 'playlist': [{
  99. 'md5': '721fededf2ab74ae4176c8c8cbfe092e',
  100. 'info_dict': {
  101. 'id': 'p3cThlMjE61VDi_SD9JlIteSNPWVDBB9',
  102. 'ext': 'mp4',
  103. 'title': 'Buddy Hield vs Steph Curry (and the world)',
  104. 'description': 'Let’s dissect only the most important Final Four storylines.',
  105. },
  106. }, {
  107. 'md5': 'bf0c5cc115636af028be1bab79217ea9',
  108. 'info_dict': {
  109. 'id': 'BmbmVjMjE6esPHxdALGubTrouQ0jYLHj',
  110. 'ext': 'mp4',
  111. 'title': 'Chasing Cinderella 2016: Syracuse basketball',
  112. 'description': 'md5:e02d56b026d51aa32c010676765a690d',
  113. },
  114. }],
  115. }, {
  116. # volume embed, Brightcove Once
  117. 'url': 'https://www.recode.net/2014/6/17/11628066/post-post-pc-ceo-the-full-code-conference-video-of-microsofts-satya',
  118. 'md5': '01571a896281f77dc06e084138987ea2',
  119. 'info_dict': {
  120. 'id': '1231c973d',
  121. 'ext': 'mp4',
  122. 'title': 'Post-Post-PC CEO: The Full Code Conference Video of Microsoft\'s Satya Nadella',
  123. 'description': 'The longtime veteran was chosen earlier this year as the software giant\'s third leader in its history.',
  124. },
  125. 'add_ie': ['VoxMediaVolume'],
  126. }]
  127. def _real_extract(self, url):
  128. display_id = self._match_id(url)
  129. webpage = compat_urllib_parse_unquote(self._download_webpage(url, display_id))
  130. def create_entry(provider_video_id, provider_video_type, title=None, description=None):
  131. video_url = {
  132. 'youtube': '%s',
  133. 'ooyala': 'ooyala:%s',
  134. 'volume': 'http://volume.vox-cdn.com/embed/%s',
  135. }[provider_video_type] % provider_video_id
  136. return {
  137. '_type': 'url_transparent',
  138. 'url': video_url,
  139. 'title': title or self._og_search_title(webpage),
  140. 'description': description or self._og_search_description(webpage),
  141. }
  142. entries = []
  143. entries_data = self._search_regex([
  144. r'Chorus\.VideoContext\.addVideo\((\[{.+}\])\);',
  145. r'var\s+entry\s*=\s*({.+});',
  146. r'SBN\.VideoLinkset\.entryGroup\(\s*(\[.+\])',
  147. ], webpage, 'video data', default=None)
  148. if entries_data:
  149. entries_data = self._parse_json(entries_data, display_id)
  150. if isinstance(entries_data, dict):
  151. entries_data = [entries_data]
  152. for video_data in entries_data:
  153. provider_video_id = video_data.get('provider_video_id')
  154. provider_video_type = video_data.get('provider_video_type')
  155. if provider_video_id and provider_video_type:
  156. entries.append(create_entry(
  157. provider_video_id, provider_video_type,
  158. video_data.get('title'), video_data.get('description')))
  159. provider_video_id = self._search_regex(
  160. r'data-ooyala-id="([^"]+)"', webpage, 'ooyala id', default=None)
  161. if provider_video_id:
  162. entries.append(create_entry(provider_video_id, 'ooyala'))
  163. volume_uuid = self._search_regex(
  164. r'data-volume-uuid="([^"]+)"', webpage, 'volume uuid', default=None)
  165. if volume_uuid:
  166. entries.append(create_entry(volume_uuid, 'volume'))
  167. if len(entries) == 1:
  168. return entries[0]
  169. else:
  170. return self.playlist_result(entries, display_id, self._og_search_title(webpage), self._og_search_description(webpage))