]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/dispeak.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / dispeak.py
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
13 class DigitallySpeakingIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:s?evt\.dispeak|events\.digitallyspeaking)\.com/(?:[^/]+/)+xml/(?P<id>[^.]+)\.xml'
15
16 _TESTS = [{
17 # From http://gdcvault.com/play/1023460/Tenacious-Design-and-The-Interface
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 },
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,
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,
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,
45 }]
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 = f'http://{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
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))
75 video_formats.append({
76 'format_id': bitrate,
77 'url': url,
78 'tbr': tbr,
79 'vbr': vbr,
80 })
81 return video_formats
82
83 def _parse_flv(self, metadata):
84 formats = []
85 akamai_url = xpath_text(metadata, './akamaiHost', fatal=True)
86 audios = metadata.findall('./audios/audio')
87 for audio in audios:
88 formats.append({
89 'url': f'rtmp://{akamai_url}/ondemand?ovpfv=1.1',
90 'play_path': remove_end(audio.get('url'), '.flv'),
91 'ext': 'flv',
92 'vcodec': 'none',
93 'quality': 1,
94 'format_id': audio.get('code'),
95 })
96 for video_key, format_id, preference in (
97 ('slide', 'slides', -2), ('speaker', 'speaker', -1)):
98 video_path = xpath_text(metadata, f'./{video_key}Video')
99 if not video_path:
100 continue
101 formats.append({
102 'url': f'rtmp://{akamai_url}/ondemand?ovpfv=1.1',
103 'play_path': remove_end(video_path, '.flv'),
104 'ext': 'flv',
105 'format_note': f'{video_key} video',
106 'quality': preference,
107 'format_id': format_id,
108 })
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)
120
121 return {
122 'id': video_id,
123 'formats': video_formats,
124 'title': xpath_text(metadata, 'title', fatal=True),
125 'duration': parse_duration(xpath_text(metadata, 'endTime')),
126 'creator': xpath_text(metadata, 'speaker'),
127 }