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.

69 lines
2.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. parse_iso8601,
  7. )
  8. class RockstarGamesIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?rockstargames\.com/videos(?:/video/|#?/?\?.*\bvideo=)(?P<id>\d+)'
  10. _TESTS = [{
  11. 'url': 'https://www.rockstargames.com/videos/video/11544/',
  12. 'md5': '03b5caa6e357a4bd50e3143fc03e5733',
  13. 'info_dict': {
  14. 'id': '11544',
  15. 'ext': 'mp4',
  16. 'title': 'Further Adventures in Finance and Felony Trailer',
  17. 'description': 'md5:6d31f55f30cb101b5476c4a379e324a3',
  18. 'thumbnail': r're:^https?://.*\.jpg$',
  19. 'timestamp': 1464876000,
  20. 'upload_date': '20160602',
  21. }
  22. }, {
  23. 'url': 'http://www.rockstargames.com/videos#/?video=48',
  24. 'only_matching': True,
  25. }]
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. video = self._download_json(
  29. 'https://www.rockstargames.com/videoplayer/videos/get-video.json',
  30. video_id, query={
  31. 'id': video_id,
  32. 'locale': 'en_us',
  33. })['video']
  34. title = video['title']
  35. formats = []
  36. for video in video['files_processed']['video/mp4']:
  37. if not video.get('src'):
  38. continue
  39. resolution = video.get('resolution')
  40. height = int_or_none(self._search_regex(
  41. r'^(\d+)[pP]$', resolution or '', 'height', default=None))
  42. formats.append({
  43. 'url': self._proto_relative_url(video['src']),
  44. 'format_id': resolution,
  45. 'height': height,
  46. })
  47. if not formats:
  48. youtube_id = video.get('youtube_id')
  49. if youtube_id:
  50. return self.url_result(youtube_id, 'Youtube')
  51. self._sort_formats(formats)
  52. return {
  53. 'id': video_id,
  54. 'title': title,
  55. 'description': video.get('description'),
  56. 'thumbnail': self._proto_relative_url(video.get('screencap')),
  57. 'timestamp': parse_iso8601(video.get('created')),
  58. 'formats': formats,
  59. }