logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

rumble.py (2184B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import (
  6. determine_ext,
  7. int_or_none,
  8. parse_iso8601,
  9. try_get,
  10. )
  11. class RumbleEmbedIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?rumble\.com/embed/(?:[0-9a-z]+\.)?(?P<id>[0-9a-z]+)'
  13. _TESTS = [{
  14. 'url': 'https://rumble.com/embed/v5pv5f',
  15. 'md5': '36a18a049856720189f30977ccbb2c34',
  16. 'info_dict': {
  17. 'id': 'v5pv5f',
  18. 'ext': 'mp4',
  19. 'title': 'WMAR 2 News Latest Headlines | October 20, 6pm',
  20. 'timestamp': 1571611968,
  21. 'upload_date': '20191020',
  22. }
  23. }, {
  24. 'url': 'https://rumble.com/embed/ufe9n.v5pv5f',
  25. 'only_matching': True,
  26. }]
  27. def _real_extract(self, url):
  28. video_id = self._match_id(url)
  29. video = self._download_json(
  30. 'https://rumble.com/embedJS/', video_id,
  31. query={'request': 'video', 'v': video_id})
  32. title = video['title']
  33. formats = []
  34. for height, ua in (video.get('ua') or {}).items():
  35. for i in range(2):
  36. f_url = try_get(ua, lambda x: x[i], compat_str)
  37. if f_url:
  38. ext = determine_ext(f_url)
  39. f = {
  40. 'ext': ext,
  41. 'format_id': '%s-%sp' % (ext, height),
  42. 'height': int_or_none(height),
  43. 'url': f_url,
  44. }
  45. bitrate = try_get(ua, lambda x: x[i + 2]['bitrate'])
  46. if bitrate:
  47. f['tbr'] = int_or_none(bitrate)
  48. formats.append(f)
  49. self._sort_formats(formats)
  50. author = video.get('author') or {}
  51. return {
  52. 'id': video_id,
  53. 'title': title,
  54. 'formats': formats,
  55. 'thumbnail': video.get('i'),
  56. 'timestamp': parse_iso8601(video.get('pubDate')),
  57. 'channel': author.get('name'),
  58. 'channel_url': author.get('url'),
  59. 'duration': int_or_none(video.get('duration')),
  60. }