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