Added extractor for rockstargames.com
[youtube-dl] / youtube_dl / extractor / rockstargames.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     qualities,
7     parse_iso8601
8 )
9
10
11 class RockstarGamesIE(InfoExtractor):
12     _VALID_URL = r'https?://(?:www\.)?rockstargames\.com/videos/video/(?P<id>[0-9]+)'
13     _TEST = {
14         'url': 'https://www.rockstargames.com/videos/video/11544/',
15         'md5': '03b5caa6e357a4bd50e3143fc03e5733',
16         'info_dict': {
17             'id': '11544',
18             'ext': 'mp4',
19             'title': 'Further Adventures in Finance and Felony Trailer',
20             'thumbnail': 're:^https?://.*\.jpg$',
21             'description': 'md5:6d31f55f30cb101b5476c4a379e324a3',
22             'upload_date': '20160602',
23             'timestamp': 1464876000
24         }
25     }
26
27     def _real_extract(self, url):
28         video_id = self._match_id(url)
29         json_data = self._download_json(
30             'https://www.rockstargames.com/videoplayer/videos/get-video.json?id=%s&locale=en_us' % video_id,
31             video_id
32         )['video']
33
34         formats = []
35
36         for video in json_data['files_processed']['video/mp4']:
37             if not video.get('src'):
38                 continue
39             height = video.get('resolution', '').replace('p', '')
40             
41             formats.append({
42                 'url': self._proto_relative_url(video['src']),
43                 'height': int(height) if height.isdigit() else -1,
44             })
45         self._sort_formats(formats)
46
47         return {
48             'id': video_id,
49             'title': json_data['title'],
50             'description': json_data.get('description'),
51             'formats': formats,
52             'thumbnail': self._proto_relative_url(json_data.get('screencap')),
53             'timestamp': parse_iso8601(json_data.get('created'))
54         }