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.

126 lines
5.3 KiB

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