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