]>
Commit | Line | Data |
---|---|---|
68d301ff S |
1 | import json |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import ( | |
c3c94ca4 | 5 | determine_ext, |
68d301ff | 6 | int_or_none, |
c3c94ca4 YCH |
7 | qualities, |
8 | unescapeHTML, | |
68d301ff S |
9 | ) |
10 | ||
11 | ||
12 | class GiantBombIE(InfoExtractor): | |
8f841faf J |
13 | _VALID_URL = r'https?://(?:www\.)?giantbomb\.com/(?:videos|shows)/(?P<display_id>[^/]+)/(?P<id>\d+-\d+)' |
14 | _TESTS = [{ | |
68d301ff | 15 | 'url': 'http://www.giantbomb.com/videos/quick-look-destiny-the-dark-below/2300-9782/', |
8f841faf | 16 | 'md5': '132f5a803e7e0ab0e274d84bda1e77ae', |
68d301ff S |
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, | |
ec85ded8 | 24 | 'thumbnail': r're:^https?://.*\.jpg$', |
68d301ff | 25 | } |
8f841faf J |
26 | }, { |
27 | 'url': 'https://www.giantbomb.com/shows/ben-stranding/2970-20212', | |
28 | 'only_matching': True, | |
29 | }] | |
68d301ff S |
30 | |
31 | def _real_extract(self, url): | |
5ad28e7f | 32 | mobj = self._match_valid_url(url) |
68d301ff S |
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 | |
c3c94ca4 YCH |
55 | ext = determine_ext(video_url) |
56 | if ext == 'f4m': | |
68d301ff S |
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) | |
c3c94ca4 YCH |
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)) | |
68d301ff S |
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 | self._sort_formats(formats) | |
78 | ||
79 | return { | |
80 | 'id': video_id, | |
81 | 'display_id': display_id, | |
82 | 'title': title, | |
83 | 'description': description, | |
84 | 'thumbnail': thumbnail, | |
85 | 'duration': duration, | |
86 | 'formats': formats, | |
87 | } |