You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
7.4 KiB

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