]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/rockstargames.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / rockstargames.py
CommitLineData
14d0f4e0
D
1from .common import InfoExtractor
2from ..utils import (
16b6bd01
S
3 int_or_none,
4 parse_iso8601,
14d0f4e0
D
5)
6
7
8class RockstarGamesIE(InfoExtractor):
16b6bd01
S
9 _VALID_URL = r'https?://(?:www\.)?rockstargames\.com/videos(?:/video/|#?/?\?.*\bvideo=)(?P<id>\d+)'
10 _TESTS = [{
14d0f4e0
D
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',
14d0f4e0 17 'description': 'md5:6d31f55f30cb101b5476c4a379e324a3',
ec85ded8 18 'thumbnail': r're:^https?://.*\.jpg$',
16b6bd01 19 'timestamp': 1464876000,
14d0f4e0 20 'upload_date': '20160602',
14d0f4e0 21 }
16b6bd01
S
22 }, {
23 'url': 'http://www.rockstargames.com/videos#/?video=48',
24 'only_matching': True,
25 }]
14d0f4e0
D
26
27 def _real_extract(self, url):
28 video_id = self._match_id(url)
14d0f4e0 29
16b6bd01
S
30 video = self._download_json(
31 'https://www.rockstargames.com/videoplayer/videos/get-video.json',
32 video_id, query={
33 'id': video_id,
34 'locale': 'en_us',
35 })['video']
36
37 title = video['title']
14d0f4e0 38
16b6bd01
S
39 formats = []
40 for video in video['files_processed']['video/mp4']:
14d0f4e0
D
41 if not video.get('src'):
42 continue
16b6bd01
S
43 resolution = video.get('resolution')
44 height = int_or_none(self._search_regex(
45 r'^(\d+)[pP]$', resolution or '', 'height', default=None))
14d0f4e0
D
46 formats.append({
47 'url': self._proto_relative_url(video['src']),
16b6bd01
S
48 'format_id': resolution,
49 'height': height,
14d0f4e0 50 })
16b6bd01
S
51
52 if not formats:
53 youtube_id = video.get('youtube_id')
54 if youtube_id:
55 return self.url_result(youtube_id, 'Youtube')
56
14d0f4e0
D
57 return {
58 'id': video_id,
16b6bd01
S
59 'title': title,
60 'description': video.get('description'),
61 'thumbnail': self._proto_relative_url(video.get('screencap')),
62 'timestamp': parse_iso8601(video.get('created')),
14d0f4e0 63 'formats': formats,
14d0f4e0 64 }