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.

98 lines
3.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. float_or_none,
  7. int_or_none,
  8. )
  9. class StreamableIE(InfoExtractor):
  10. _VALID_URL = r'https?://streamable\.com/(?:e/)?(?P<id>\w+)'
  11. _TESTS = [
  12. {
  13. 'url': 'https://streamable.com/dnd1',
  14. 'md5': '3e3bc5ca088b48c2d436529b64397fef',
  15. 'info_dict': {
  16. 'id': 'dnd1',
  17. 'ext': 'mp4',
  18. 'title': 'Mikel Oiarzabal scores to make it 0-3 for La Real against Espanyol',
  19. 'thumbnail': 're:https?://.*\.jpg$',
  20. 'uploader': 'teabaker',
  21. 'timestamp': 1454964157.35115,
  22. 'upload_date': '20160208',
  23. 'duration': 61.516,
  24. 'view_count': int,
  25. }
  26. },
  27. # older video without bitrate, width/height, etc. info
  28. {
  29. 'url': 'https://streamable.com/moo',
  30. 'md5': '2cf6923639b87fba3279ad0df3a64e73',
  31. 'info_dict': {
  32. 'id': 'moo',
  33. 'ext': 'mp4',
  34. 'title': '"Please don\'t eat me!"',
  35. 'thumbnail': 're:https?://.*\.jpg$',
  36. 'timestamp': 1426115495,
  37. 'upload_date': '20150311',
  38. 'duration': 12,
  39. 'view_count': int,
  40. }
  41. },
  42. {
  43. 'url': 'https://streamable.com/e/dnd1',
  44. 'only_matching': True,
  45. }
  46. ]
  47. def _real_extract(self, url):
  48. video_id = self._match_id(url)
  49. # Note: Using the ajax API, as the public Streamable API doesn't seem
  50. # to return video info like the title properly sometimes, and doesn't
  51. # include info like the video duration
  52. video = self._download_json(
  53. 'https://streamable.com/ajax/videos/%s' % video_id, video_id)
  54. # Format IDs:
  55. # 0 The video is being uploaded
  56. # 1 The video is being processed
  57. # 2 The video has at least one file ready
  58. # 3 The video is unavailable due to an error
  59. status = video.get('status')
  60. if status != 2:
  61. raise ExtractorError(
  62. 'This video is currently unavailable. It may still be uploading or processing.',
  63. expected=True)
  64. title = video.get('reddit_title') or video['title']
  65. formats = []
  66. for key, info in video['files'].items():
  67. if not info.get('url'):
  68. continue
  69. formats.append({
  70. 'format_id': key,
  71. 'url': self._proto_relative_url(info['url']),
  72. 'width': int_or_none(info.get('width')),
  73. 'height': int_or_none(info.get('height')),
  74. 'filesize': int_or_none(info.get('size')),
  75. 'fps': int_or_none(info.get('framerate')),
  76. 'vbr': float_or_none(info.get('bitrate'), 1000)
  77. })
  78. self._sort_formats(formats)
  79. return {
  80. 'id': video_id,
  81. 'title': title,
  82. 'description': video.get('description'),
  83. 'thumbnail': self._proto_relative_url(video.get('thumbnail_url')),
  84. 'uploader': video.get('owner', {}).get('user_name'),
  85. 'timestamp': float_or_none(video.get('date_added')),
  86. 'duration': float_or_none(video.get('duration')),
  87. 'view_count': int_or_none(video.get('plays')),
  88. 'formats': formats
  89. }