]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/giantbomb.py
Imported Debian patch 2015.11.27.1-1.1
[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 unescapeHTML,
9 qualities,
10 int_or_none,
11 )
12
13
14 class GiantBombIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?giantbomb\.com/videos/(?P<display_id>[^/]+)/(?P<id>\d+-\d+)'
16 _TEST = {
17 'url': 'http://www.giantbomb.com/videos/quick-look-destiny-the-dark-below/2300-9782/',
18 'md5': '57badeface303ecf6b98b812de1b9018',
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,
26 'thumbnail': 're:^https?://.*\.jpg$',
27 }
28 }
29
30 def _real_extract(self, url):
31 mobj = re.match(self._VALID_URL, url)
32 video_id = mobj.group('id')
33 display_id = mobj.group('display_id')
34
35 webpage = self._download_webpage(url, display_id)
36
37 title = self._og_search_title(webpage)
38 description = self._og_search_description(webpage)
39 thumbnail = self._og_search_thumbnail(webpage)
40
41 video = json.loads(unescapeHTML(self._search_regex(
42 r'data-video="([^"]+)"', webpage, 'data-video')))
43
44 duration = int_or_none(video.get('lengthSeconds'))
45
46 quality = qualities([
47 'f4m_low', 'progressive_low', 'f4m_high',
48 'progressive_high', 'f4m_hd', 'progressive_hd'])
49
50 formats = []
51 for format_id, video_url in video['videoStreams'].items():
52 if format_id == 'f4m_stream':
53 continue
54 if video_url.endswith('.f4m'):
55 f4m_formats = self._extract_f4m_formats(video_url + '?hdcore=3.3.1', display_id)
56 if f4m_formats:
57 f4m_formats[0]['quality'] = quality(format_id)
58 formats.extend(f4m_formats)
59 else:
60 formats.append({
61 'url': video_url,
62 'format_id': format_id,
63 'quality': quality(format_id),
64 })
65
66 if not formats:
67 youtube_id = video.get('youtubeID')
68 if youtube_id:
69 return self.url_result(youtube_id, 'Youtube')
70
71 self._sort_formats(formats)
72
73 return {
74 'id': video_id,
75 'display_id': display_id,
76 'title': title,
77 'description': description,
78 'thumbnail': thumbnail,
79 'duration': duration,
80 'formats': formats,
81 }