go90.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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/(?P<id>[0-9a-zA-Z]+)'
  15. _TEST = {
  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. _GEO_BYPASS = False
  29. def _real_extract(self, url):
  30. video_id = self._match_id(url)
  31. try:
  32. headers = self.geo_verification_headers()
  33. headers.update({
  34. 'Content-Type': 'application/json; charset=utf-8',
  35. })
  36. video_data = self._download_json(
  37. 'https://www.go90.com/api/view/items/' + video_id, video_id,
  38. headers=headers, data=b'{"client":"web","device_type":"pc"}')
  39. except ExtractorError as e:
  40. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400:
  41. message = self._parse_json(e.cause.read().decode(), None)['error']['message']
  42. if 'region unavailable' in message:
  43. self.raise_geo_restricted(countries=['US'])
  44. raise ExtractorError(message, expected=True)
  45. raise
  46. if video_data.get('requires_drm'):
  47. raise ExtractorError('This video is DRM protected.', expected=True)
  48. main_video_asset = video_data['main_video_asset']
  49. episode_number = int_or_none(video_data.get('episode_number'))
  50. series = None
  51. season = None
  52. season_id = None
  53. season_number = None
  54. for metadata in video_data.get('__children', {}).get('Item', {}).values():
  55. if metadata.get('type') == 'show':
  56. series = metadata.get('title')
  57. elif metadata.get('type') == 'season':
  58. season = metadata.get('title')
  59. season_id = metadata.get('id')
  60. season_number = int_or_none(metadata.get('season_number'))
  61. title = episode = video_data.get('title') or series
  62. if series and series != title:
  63. title = '%s - %s' % (series, title)
  64. thumbnails = []
  65. formats = []
  66. subtitles = {}
  67. for asset in video_data.get('assets'):
  68. if asset.get('id') == main_video_asset:
  69. for source in asset.get('sources', []):
  70. source_location = source.get('location')
  71. if not source_location:
  72. continue
  73. source_type = source.get('type')
  74. if source_type == 'hls':
  75. m3u8_formats = self._extract_m3u8_formats(
  76. source_location, video_id, 'mp4',
  77. 'm3u8_native', m3u8_id='hls', fatal=False)
  78. for f in m3u8_formats:
  79. mobj = re.search(r'/hls-(\d+)-(\d+)K', f['url'])
  80. if mobj:
  81. height, tbr = mobj.groups()
  82. height = int_or_none(height)
  83. f.update({
  84. 'height': f.get('height') or height,
  85. 'width': f.get('width') or int_or_none(height / 9.0 * 16.0 if height else None),
  86. 'tbr': f.get('tbr') or int_or_none(tbr),
  87. })
  88. formats.extend(m3u8_formats)
  89. elif source_type == 'dash':
  90. formats.extend(self._extract_mpd_formats(
  91. source_location, video_id, mpd_id='dash', fatal=False))
  92. else:
  93. formats.append({
  94. 'format_id': source.get('name'),
  95. 'url': source_location,
  96. 'width': int_or_none(source.get('width')),
  97. 'height': int_or_none(source.get('height')),
  98. 'tbr': int_or_none(source.get('bitrate')),
  99. })
  100. for caption in asset.get('caption_metadata', []):
  101. caption_url = caption.get('source_url')
  102. if not caption_url:
  103. continue
  104. subtitles.setdefault(caption.get('language', 'en'), []).append({
  105. 'url': caption_url,
  106. 'ext': determine_ext(caption_url, 'vtt'),
  107. })
  108. elif asset.get('type') == 'image':
  109. asset_location = asset.get('location')
  110. if not asset_location:
  111. continue
  112. thumbnails.append({
  113. 'url': asset_location,
  114. 'width': int_or_none(asset.get('width')),
  115. 'height': int_or_none(asset.get('height')),
  116. })
  117. self._sort_formats(formats)
  118. return {
  119. 'id': video_id,
  120. 'title': title,
  121. 'formats': formats,
  122. 'thumbnails': thumbnails,
  123. 'description': video_data.get('short_description'),
  124. 'like_count': int_or_none(video_data.get('like_count')),
  125. 'timestamp': parse_iso8601(video_data.get('released_at')),
  126. 'series': series,
  127. 'episode': episode,
  128. 'season': season,
  129. 'season_id': season_id,
  130. 'season_number': season_number,
  131. 'episode_number': episode_number,
  132. 'subtitles': subtitles,
  133. 'age_limit': parse_age_limit(video_data.get('rating')),
  134. }