]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/rockstargames.py
debian/{compat,control}: Update to debhelper compatibility level 12.
[youtubedl] / 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 int_or_none,
7 parse_iso8601,
8 )
9
10
11 class RockstarGamesIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?rockstargames\.com/videos(?:/video/|#?/?\?.*\bvideo=)(?P<id>\d+)'
13 _TESTS = [{
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 'description': 'md5:6d31f55f30cb101b5476c4a379e324a3',
21 'thumbnail': r're:^https?://.*\.jpg$',
22 'timestamp': 1464876000,
23 'upload_date': '20160602',
24 }
25 }, {
26 'url': 'http://www.rockstargames.com/videos#/?video=48',
27 'only_matching': True,
28 }]
29
30 def _real_extract(self, url):
31 video_id = self._match_id(url)
32
33 video = self._download_json(
34 'https://www.rockstargames.com/videoplayer/videos/get-video.json',
35 video_id, query={
36 'id': video_id,
37 'locale': 'en_us',
38 })['video']
39
40 title = video['title']
41
42 formats = []
43 for video in video['files_processed']['video/mp4']:
44 if not video.get('src'):
45 continue
46 resolution = video.get('resolution')
47 height = int_or_none(self._search_regex(
48 r'^(\d+)[pP]$', resolution or '', 'height', default=None))
49 formats.append({
50 'url': self._proto_relative_url(video['src']),
51 'format_id': resolution,
52 'height': height,
53 })
54
55 if not formats:
56 youtube_id = video.get('youtube_id')
57 if youtube_id:
58 return self.url_result(youtube_id, 'Youtube')
59
60 self._sort_formats(formats)
61
62 return {
63 'id': video_id,
64 'title': title,
65 'description': video.get('description'),
66 'thumbnail': self._proto_relative_url(video.get('screencap')),
67 'timestamp': parse_iso8601(video.get('created')),
68 'formats': formats,
69 }