microsoftembed.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from .common import InfoExtractor
  2. from ..utils import int_or_none, traverse_obj, unified_timestamp
  3. class MicrosoftEmbedIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?microsoft\.com/(?:[^/]+/)?videoplayer/embed/(?P<id>[a-z0-9A-Z]+)'
  5. _TESTS = [{
  6. 'url': 'https://www.microsoft.com/en-us/videoplayer/embed/RWL07e',
  7. 'md5': 'eb0ae9007f9b305f9acd0a03e74cb1a9',
  8. 'info_dict': {
  9. 'id': 'RWL07e',
  10. 'title': 'Microsoft for Public Health and Social Services',
  11. 'ext': 'mp4',
  12. 'thumbnail': 'http://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RWL7Ju?ver=cae5',
  13. 'age_limit': 0,
  14. 'timestamp': 1631658316,
  15. 'upload_date': '20210914'
  16. }
  17. }]
  18. _API_URL = 'https://prod-video-cms-rt-microsoft-com.akamaized.net/vhs/api/videos/'
  19. def _real_extract(self, url):
  20. video_id = self._match_id(url)
  21. metadata = self._download_json(self._API_URL + video_id, video_id)
  22. formats = []
  23. for source_type, source in metadata['streams'].items():
  24. if source_type == 'smooth_Streaming':
  25. formats.extend(self._extract_ism_formats(source['url'], video_id, 'mss'))
  26. elif source_type == 'apple_HTTP_Live_Streaming':
  27. formats.extend(self._extract_m3u8_formats(source['url'], video_id, 'mp4'))
  28. elif source_type == 'mPEG_DASH':
  29. formats.extend(self._extract_mpd_formats(source['url'], video_id))
  30. else:
  31. formats.append({
  32. 'format_id': source_type,
  33. 'url': source['url'],
  34. 'height': source.get('heightPixels'),
  35. 'width': source.get('widthPixels'),
  36. })
  37. subtitles = {
  38. lang: [{
  39. 'url': data.get('url'),
  40. 'ext': 'vtt',
  41. }] for lang, data in traverse_obj(metadata, 'captions', default={}).items()
  42. }
  43. thumbnails = [{
  44. 'url': thumb.get('url'),
  45. 'width': thumb.get('width') or None,
  46. 'height': thumb.get('height') or None,
  47. } for thumb in traverse_obj(metadata, ('snippet', 'thumbnails', ...))]
  48. self._remove_duplicate_formats(thumbnails)
  49. return {
  50. 'id': video_id,
  51. 'title': traverse_obj(metadata, ('snippet', 'title')),
  52. 'timestamp': unified_timestamp(traverse_obj(metadata, ('snippet', 'activeStartDate'))),
  53. 'age_limit': int_or_none(traverse_obj(metadata, ('snippet', 'minimumAge'))) or 0,
  54. 'formats': formats,
  55. 'subtitles': subtitles,
  56. 'thumbnails': thumbnails,
  57. }