rockstargames.py 2.1 KB

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