]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/giantbomb.py
debian/copyright: use spaces rather than tabs to start continuation lines.
[youtubedl] / youtube_dl / extractor / giantbomb.py
1 from __future__ import unicode_literals
2
3 import re
4 import json
5
6 from .common import InfoExtractor
7 from ..utils import (
8 determine_ext,
9 int_or_none,
10 qualities,
11 unescapeHTML,
12 )
13
14
15 class GiantBombIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?giantbomb\.com/videos/(?P<display_id>[^/]+)/(?P<id>\d+-\d+)'
17 _TEST = {
18 'url': 'http://www.giantbomb.com/videos/quick-look-destiny-the-dark-below/2300-9782/',
19 'md5': 'c8ea694254a59246a42831155dec57ac',
20 'info_dict': {
21 'id': '2300-9782',
22 'display_id': 'quick-look-destiny-the-dark-below',
23 'ext': 'mp4',
24 'title': 'Quick Look: Destiny: The Dark Below',
25 'description': 'md5:0aa3aaf2772a41b91d44c63f30dfad24',
26 'duration': 2399,
27 'thumbnail': r're:^https?://.*\.jpg$',
28 }
29 }
30
31 def _real_extract(self, url):
32 mobj = re.match(self._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 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 }