]>
Commit | Line | Data |
---|---|---|
ec59d657 YCH |
1 | from __future__ import unicode_literals |
2 | ||
3 | import re | |
4 | ||
5 | from .common import InfoExtractor | |
6 | from ..utils import ( | |
7 | int_or_none, | |
8 | parse_duration, | |
9 | remove_end, | |
10 | xpath_element, | |
11 | xpath_text, | |
12 | ) | |
13 | ||
14 | ||
982e518a | 15 | class DigitallySpeakingIE(InfoExtractor): |
d20b1c67 | 16 | _VALID_URL = r'https?://(?:s?evt\.dispeak|events\.digitallyspeaking)\.com/(?:[^/]+/)+xml/(?P<id>[^.]+)\.xml' |
ec59d657 | 17 | |
442c4d36 | 18 | _TESTS = [{ |
748e7300 | 19 | # From http://gdcvault.com/play/1023460/Tenacious-Design-and-The-Interface |
ec59d657 YCH |
20 | 'url': 'http://evt.dispeak.com/ubm/gdc/sf16/xml/840376_BQRC.xml', |
21 | 'md5': 'a8efb6c31ed06ca8739294960b2dbabd', | |
22 | 'info_dict': { | |
23 | 'id': '840376_BQRC', | |
24 | 'ext': 'mp4', | |
25 | 'title': 'Tenacious Design and The Interface of \'Destiny\'', | |
26 | }, | |
442c4d36 YCH |
27 | }, { |
28 | # From http://www.gdcvault.com/play/1014631/Classic-Game-Postmortem-PAC | |
29 | 'url': 'http://events.digitallyspeaking.com/gdc/sf11/xml/12396_1299111843500GMPX.xml', | |
30 | 'only_matching': True, | |
d20b1c67 YCH |
31 | }, { |
32 | # From http://www.gdcvault.com/play/1013700/Advanced-Material | |
33 | 'url': 'http://sevt.dispeak.com/ubm/gdc/eur10/xml/11256_1282118587281VNIT.xml', | |
34 | 'only_matching': True, | |
41d1cca3 | 35 | }, { |
36 | # From https://gdcvault.com/play/1016624, empty speakerVideo | |
37 | 'url': 'https://sevt.dispeak.com/ubm/gdc/online12/xml/201210-822101_1349794556671DDDD.xml', | |
38 | 'info_dict': { | |
39 | 'id': '201210-822101_1349794556671DDDD', | |
40 | 'ext': 'flv', | |
41 | 'title': 'Pre-launch - Preparing to Take the Plunge', | |
42 | }, | |
43 | }, { | |
44 | # From http://www.gdcvault.com/play/1014846/Conference-Keynote-Shigeru, empty slideVideo | |
45 | 'url': 'http://events.digitallyspeaking.com/gdc/project25/xml/p25-miyamoto1999_1282467389849HSVB.xml', | |
46 | 'only_matching': True, | |
442c4d36 | 47 | }] |
ec59d657 YCH |
48 | |
49 | def _parse_mp4(self, metadata): | |
50 | video_formats = [] | |
51 | video_root = None | |
52 | ||
53 | mp4_video = xpath_text(metadata, './mp4video', default=None) | |
54 | if mp4_video is not None: | |
55 | mobj = re.match(r'(?P<root>https?://.*?/).*', mp4_video) | |
56 | video_root = mobj.group('root') | |
57 | if video_root is None: | |
58 | http_host = xpath_text(metadata, 'httpHost', default=None) | |
59 | if http_host: | |
60 | video_root = 'http://%s/' % http_host | |
61 | if video_root is None: | |
62 | # Hard-coded in http://evt.dispeak.com/ubm/gdc/sf16/custom/player2.js | |
63 | # Works for GPUTechConf, too | |
64 | video_root = 'http://s3-2u.digitallyspeaking.com/' | |
65 | ||
66 | formats = metadata.findall('./MBRVideos/MBRVideo') | |
67 | if not formats: | |
68 | return None | |
69 | for a_format in formats: | |
70 | stream_name = xpath_text(a_format, 'streamName', fatal=True) | |
71 | video_path = re.match(r'mp4\:(?P<path>.*)', stream_name).group('path') | |
72 | url = video_root + video_path | |
4bc12b8f RA |
73 | bitrate = xpath_text(a_format, 'bitrate') |
74 | tbr = int_or_none(bitrate) | |
75 | vbr = int_or_none(self._search_regex( | |
76 | r'-(\d+)\.mp4', video_path, 'vbr', default=None)) | |
ec59d657 | 77 | video_formats.append({ |
4bc12b8f | 78 | 'format_id': bitrate, |
ec59d657 | 79 | 'url': url, |
4bc12b8f RA |
80 | 'tbr': tbr, |
81 | 'vbr': vbr, | |
ec59d657 YCH |
82 | }) |
83 | return video_formats | |
84 | ||
85 | def _parse_flv(self, metadata): | |
86 | formats = [] | |
87 | akamai_url = xpath_text(metadata, './akamaiHost', fatal=True) | |
442c4d36 YCH |
88 | audios = metadata.findall('./audios/audio') |
89 | for audio in audios: | |
90 | formats.append({ | |
91 | 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url, | |
92 | 'play_path': remove_end(audio.get('url'), '.flv'), | |
93 | 'ext': 'flv', | |
94 | 'vcodec': 'none', | |
f983b875 | 95 | 'quality': 1, |
442c4d36 YCH |
96 | 'format_id': audio.get('code'), |
97 | }) | |
41d1cca3 | 98 | for video_key, format_id, preference in ( |
99 | ('slide', 'slides', -2), ('speaker', 'speaker', -1)): | |
100 | video_path = xpath_text(metadata, './%sVideo' % video_key) | |
101 | if not video_path: | |
102 | continue | |
103 | formats.append({ | |
104 | 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url, | |
105 | 'play_path': remove_end(video_path, '.flv'), | |
106 | 'ext': 'flv', | |
107 | 'format_note': '%s video' % video_key, | |
108 | 'quality': preference, | |
109 | 'format_id': format_id, | |
110 | }) | |
ec59d657 YCH |
111 | return formats |
112 | ||
113 | def _real_extract(self, url): | |
114 | video_id = self._match_id(url) | |
115 | ||
116 | xml_description = self._download_xml(url, video_id) | |
117 | metadata = xpath_element(xml_description, 'metadata') | |
118 | ||
119 | video_formats = self._parse_mp4(metadata) | |
120 | if video_formats is None: | |
121 | video_formats = self._parse_flv(metadata) | |
6970b600 | 122 | self._sort_formats(video_formats) |
ec59d657 YCH |
123 | |
124 | return { | |
125 | 'id': video_id, | |
126 | 'formats': video_formats, | |
127 | 'title': xpath_text(metadata, 'title', fatal=True), | |
128 | 'duration': parse_duration(xpath_text(metadata, 'endTime')), | |
129 | 'creator': xpath_text(metadata, 'speaker'), | |
130 | } |