msn.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. determine_ext,
  6. int_or_none,
  7. unescapeHTML,
  8. )
  9. class MSNIE(InfoExtractor):
  10. _WORKING = False
  11. _VALID_URL = r'https?://(?:(?:www|preview)\.)?msn\.com/(?:[^/]+/)+(?P<display_id>[^/]+)/[a-z]{2}-(?P<id>[\da-zA-Z]+)'
  12. _TESTS = [{
  13. 'url': 'https://www.msn.com/en-in/money/video/7-ways-to-get-rid-of-chest-congestion/vi-BBPxU6d',
  14. 'md5': '087548191d273c5c55d05028f8d2cbcd',
  15. 'info_dict': {
  16. 'id': 'BBPxU6d',
  17. 'display_id': '7-ways-to-get-rid-of-chest-congestion',
  18. 'ext': 'mp4',
  19. 'title': 'Seven ways to get rid of chest congestion',
  20. 'description': '7 Ways to Get Rid of Chest Congestion',
  21. 'duration': 88,
  22. 'uploader': 'Health',
  23. 'uploader_id': 'BBPrMqa',
  24. },
  25. }, {
  26. # Article, multiple Dailymotion Embeds
  27. 'url': 'https://www.msn.com/en-in/money/sports/hottest-football-wags-greatest-footballers-turned-managers-and-more/ar-BBpc7Nl',
  28. 'info_dict': {
  29. 'id': 'BBpc7Nl',
  30. },
  31. 'playlist_mincount': 4,
  32. }, {
  33. 'url': 'http://www.msn.com/en-ae/news/offbeat/meet-the-nine-year-old-self-made-millionaire/ar-BBt6ZKf',
  34. 'only_matching': True,
  35. }, {
  36. 'url': 'http://www.msn.com/en-ae/video/watch/obama-a-lot-of-people-will-be-disappointed/vi-AAhxUMH',
  37. 'only_matching': True,
  38. }, {
  39. # geo restricted
  40. 'url': 'http://www.msn.com/en-ae/foodanddrink/joinourtable/the-first-fart-makes-you-laugh-the-last-fart-makes-you-cry/vp-AAhzIBU',
  41. 'only_matching': True,
  42. }, {
  43. 'url': 'http://www.msn.com/en-ae/entertainment/bollywood/watch-how-salman-khan-reacted-when-asked-if-he-would-apologize-for-his-‘raped-woman’-comment/vi-AAhvzW6',
  44. 'only_matching': True,
  45. }, {
  46. # Vidible(AOL) Embed
  47. 'url': 'https://www.msn.com/en-us/money/other/jupiter-is-about-to-come-so-close-you-can-see-its-moons-with-binoculars/vi-AACqsHR',
  48. 'only_matching': True,
  49. }, {
  50. # Dailymotion Embed
  51. 'url': 'https://www.msn.com/es-ve/entretenimiento/watch/winston-salem-paire-refait-des-siennes-en-perdant-sa-raquette-au-service/vp-AAG704L',
  52. 'only_matching': True,
  53. }, {
  54. # YouTube Embed
  55. 'url': 'https://www.msn.com/en-in/money/news/meet-vikram-%E2%80%94-chandrayaan-2s-lander/vi-AAGUr0v',
  56. 'only_matching': True,
  57. }, {
  58. # NBCSports Embed
  59. 'url': 'https://www.msn.com/en-us/money/football_nfl/week-13-preview-redskins-vs-panthers/vi-BBXsCDb',
  60. 'only_matching': True,
  61. }]
  62. def _real_extract(self, url):
  63. display_id, page_id = self._match_valid_url(url).groups()
  64. webpage = self._download_webpage(url, display_id)
  65. entries = []
  66. for _, metadata in re.findall(r'data-metadata\s*=\s*(["\'])(?P<data>.+?)\1', webpage):
  67. video = self._parse_json(unescapeHTML(metadata), display_id)
  68. provider_id = video.get('providerId')
  69. player_name = video.get('playerName')
  70. if player_name and provider_id:
  71. entry = None
  72. if player_name == 'AOL':
  73. if provider_id.startswith('http'):
  74. provider_id = self._search_regex(
  75. r'https?://delivery\.vidible\.tv/video/redirect/([0-9a-f]{24})',
  76. provider_id, 'vidible id')
  77. entry = self.url_result(
  78. 'aol-video:' + provider_id, 'Aol', provider_id)
  79. elif player_name == 'Dailymotion':
  80. entry = self.url_result(
  81. 'https://www.dailymotion.com/video/' + provider_id,
  82. 'Dailymotion', provider_id)
  83. elif player_name == 'YouTube':
  84. entry = self.url_result(
  85. provider_id, 'Youtube', provider_id)
  86. elif player_name == 'NBCSports':
  87. entry = self.url_result(
  88. 'http://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/media/' + provider_id,
  89. 'NBCSportsVPlayer', provider_id)
  90. if entry:
  91. entries.append(entry)
  92. continue
  93. video_id = video['uuid']
  94. title = video['title']
  95. formats = []
  96. for file_ in video.get('videoFiles', []):
  97. format_url = file_.get('url')
  98. if not format_url:
  99. continue
  100. if 'format=m3u8-aapl' in format_url:
  101. # m3u8_native should not be used here until
  102. # https://github.com/ytdl-org/youtube-dl/issues/9913 is fixed
  103. formats.extend(self._extract_m3u8_formats(
  104. format_url, display_id, 'mp4',
  105. m3u8_id='hls', fatal=False))
  106. elif 'format=mpd-time-csf' in format_url:
  107. formats.extend(self._extract_mpd_formats(
  108. format_url, display_id, 'dash', fatal=False))
  109. elif '.ism' in format_url:
  110. if format_url.endswith('.ism'):
  111. format_url += '/manifest'
  112. formats.extend(self._extract_ism_formats(
  113. format_url, display_id, 'mss', fatal=False))
  114. else:
  115. format_id = file_.get('formatCode')
  116. formats.append({
  117. 'url': format_url,
  118. 'ext': 'mp4',
  119. 'format_id': format_id,
  120. 'width': int_or_none(file_.get('width')),
  121. 'height': int_or_none(file_.get('height')),
  122. 'vbr': int_or_none(self._search_regex(r'_(\d+)\.mp4', format_url, 'vbr', default=None)),
  123. 'quality': 1 if format_id == '1001' else None,
  124. })
  125. subtitles = {}
  126. for file_ in video.get('files', []):
  127. format_url = file_.get('url')
  128. format_code = file_.get('formatCode')
  129. if not format_url or not format_code:
  130. continue
  131. if str(format_code) == '3100':
  132. subtitles.setdefault(file_.get('culture', 'en'), []).append({
  133. 'ext': determine_ext(format_url, 'ttml'),
  134. 'url': format_url,
  135. })
  136. entries.append({
  137. 'id': video_id,
  138. 'display_id': display_id,
  139. 'title': title,
  140. 'description': video.get('description'),
  141. 'thumbnail': video.get('headlineImage', {}).get('url'),
  142. 'duration': int_or_none(video.get('durationSecs')),
  143. 'uploader': video.get('sourceFriendly'),
  144. 'uploader_id': video.get('providerId'),
  145. 'creator': video.get('creator'),
  146. 'subtitles': subtitles,
  147. 'formats': formats,
  148. })
  149. if not entries:
  150. error = unescapeHTML(self._search_regex(
  151. r'data-error=(["\'])(?P<error>.+?)\1',
  152. webpage, 'error', group='error'))
  153. raise ExtractorError(f'{self.IE_NAME} said: {error}', expected=True)
  154. return self.playlist_result(entries, page_id)