logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

microsoftembed.py (13717B)


  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. int_or_none,
  5. parse_iso8601,
  6. traverse_obj,
  7. unified_timestamp,
  8. url_basename,
  9. url_or_none,
  10. )
  11. class MicrosoftEmbedIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?microsoft\.com/(?:[^/]+/)?videoplayer/embed/(?P<id>[a-z0-9A-Z]+)'
  13. _TESTS = [{
  14. 'url': 'https://www.microsoft.com/en-us/videoplayer/embed/RWL07e',
  15. 'md5': 'eb0ae9007f9b305f9acd0a03e74cb1a9',
  16. 'info_dict': {
  17. 'id': 'RWL07e',
  18. 'title': 'Microsoft for Public Health and Social Services',
  19. 'ext': 'mp4',
  20. 'thumbnail': 'http://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RWL7Ju?ver=cae5',
  21. 'age_limit': 0,
  22. 'timestamp': 1631658316,
  23. 'upload_date': '20210914',
  24. },
  25. 'expected_warnings': ['Failed to parse XML: syntax error: line 1, column 0'],
  26. }]
  27. _API_URL = 'https://prod-video-cms-rt-microsoft-com.akamaized.net/vhs/api/videos/'
  28. def _real_extract(self, url):
  29. video_id = self._match_id(url)
  30. metadata = self._download_json(self._API_URL + video_id, video_id)
  31. formats = []
  32. for source_type, source in metadata['streams'].items():
  33. if source_type == 'smooth_Streaming':
  34. formats.extend(self._extract_ism_formats(source['url'], video_id, 'mss', fatal=False))
  35. elif source_type == 'apple_HTTP_Live_Streaming':
  36. formats.extend(self._extract_m3u8_formats(source['url'], video_id, 'mp4', fatal=False))
  37. elif source_type == 'mPEG_DASH':
  38. formats.extend(self._extract_mpd_formats(source['url'], video_id, fatal=False))
  39. else:
  40. formats.append({
  41. 'format_id': source_type,
  42. 'url': source['url'],
  43. 'height': source.get('heightPixels'),
  44. 'width': source.get('widthPixels'),
  45. })
  46. subtitles = {
  47. lang: [{
  48. 'url': data.get('url'),
  49. 'ext': 'vtt',
  50. }] for lang, data in traverse_obj(metadata, 'captions', default={}).items()
  51. }
  52. thumbnails = [{
  53. 'url': thumb.get('url'),
  54. 'width': thumb.get('width') or None,
  55. 'height': thumb.get('height') or None,
  56. } for thumb in traverse_obj(metadata, ('snippet', 'thumbnails', ...))]
  57. self._remove_duplicate_formats(thumbnails)
  58. return {
  59. 'id': video_id,
  60. 'title': traverse_obj(metadata, ('snippet', 'title')),
  61. 'timestamp': unified_timestamp(traverse_obj(metadata, ('snippet', 'activeStartDate'))),
  62. 'age_limit': int_or_none(traverse_obj(metadata, ('snippet', 'minimumAge'))) or 0,
  63. 'formats': formats,
  64. 'subtitles': subtitles,
  65. 'thumbnails': thumbnails,
  66. }
  67. class MicrosoftMediusBaseIE(InfoExtractor):
  68. @staticmethod
  69. def _sub_to_dict(subtitle_list):
  70. subtitles = {}
  71. for sub in subtitle_list:
  72. subtitles.setdefault(sub.pop('tag', 'und'), []).append(sub)
  73. return subtitles
  74. def _extract_ism(self, ism_url, video_id):
  75. formats = self._extract_ism_formats(ism_url, video_id)
  76. for fmt in formats:
  77. if fmt['language'] != 'eng' and 'English' not in fmt['format_id']:
  78. fmt['language_preference'] = -10
  79. return formats
  80. class MicrosoftMediusIE(MicrosoftMediusBaseIE):
  81. _VALID_URL = r'https?://medius\.microsoft\.com/Embed/(?:Video\?id=|video-nc/|VideoDetails/)(?P<id>[\da-f-]+)'
  82. _TESTS = [{
  83. 'url': 'https://medius.microsoft.com/Embed/video-nc/9640d86c-f513-4889-959e-5dace86e7d2b',
  84. 'info_dict': {
  85. 'id': '9640d86c-f513-4889-959e-5dace86e7d2b',
  86. 'ext': 'ismv',
  87. 'title': 'Rapidly code, test and ship from secure cloud developer environments',
  88. 'description': 'md5:33c8e4facadc438613476eea24165f71',
  89. 'thumbnail': r're:https://mediusimg\.event\.microsoft\.com/video-\d+/thumbnail\.jpg.*',
  90. 'subtitles': 'count:30',
  91. },
  92. }, {
  93. 'url': 'https://medius.microsoft.com/Embed/video-nc/81215af5-c813-4dcd-aede-94f4e1a7daa3',
  94. 'info_dict': {
  95. 'id': '81215af5-c813-4dcd-aede-94f4e1a7daa3',
  96. 'ext': 'ismv',
  97. 'title': 'Microsoft Build opening',
  98. 'description': 'md5:43455096141077a1f23144cab8cec1cb',
  99. 'thumbnail': r're:https://mediusimg\.event\.microsoft\.com/video-\d+/thumbnail\.jpg.*',
  100. 'subtitles': 'count:31',
  101. },
  102. }, {
  103. 'url': 'https://medius.microsoft.com/Embed/VideoDetails/78493569-9b3b-4a85-a409-ee76e789e25c',
  104. 'info_dict': {
  105. 'id': '78493569-9b3b-4a85-a409-ee76e789e25c',
  106. 'ext': 'ismv',
  107. 'title': ' Anomaly Detection & Root cause at Edge',
  108. 'description': 'md5:f8f1ad93d7918649bfb97fa081b03b83',
  109. 'thumbnail': r're:https://mediusdownload.event.microsoft.com/asset.*\.jpg.*',
  110. 'subtitles': 'count:17',
  111. },
  112. }, {
  113. 'url': 'https://medius.microsoft.com/Embed/Video?id=0dc69bda-079b-4070-a7db-a8da1a06a9c7',
  114. 'only_matching': True,
  115. }, {
  116. 'url': 'https://medius.microsoft.com/Embed/video-nc/fe823a91-959c-465b-96d4-8f4db624f72c',
  117. 'only_matching': True,
  118. }]
  119. def _extract_subtitle(self, webpage, video_id):
  120. captions = traverse_obj(
  121. self._search_json(r'const\s+captionsConfiguration\s*=', webpage, 'captions', video_id, default=None),
  122. ('languageList', lambda _, v: url_or_none(v['src']), {
  123. 'url': 'src',
  124. 'tag': ('srclang', {str}),
  125. 'name': ('kind', {str}),
  126. })) or [{'url': url, 'tag': url_basename(url).split('.vtt')[0].split('_')[-1]}
  127. for url in re.findall(r'var\s+file\s+=\s+\{[^}]+\'(https://[^\']+\.vtt\?[^\']+)', webpage)]
  128. return self._sub_to_dict(captions)
  129. def _real_extract(self, url):
  130. video_id = self._match_id(url)
  131. webpage = self._download_webpage(f'https://medius.microsoft.com/Embed/video-nc/{video_id}', video_id)
  132. return {
  133. 'id': video_id,
  134. 'title': self._og_search_title(webpage),
  135. 'description': self._og_search_description(webpage),
  136. 'formats': self._extract_ism(
  137. self._search_regex(r'StreamUrl\s*=\s*"([^"]+manifest)"', webpage, 'ism url'), video_id),
  138. 'thumbnail': self._og_search_thumbnail(webpage),
  139. 'subtitles': self._extract_subtitle(webpage, video_id),
  140. }
  141. class MicrosoftLearnPlaylistIE(InfoExtractor):
  142. _VALID_URL = r'https?://learn\.microsoft\.com/(?:[\w-]+/)?(?P<type>shows|events)/(?P<id>[\w-]+)/?(?:[?#]|$)'
  143. _TESTS = [{
  144. 'url': 'https://learn.microsoft.com/en-us/shows/bash-for-beginners',
  145. 'info_dict': {
  146. 'id': 'bash-for-beginners',
  147. 'title': 'Bash for Beginners',
  148. 'description': 'md5:16a91c07222117d1e00912f0dbc02c2c',
  149. },
  150. 'playlist_count': 20,
  151. }, {
  152. 'url': 'https://learn.microsoft.com/en-us/events/build-2022',
  153. 'info_dict': {
  154. 'id': 'build-2022',
  155. 'title': 'Microsoft Build 2022 - Events',
  156. 'description': 'md5:c16b43848027df837b22c6fbac7648d3',
  157. },
  158. 'playlist_count': 201,
  159. }]
  160. def _entries(self, url_base, video_id):
  161. skip = 0
  162. while True:
  163. playlist_info = self._download_json(url_base, video_id, f'Downloading entries {skip}', query={
  164. 'locale': 'en-us',
  165. '$skip': skip,
  166. })
  167. url_paths = traverse_obj(playlist_info, ('results', ..., 'url', {str}))
  168. for url_path in url_paths:
  169. yield self.url_result(f'https://learn.microsoft.com/en-us{url_path}')
  170. skip += len(url_paths)
  171. if skip >= playlist_info.get('count', 0) or not url_paths:
  172. break
  173. def _real_extract(self, url):
  174. playlist_id, playlist_type = self._match_valid_url(url).group('id', 'type')
  175. webpage = self._download_webpage(url, playlist_id)
  176. metainfo = {
  177. 'title': self._og_search_title(webpage),
  178. 'description': self._og_search_description(webpage),
  179. }
  180. sub_type = 'episodes' if playlist_type == 'shows' else 'sessions'
  181. url_base = f'https://learn.microsoft.com/api/contentbrowser/search/{playlist_type}/{playlist_id}/{sub_type}'
  182. return self.playlist_result(self._entries(url_base, playlist_id), playlist_id, **metainfo)
  183. class MicrosoftLearnEpisodeIE(MicrosoftMediusBaseIE):
  184. _VALID_URL = r'https?://learn\.microsoft\.com/(?:[\w-]+/)?shows/[\w-]+/(?P<id>[^?#/]+)'
  185. _TESTS = [{
  186. '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/',
  187. 'info_dict': {
  188. 'id': 'd44e1a03-a0e5-45c2-9496-5c9fa08dc94c',
  189. 'ext': 'ismv',
  190. 'title': 'What is the Difference Between a Terminal and a Shell? (Part 2 of 20)',
  191. 'description': 'md5:7bbbfb593d21c2cf2babc3715ade6b88',
  192. 'timestamp': 1676339547,
  193. 'upload_date': '20230214',
  194. 'thumbnail': r're:https://learn\.microsoft\.com/video/media/.*\.png',
  195. 'subtitles': 'count:14',
  196. },
  197. }]
  198. def _real_extract(self, url):
  199. video_id = self._match_id(url)
  200. webpage = self._download_webpage(url, video_id)
  201. entry_id = self._html_search_meta('entryId', webpage, 'entryId', fatal=True)
  202. video_info = self._download_json(
  203. f'https://learn.microsoft.com/api/video/public/v1/entries/{entry_id}', video_id)
  204. return {
  205. 'id': entry_id,
  206. 'formats': self._extract_ism(video_info['publicVideo']['adaptiveVideoUrl'], video_id),
  207. 'subtitles': self._sub_to_dict(traverse_obj(video_info, (
  208. 'publicVideo', 'captions', lambda _, v: url_or_none(v['url']), {
  209. 'tag': ('language', {str}),
  210. 'url': 'url',
  211. }))),
  212. 'title': self._og_search_title(webpage),
  213. 'description': self._og_search_description(webpage),
  214. **traverse_obj(video_info, {
  215. 'timestamp': ('createTime', {parse_iso8601}),
  216. 'thumbnails': ('publicVideo', 'thumbnailOtherSizes', ..., {'url': {url_or_none}}),
  217. }),
  218. }
  219. class MicrosoftLearnSessionIE(InfoExtractor):
  220. _VALID_URL = r'https?://learn\.microsoft\.com/(?:[\w-]+/)?events/[\w-]+/(?P<id>[^?#/]+)'
  221. _TESTS = [{
  222. 'url': 'https://learn.microsoft.com/en-us/events/build-2022/ts01-rapidly-code-test-ship-from-secure-cloud-developer-environments',
  223. 'info_dict': {
  224. 'id': '9640d86c-f513-4889-959e-5dace86e7d2b',
  225. 'ext': 'ismv',
  226. 'title': 'Rapidly code, test and ship from secure cloud developer environments - Events',
  227. 'description': 'md5:f26c1a85d41c1cffd27a0279254a25c3',
  228. 'timestamp': 1653408600,
  229. 'upload_date': '20220524',
  230. 'thumbnail': r're:https://mediusimg\.event\.microsoft\.com/video-\d+/thumbnail\.jpg.*',
  231. },
  232. }]
  233. def _real_extract(self, url):
  234. video_id = self._match_id(url)
  235. webpage = self._download_webpage(url, video_id)
  236. metainfo = {
  237. 'title': self._og_search_title(webpage),
  238. 'description': self._og_search_description(webpage),
  239. 'timestamp': parse_iso8601(self._html_search_meta('startDate', webpage, 'startDate')),
  240. }
  241. return self.url_result(
  242. self._html_search_meta('externalVideoUrl', webpage, 'videoUrl', fatal=True),
  243. url_transparent=True, ie=MicrosoftMediusIE, **metainfo)
  244. class MicrosoftBuildIE(InfoExtractor):
  245. _VALID_URL = [
  246. r'https?://build\.microsoft\.com/[\w-]+/sessions/(?P<id>[\da-f-]+)',
  247. r'https?://build\.microsoft\.com/[\w-]+/(?P<id>sessions)/?(?:[?#]|$)',
  248. ]
  249. _TESTS = [{
  250. 'url': 'https://build.microsoft.com/en-US/sessions/b49feb31-afcd-4217-a538-d3ca1d171198?source=sessions',
  251. 'info_dict': {
  252. 'id': 'aee55fb5-fcf9-4b38-b764-a3527cb57554',
  253. 'ext': 'ismv',
  254. 'title': 'Microsoft Build opening keynote',
  255. 'description': 'md5:d38338f336ef4b6ef9ad2a7466a76655',
  256. 'timestamp': 1716307200,
  257. 'upload_date': '20240521',
  258. 'thumbnail': r're:https://mediusimg\.event\.microsoft\.com/video-\d+/thumbnail\.jpg.*',
  259. },
  260. }, {
  261. 'url': 'https://build.microsoft.com/en-US/sessions',
  262. 'info_dict': {
  263. 'id': 'sessions',
  264. },
  265. 'playlist_mincount': 418,
  266. }]
  267. def _real_extract(self, url):
  268. video_id = self._match_id(url)
  269. entries = [
  270. self.url_result(
  271. video_info['onDemand'], ie=MicrosoftMediusIE, url_transparent=True, **traverse_obj(video_info, {
  272. 'id': ('sessionId', {str}),
  273. 'title': ('title', {str}),
  274. 'description': ('description', {str}),
  275. 'timestamp': ('startDateTime', {parse_iso8601}),
  276. }))
  277. for video_info in self._download_json(
  278. 'https://api-v2.build.microsoft.com/api/session/all/en-US', video_id, 'Downloading video info')
  279. ]
  280. if video_id == 'sessions':
  281. return self.playlist_result(entries, video_id)
  282. else:
  283. return traverse_obj(entries, (lambda _, v: v['id'] == video_id), get_all=False)