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