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.

149 lines
6.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_HTTPError
  6. from ..utils import (
  7. determine_ext,
  8. ExtractorError,
  9. int_or_none,
  10. parse_age_limit,
  11. parse_iso8601,
  12. )
  13. class Go90IE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:www\.)?go90\.com/(?:videos|embed)/(?P<id>[0-9a-zA-Z]+)'
  15. _TESTS = [{
  16. 'url': 'https://www.go90.com/videos/84BUqjLpf9D',
  17. 'md5': 'efa7670dbbbf21a7b07b360652b24a32',
  18. 'info_dict': {
  19. 'id': '84BUqjLpf9D',
  20. 'ext': 'mp4',
  21. 'title': 'Daily VICE - Inside The Utah Coalition Against Pornography Convention',
  22. 'description': 'VICE\'s Karley Sciortino meets with activists who discuss the state\'s strong anti-porn stance. Then, VICE Sports explains NFL contracts.',
  23. 'timestamp': 1491868800,
  24. 'upload_date': '20170411',
  25. 'age_limit': 14,
  26. }
  27. }, {
  28. 'url': 'https://www.go90.com/embed/261MflWkD3N',
  29. 'only_matching': True,
  30. }]
  31. _GEO_BYPASS = False
  32. def _real_extract(self, url):
  33. video_id = self._match_id(url)
  34. try:
  35. headers = self.geo_verification_headers()
  36. headers.update({
  37. 'Content-Type': 'application/json; charset=utf-8',
  38. })
  39. video_data = self._download_json(
  40. 'https://www.go90.com/api/view/items/' + video_id, video_id,
  41. headers=headers, data=b'{"client":"web","device_type":"pc"}')
  42. except ExtractorError as e:
  43. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400:
  44. message = self._parse_json(e.cause.read().decode(), None)['error']['message']
  45. if 'region unavailable' in message:
  46. self.raise_geo_restricted(countries=['US'])
  47. raise ExtractorError(message, expected=True)
  48. raise
  49. if video_data.get('requires_drm'):
  50. raise ExtractorError('This video is DRM protected.', expected=True)
  51. main_video_asset = video_data['main_video_asset']
  52. episode_number = int_or_none(video_data.get('episode_number'))
  53. series = None
  54. season = None
  55. season_id = None
  56. season_number = None
  57. for metadata in video_data.get('__children', {}).get('Item', {}).values():
  58. if metadata.get('type') == 'show':
  59. series = metadata.get('title')
  60. elif metadata.get('type') == 'season':
  61. season = metadata.get('title')
  62. season_id = metadata.get('id')
  63. season_number = int_or_none(metadata.get('season_number'))
  64. title = episode = video_data.get('title') or series
  65. if series and series != title:
  66. title = '%s - %s' % (series, title)
  67. thumbnails = []
  68. formats = []
  69. subtitles = {}
  70. for asset in video_data.get('assets'):
  71. if asset.get('id') == main_video_asset:
  72. for source in asset.get('sources', []):
  73. source_location = source.get('location')
  74. if not source_location:
  75. continue
  76. source_type = source.get('type')
  77. if source_type == 'hls':
  78. m3u8_formats = self._extract_m3u8_formats(
  79. source_location, video_id, 'mp4',
  80. 'm3u8_native', m3u8_id='hls', fatal=False)
  81. for f in m3u8_formats:
  82. mobj = re.search(r'/hls-(\d+)-(\d+)K', f['url'])
  83. if mobj:
  84. height, tbr = mobj.groups()
  85. height = int_or_none(height)
  86. f.update({
  87. 'height': f.get('height') or height,
  88. 'width': f.get('width') or int_or_none(height / 9.0 * 16.0 if height else None),
  89. 'tbr': f.get('tbr') or int_or_none(tbr),
  90. })
  91. formats.extend(m3u8_formats)
  92. elif source_type == 'dash':
  93. formats.extend(self._extract_mpd_formats(
  94. source_location, video_id, mpd_id='dash', fatal=False))
  95. else:
  96. formats.append({
  97. 'format_id': source.get('name'),
  98. 'url': source_location,
  99. 'width': int_or_none(source.get('width')),
  100. 'height': int_or_none(source.get('height')),
  101. 'tbr': int_or_none(source.get('bitrate')),
  102. })
  103. for caption in asset.get('caption_metadata', []):
  104. caption_url = caption.get('source_url')
  105. if not caption_url:
  106. continue
  107. subtitles.setdefault(caption.get('language', 'en'), []).append({
  108. 'url': caption_url,
  109. 'ext': determine_ext(caption_url, 'vtt'),
  110. })
  111. elif asset.get('type') == 'image':
  112. asset_location = asset.get('location')
  113. if not asset_location:
  114. continue
  115. thumbnails.append({
  116. 'url': asset_location,
  117. 'width': int_or_none(asset.get('width')),
  118. 'height': int_or_none(asset.get('height')),
  119. })
  120. self._sort_formats(formats)
  121. return {
  122. 'id': video_id,
  123. 'title': title,
  124. 'formats': formats,
  125. 'thumbnails': thumbnails,
  126. 'description': video_data.get('short_description'),
  127. 'like_count': int_or_none(video_data.get('like_count')),
  128. 'timestamp': parse_iso8601(video_data.get('released_at')),
  129. 'series': series,
  130. 'episode': episode,
  131. 'season': season,
  132. 'season_id': season_id,
  133. 'season_number': season_number,
  134. 'episode_number': episode_number,
  135. 'subtitles': subtitles,
  136. 'age_limit': parse_age_limit(video_data.get('rating')),
  137. }