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.

92 lines
3.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. parse_iso8601,
  8. )
  9. class Go90IE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?go90\.com/videos/(?P<id>[0-9a-zA-Z]+)'
  11. _TEST = {
  12. 'url': 'https://www.go90.com/videos/84BUqjLpf9D',
  13. 'md5': 'efa7670dbbbf21a7b07b360652b24a32',
  14. 'info_dict': {
  15. 'id': '84BUqjLpf9D',
  16. 'ext': 'mp4',
  17. 'title': 'Inside The Utah Coalition Against Pornography Convention',
  18. 'description': 'VICE\'s Karley Sciortino meets with activists who discuss the state\'s strong anti-porn stance. Then, VICE Sports explains NFL contracts.',
  19. 'timestamp': 1491868800,
  20. 'upload_date': '20170411',
  21. }
  22. }
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. video_data = self._download_json(
  26. 'https://www.go90.com/api/view/items/' + video_id,
  27. video_id, headers={
  28. 'Content-Type': 'application/json; charset=utf-8',
  29. }, data=b'{"client":"web","device_type":"pc"}')
  30. title = video_data['title']
  31. main_video_asset = video_data['main_video_asset']
  32. thumbnails = []
  33. formats = []
  34. for asset in video_data.get('assets'):
  35. if asset.get('id') == main_video_asset:
  36. for source in asset.get('sources', []):
  37. source_location = source.get('location')
  38. if not source_location:
  39. continue
  40. source_type = source.get('type')
  41. if source_type == 'hls':
  42. m3u8_formats = self._extract_m3u8_formats(
  43. source_location, video_id, 'mp4',
  44. 'm3u8_native', m3u8_id='hls', fatal=False)
  45. for f in m3u8_formats:
  46. mobj = re.search(r'/hls-(\d+)-(\d+)K', f['url'])
  47. if mobj:
  48. height, tbr = mobj.groups()
  49. height = int_or_none(height)
  50. f.update({
  51. 'height': f.get('height') or height,
  52. 'width': f.get('width') or int_or_none(height / 9.0 * 16.0 if height else None),
  53. 'tbr': f.get('tbr') or int_or_none(tbr),
  54. })
  55. formats.extend(m3u8_formats)
  56. elif source_type == 'dash':
  57. formats.extend(self._extract_mpd_formats(
  58. source_location, video_id, mpd_id='dash', fatal=False))
  59. else:
  60. formats.append({
  61. 'format_id': source.get('name'),
  62. 'url': source_location,
  63. 'width': int_or_none(source.get('width')),
  64. 'height': int_or_none(source.get('height')),
  65. 'tbr': int_or_none(source.get('bitrate')),
  66. })
  67. elif asset.get('type') == 'image':
  68. asset_location = asset.get('location')
  69. if not asset_location:
  70. continue
  71. thumbnails.append({
  72. 'url': asset_location,
  73. 'width': int_or_none(asset.get('width')),
  74. 'height': int_or_none(asset.get('height')),
  75. })
  76. self._sort_formats(formats)
  77. return {
  78. 'id': video_id,
  79. 'title': title,
  80. 'formats': formats,
  81. 'thumbnails': thumbnails,
  82. 'description': video_data.get('short_description'),
  83. 'like_count': int_or_none(video_data.get('like_count')),
  84. 'timestamp': parse_iso8601(video_data.get('released_at')),
  85. }