3 from .common
import InfoExtractor
14 class MicrosoftEmbedIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:www\.)?microsoft\.com/(?:[^/]+/)?videoplayer/embed/(?P<id>[a-z0-9A-Z]+)'
18 'url': 'https://www.microsoft.com/en-us/videoplayer/embed/RWL07e',
19 'md5': 'eb0ae9007f9b305f9acd0a03e74cb1a9',
22 'title': 'Microsoft for Public Health and Social Services',
24 'thumbnail': 'http://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RWL7Ju?ver=cae5',
26 'timestamp': 1631658316,
27 'upload_date': '20210914',
29 'expected_warnings': ['Failed to parse XML: syntax error: line 1, column 0'],
31 _API_URL
= 'https://prod-video-cms-rt-microsoft-com.akamaized.net/vhs/api/videos/'
33 def _real_extract(self
, url
):
34 video_id
= self
._match
_id
(url
)
35 metadata
= self
._download
_json
(self
._API
_URL
+ video_id
, video_id
)
38 for source_type
, source
in metadata
['streams'].items():
39 if source_type
== 'smooth_Streaming':
40 formats
.extend(self
._extract
_ism
_formats
(source
['url'], video_id
, 'mss', fatal
=False))
41 elif source_type
== 'apple_HTTP_Live_Streaming':
42 formats
.extend(self
._extract
_m
3u8_formats
(source
['url'], video_id
, 'mp4', fatal
=False))
43 elif source_type
== 'mPEG_DASH':
44 formats
.extend(self
._extract
_mpd
_formats
(source
['url'], video_id
, fatal
=False))
47 'format_id': source_type
,
49 'height': source
.get('heightPixels'),
50 'width': source
.get('widthPixels'),
55 'url': data
.get('url'),
57 }] for lang
, data
in traverse_obj(metadata
, 'captions', default
={}).items()
61 'url': thumb
.get('url'),
62 'width': thumb
.get('width') or None,
63 'height': thumb
.get('height') or None,
64 } for thumb
in traverse_obj(metadata
, ('snippet', 'thumbnails', ...))]
65 self
._remove
_duplicate
_formats
(thumbnails
)
69 'title': traverse_obj(metadata
, ('snippet', 'title')),
70 'timestamp': unified_timestamp(traverse_obj(metadata
, ('snippet', 'activeStartDate'))),
71 'age_limit': int_or_none(traverse_obj(metadata
, ('snippet', 'minimumAge'))) or 0,
73 'subtitles': subtitles
,
74 'thumbnails': thumbnails
,
78 class MicrosoftMediusBaseIE(InfoExtractor
):
80 def _sub_to_dict(subtitle_list
):
82 for sub
in subtitle_list
:
83 subtitles
.setdefault(sub
.pop('tag', 'und'), []).append(sub
)
86 def _extract_ism(self
, ism_url
, video_id
):
87 formats
= self
._extract
_ism
_formats
(ism_url
, video_id
)
89 if fmt
['language'] != 'eng' and 'English' not in fmt
['format_id']:
90 fmt
['language_preference'] = -10
94 class MicrosoftMediusIE(MicrosoftMediusBaseIE
):
95 _VALID_URL
= r
'https?://medius\.microsoft\.com/Embed/(?:Video\?id=|video-nc/|VideoDetails/)(?P<id>[\da-f-]+)'
98 'url': 'https://medius.microsoft.com/Embed/video-nc/9640d86c-f513-4889-959e-5dace86e7d2b',
100 'id': '9640d86c-f513-4889-959e-5dace86e7d2b',
102 'title': 'Rapidly code, test and ship from secure cloud developer environments',
103 'description': 'md5:33c8e4facadc438613476eea24165f71',
104 'thumbnail': r
're:https://mediusimg\.event\.microsoft\.com/video-\d+/thumbnail\.jpg.*',
105 'subtitles': 'count:30',
108 'url': 'https://medius.microsoft.com/Embed/video-nc/81215af5-c813-4dcd-aede-94f4e1a7daa3',
110 'id': '81215af5-c813-4dcd-aede-94f4e1a7daa3',
112 'title': 'Microsoft Build opening',
113 'description': 'md5:43455096141077a1f23144cab8cec1cb',
114 'thumbnail': r
're:https://mediusimg\.event\.microsoft\.com/video-\d+/thumbnail\.jpg.*',
115 'subtitles': 'count:31',
118 'url': 'https://medius.microsoft.com/Embed/VideoDetails/78493569-9b3b-4a85-a409-ee76e789e25c',
120 'id': '78493569-9b3b-4a85-a409-ee76e789e25c',
122 'title': ' Anomaly Detection & Root cause at Edge',
123 'description': 'md5:f8f1ad93d7918649bfb97fa081b03b83',
124 'thumbnail': r
're:https://mediusdownload.event.microsoft.com/asset.*\.jpg.*',
125 'subtitles': 'count:17',
128 'url': 'https://medius.microsoft.com/Embed/Video?id=0dc69bda-079b-4070-a7db-a8da1a06a9c7',
129 'only_matching': True,
131 'url': 'https://medius.microsoft.com/Embed/video-nc/fe823a91-959c-465b-96d4-8f4db624f72c',
132 'only_matching': True,
135 def _extract_subtitle(self
, webpage
, video_id
):
136 captions
= traverse_obj(
137 self
._search
_json
(r
'const\s+captionsConfiguration\s*=', webpage
, 'captions', video_id
, default
=None),
138 ('languageList', lambda _
, v
: url_or_none(v
['src']), {
140 'tag': ('srclang', {str}
),
141 'name': ('kind', {str}
),
142 })) or [{'url': url
, 'tag': url_basename(url
).split('.vtt')[0].split('_')[-1]}
143 for url
in re
.findall(r
'var\s+file\s+=\s+\{[^}]+\'(https
://[^
\']+\
.vtt
\?[^
\']+)', webpage)]
145 return self._sub_to_dict(captions)
147 def _real_extract(self, url):
148 video_id = self._match_id(url)
149 webpage = self._download_webpage(f'https
://medius
.microsoft
.com
/Embed
/video
-nc
/{video_id}
', video_id)
153 'title
': self._og_search_title(webpage),
154 'description
': self._og_search_description(webpage),
155 'formats
': self._extract_ism(
156 self._search_regex(r'StreamUrl\s
*=\s
*"([^"]+manifest
)"', webpage, 'ism url'), video_id),
157 'thumbnail': self._og_search_thumbnail(webpage),
158 'subtitles': self._extract_subtitle(webpage, video_id),
162 class MicrosoftLearnPlaylistIE(InfoExtractor):
163 _VALID_URL = r'https?://learn\.microsoft\.com/(?:[\w-]+/)?(?P<type>shows|events)/(?P<id>[\w-]+)/?(?:[?#]|$)'
165 'url': 'https://learn.microsoft.com/en-us/shows/bash-for-beginners',
167 'id': 'bash-for-beginners',
168 'title': 'Bash for Beginners',
169 'description': 'md5:16a91c07222117d1e00912f0dbc02c2c',
171 'playlist_count': 20,
173 'url': 'https://learn.microsoft.com/en-us/events/build-2022',
176 'title': 'Microsoft Build 2022 - Events',
177 'description': 'md5:c16b43848027df837b22c6fbac7648d3',
179 'playlist_count': 201,
182 def _entries(self, url_base, video_id):
185 playlist_info = self._download_json(url_base, video_id, f'Downloading entries {skip}', query={
189 url_paths = traverse_obj(playlist_info, ('results', ..., 'url', {str}))
190 for url_path in url_paths:
191 yield self.url_result(f'https://learn.microsoft.com/en-us{url_path}')
192 skip += len(url_paths)
193 if skip >= playlist_info.get('count', 0) or not url_paths:
196 def _real_extract(self, url):
197 playlist_id, playlist_type = self._match_valid_url(url).group('id', 'type')
198 webpage = self._download_webpage(url, playlist_id)
201 'title': self._og_search_title(webpage),
202 'description': self._og_search_description(webpage),
204 sub_type = 'episodes' if playlist_type == 'shows' else 'sessions'
206 url_base = f'https://learn.microsoft.com/api/contentbrowser/search/{playlist_type}/{playlist_id}/{sub_type}'
207 return self.playlist_result(self._entries(url_base, playlist_id), playlist_id, **metainfo)
210 class MicrosoftLearnEpisodeIE(MicrosoftMediusBaseIE):
211 _VALID_URL = r'https?://learn\.microsoft\.com/(?:[\w-]+/)?shows/[\w-]+/(?P<id>[^?#/]+)'
213 'url': 'https://learn.microsoft.com/en-us/shows/bash-for-beginners/what-is-the-difference-between-a-terminal-and-a-shell-2-of-20-bash-for-beginners/',
215 'id': 'd44e1a03-a0e5-45c2-9496-5c9fa08dc94c',
217 'title': 'What is the Difference Between a Terminal and a Shell? (Part 2 of 20)',
218 'description': 'md5:7bbbfb593d21c2cf2babc3715ade6b88',
219 'timestamp': 1676339547,
220 'upload_date': '20230214',
221 'thumbnail': r're:https://learn\.microsoft\.com/video/media/.*\.png',
222 'subtitles': 'count:14',
226 def _real_extract(self, url):
227 video_id = self._match_id(url)
228 webpage = self._download_webpage(url, video_id)
230 entry_id = self._html_search_meta('entryId', webpage, 'entryId', fatal=True)
231 video_info = self._download_json(
232 f'https://learn.microsoft.com/api/video/public/v1/entries/{entry_id}', video_id)
235 'formats': self._extract_ism(video_info['publicVideo']['adaptiveVideoUrl'], video_id),
236 'subtitles': self._sub_to_dict(traverse_obj(video_info, (
237 'publicVideo', 'captions', lambda _, v: url_or_none(v['url']), {
238 'tag': ('language', {str}),
241 'title': self._og_search_title(webpage),
242 'description': self._og_search_description(webpage),
243 **traverse_obj(video_info, {
244 'timestamp': ('createTime', {parse_iso8601}),
245 'thumbnails': ('publicVideo', 'thumbnailOtherSizes', ..., {'url': {url_or_none}}),
250 class MicrosoftLearnSessionIE(InfoExtractor):
251 _VALID_URL = r'https?://learn\.microsoft\.com/(?:[\w-]+/)?events/[\w-]+/(?P<id>[^?#/]+)'
253 'url': 'https://learn.microsoft.com/en-us/events/build-2022/ts01-rapidly-code-test-ship-from-secure-cloud-developer-environments',
255 'id': '9640d86c-f513-4889-959e-5dace86e7d2b',
257 'title': 'Rapidly code, test and ship from secure cloud developer environments - Events',
258 'description': 'md5:f26c1a85d41c1cffd27a0279254a25c3',
259 'timestamp': 1653408600,
260 'upload_date': '20220524',
261 'thumbnail': r're:https://mediusimg\.event\.microsoft\.com/video-\d+/thumbnail\.jpg.*',
265 def _real_extract(self, url):
266 video_id = self._match_id(url)
267 webpage = self._download_webpage(url, video_id)
270 'title': self._og_search_title(webpage),
271 'description': self._og_search_description(webpage),
272 'timestamp': parse_iso8601(self._html_search_meta('startDate', webpage, 'startDate')),
275 return self.url_result(
276 self._html_search_meta('externalVideoUrl', webpage, 'videoUrl', fatal=True),
277 url_transparent=True, ie=MicrosoftMediusIE, **metainfo)
280 class MicrosoftBuildIE(InfoExtractor):
282 r'https?://build\.microsoft\.com/[\w-]+/sessions/(?P<id>[\da-f-]+)',
283 r'https?://build\.microsoft\.com/[\w-]+/(?P<id>sessions)/?(?:[?#]|$)',
287 'url': 'https://build.microsoft.com/en-US/sessions/b49feb31-afcd-4217-a538-d3ca1d171198?source=sessions',
289 'id': 'aee55fb5-fcf9-4b38-b764-a3527cb57554',
291 'title': 'Microsoft Build opening keynote',
292 'description': 'md5:d38338f336ef4b6ef9ad2a7466a76655',
293 'timestamp': 1716307200,
294 'upload_date': '20240521',
295 'thumbnail': r're:https://mediusimg\.event\.microsoft\.com/video-\d+/thumbnail\.jpg.*',
298 'url': 'https://build.microsoft.com/en-US/sessions',
302 'playlist_mincount': 418,
305 def _real_extract(self, url):
306 video_id = self._match_id(url)
310 video_info['onDemand'], ie=MicrosoftMediusIE, url_transparent=True, **traverse_obj(video_info, {
311 'id': ('sessionId', {str}),
312 'title': ('title', {str}),
313 'description': ('description', {str}),
314 'timestamp': ('startDateTime', {parse_iso8601}),
316 for video_info in self._download_json(
317 'https://api-v2.build.microsoft.com/api/session/all/en-US', video_id, 'Downloading video info')
319 if video_id == 'sessions':
320 return self.playlist_result(entries, video_id)
322 return traverse_obj(entries, (lambda _, v: v['id'] == video_id), get_all=False)