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.

136 lines
6.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_urllib_parse_unquote
  5. class VoxMediaIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?(?:theverge|vox|sbnation|eater|polygon|curbed|racked)\.com/(?:[^/]+/)*(?P<id>[^/?]+)'
  7. _TESTS = [{
  8. 'url': 'http://www.theverge.com/2014/6/27/5849272/material-world-how-google-discovered-what-software-is-made-of',
  9. 'md5': '73856edf3e89a711e70d5cf7cb280b37',
  10. 'info_dict': {
  11. 'id': '11eXZobjrG8DCSTgrNjVinU-YmmdYjhe',
  12. 'ext': 'mp4',
  13. 'title': 'Google\'s new material design direction',
  14. 'description': 'md5:2f44f74c4d14a1f800ea73e1c6832ad2',
  15. },
  16. 'add_ie': ['Ooyala'],
  17. }, {
  18. # data-ooyala-id
  19. 'url': 'http://www.theverge.com/2014/10/21/7025853/google-nexus-6-hands-on-photos-video-android-phablet',
  20. 'md5': 'd744484ff127884cd2ba09e3fa604e4b',
  21. 'info_dict': {
  22. 'id': 'RkZXU4cTphOCPDMZg5oEounJyoFI0g-B',
  23. 'ext': 'mp4',
  24. 'title': 'The Nexus 6: hands-on with Google\'s phablet',
  25. 'description': 'md5:87a51fe95ff8cea8b5bdb9ac7ae6a6af',
  26. },
  27. 'add_ie': ['Ooyala'],
  28. }, {
  29. # volume embed
  30. 'url': 'http://www.vox.com/2016/3/31/11336640/mississippi-lgbt-religious-freedom-bill',
  31. 'md5': '375c483c5080ab8cd85c9c84cfc2d1e4',
  32. 'info_dict': {
  33. 'id': 'wydzk3dDpmRz7PQoXRsTIX6XTkPjYL0b',
  34. 'ext': 'mp4',
  35. 'title': 'The new frontier of LGBTQ civil rights, explained',
  36. 'description': 'md5:0dc58e94a465cbe91d02950f770eb93f',
  37. },
  38. 'add_ie': ['Ooyala'],
  39. }, {
  40. # youtube embed
  41. 'url': 'http://www.vox.com/2016/3/24/11291692/robot-dance',
  42. 'md5': '83b3080489fb103941e549352d3e0977',
  43. 'info_dict': {
  44. 'id': 'FcNHTJU1ufM',
  45. 'ext': 'mp4',
  46. 'title': 'How "the robot" became the greatest novelty dance of all time',
  47. 'description': 'md5:b081c0d588b8b2085870cda55e6da176',
  48. 'upload_date': '20160324',
  49. 'uploader_id': 'voxdotcom',
  50. 'uploader': 'Vox',
  51. },
  52. 'add_ie': ['Youtube'],
  53. }, {
  54. # SBN.VideoLinkset.entryGroup multiple ooyala embeds
  55. 'url': 'http://www.sbnation.com/college-football-recruiting/2015/2/3/7970291/national-signing-day-rationalizations-itll-be-ok-itll-be-ok',
  56. 'info_dict': {
  57. 'id': 'national-signing-day-rationalizations-itll-be-ok-itll-be-ok',
  58. 'title': '25 lies you will tell yourself on National Signing Day',
  59. 'description': 'It\'s the most self-delusional time of the year, and everyone\'s gonna tell the same lies together!',
  60. },
  61. 'playlist': [{
  62. 'md5': '721fededf2ab74ae4176c8c8cbfe092e',
  63. 'info_dict': {
  64. 'id': 'p3cThlMjE61VDi_SD9JlIteSNPWVDBB9',
  65. 'ext': 'mp4',
  66. 'title': 'Buddy Hield vs Steph Curry (and the world)',
  67. 'description': 'Let’s dissect only the most important Final Four storylines.',
  68. },
  69. }, {
  70. 'md5': 'bf0c5cc115636af028be1bab79217ea9',
  71. 'info_dict': {
  72. 'id': 'BmbmVjMjE6esPHxdALGubTrouQ0jYLHj',
  73. 'ext': 'mp4',
  74. 'title': 'Chasing Cinderella 2016: Syracuse basketball',
  75. 'description': 'md5:e02d56b026d51aa32c010676765a690d',
  76. },
  77. }],
  78. }]
  79. def _real_extract(self, url):
  80. display_id = self._match_id(url)
  81. webpage = compat_urllib_parse_unquote(self._download_webpage(url, display_id))
  82. def create_entry(provider_video_id, provider_video_type, title=None, description=None):
  83. return {
  84. '_type': 'url_transparent',
  85. 'url': provider_video_id if provider_video_type == 'youtube' else '%s:%s' % (provider_video_type, provider_video_id),
  86. 'title': title or self._og_search_title(webpage),
  87. 'description': description or self._og_search_description(webpage),
  88. }
  89. entries = []
  90. entries_data = self._search_regex([
  91. r'Chorus\.VideoContext\.addVideo\((\[{.+}\])\);',
  92. r'var\s+entry\s*=\s*({.+});',
  93. r'SBN\.VideoLinkset\.entryGroup\(\s*(\[.+\])',
  94. ], webpage, 'video data', default=None)
  95. if entries_data:
  96. entries_data = self._parse_json(entries_data, display_id)
  97. if isinstance(entries_data, dict):
  98. entries_data = [entries_data]
  99. for video_data in entries_data:
  100. provider_video_id = video_data.get('provider_video_id')
  101. provider_video_type = video_data.get('provider_video_type')
  102. if provider_video_id and provider_video_type:
  103. entries.append(create_entry(
  104. provider_video_id, provider_video_type,
  105. video_data.get('title'), video_data.get('description')))
  106. provider_video_id = self._search_regex(
  107. r'data-ooyala-id="([^"]+)"', webpage, 'ooyala id', default=None)
  108. if provider_video_id:
  109. entries.append(create_entry(provider_video_id, 'ooyala'))
  110. volume_uuid = self._search_regex(
  111. r'data-volume-uuid="([^"]+)"', webpage, 'volume uuid', default=None)
  112. if volume_uuid:
  113. volume_webpage = self._download_webpage(
  114. 'http://volume.vox-cdn.com/embed/%s' % volume_uuid, volume_uuid)
  115. video_data = self._parse_json(self._search_regex(
  116. r'Volume\.createVideo\(({.+})\s*,\s*{.*}\s*,\s*\[.*\]\s*,\s*{.*}\);', volume_webpage, 'video data'), volume_uuid)
  117. for provider_video_type in ('ooyala', 'youtube'):
  118. provider_video_id = video_data.get('%s_id' % provider_video_type)
  119. if provider_video_id:
  120. description = video_data.get('description_long') or video_data.get('description_short')
  121. entries.append(create_entry(
  122. provider_video_id, provider_video_type, video_data.get('title_short'), description))
  123. break
  124. if len(entries) == 1:
  125. return entries[0]
  126. else:
  127. return self.playlist_result(entries, display_id, self._og_search_title(webpage), self._og_search_description(webpage))