]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/giantbomb.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / giantbomb.py
1 import json
2
3 from .common import InfoExtractor
4 from ..utils import (
5 determine_ext,
6 int_or_none,
7 qualities,
8 unescapeHTML,
9 )
10
11
12 class GiantBombIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?giantbomb\.com/(?:videos|shows)/(?P<display_id>[^/]+)/(?P<id>\d+-\d+)'
14 _TESTS = [{
15 'url': 'http://www.giantbomb.com/videos/quick-look-destiny-the-dark-below/2300-9782/',
16 'md5': '132f5a803e7e0ab0e274d84bda1e77ae',
17 'info_dict': {
18 'id': '2300-9782',
19 'display_id': 'quick-look-destiny-the-dark-below',
20 'ext': 'mp4',
21 'title': 'Quick Look: Destiny: The Dark Below',
22 'description': 'md5:0aa3aaf2772a41b91d44c63f30dfad24',
23 'duration': 2399,
24 'thumbnail': r're:^https?://.*\.jpg$',
25 }
26 }, {
27 'url': 'https://www.giantbomb.com/shows/ben-stranding/2970-20212',
28 'only_matching': True,
29 }]
30
31 def _real_extract(self, url):
32 mobj = self._match_valid_url(url)
33 video_id = mobj.group('id')
34 display_id = mobj.group('display_id')
35
36 webpage = self._download_webpage(url, display_id)
37
38 title = self._og_search_title(webpage)
39 description = self._og_search_description(webpage)
40 thumbnail = self._og_search_thumbnail(webpage)
41
42 video = json.loads(unescapeHTML(self._search_regex(
43 r'data-video="([^"]+)"', webpage, 'data-video')))
44
45 duration = int_or_none(video.get('lengthSeconds'))
46
47 quality = qualities([
48 'f4m_low', 'progressive_low', 'f4m_high',
49 'progressive_high', 'f4m_hd', 'progressive_hd'])
50
51 formats = []
52 for format_id, video_url in video['videoStreams'].items():
53 if format_id == 'f4m_stream':
54 continue
55 ext = determine_ext(video_url)
56 if ext == 'f4m':
57 f4m_formats = self._extract_f4m_formats(video_url + '?hdcore=3.3.1', display_id)
58 if f4m_formats:
59 f4m_formats[0]['quality'] = quality(format_id)
60 formats.extend(f4m_formats)
61 elif ext == 'm3u8':
62 formats.extend(self._extract_m3u8_formats(
63 video_url, display_id, ext='mp4', entry_protocol='m3u8_native',
64 m3u8_id='hls', fatal=False))
65 else:
66 formats.append({
67 'url': video_url,
68 'format_id': format_id,
69 'quality': quality(format_id),
70 })
71
72 if not formats:
73 youtube_id = video.get('youtubeID')
74 if youtube_id:
75 return self.url_result(youtube_id, 'Youtube')
76
77 return {
78 'id': video_id,
79 'display_id': display_id,
80 'title': title,
81 'description': description,
82 'thumbnail': thumbnail,
83 'duration': duration,
84 'formats': formats,
85 }