logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

voxmedia.py (9844B)


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