go90.py 5.5 KB

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