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.

116 lines
4.5 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\.)?msn\.com/(?:[^/]+/)+(?P<display_id>[^/]+)/[a-z]{2}-(?P<id>[\da-zA-Z]+)'
  14. _TESTS = [{
  15. 'url': 'http://www.msn.com/en-ae/foodanddrink/joinourtable/criminal-minds-shemar-moore-shares-a-touching-goodbye-message/vp-BBqQYNE',
  16. 'md5': '8442f66c116cbab1ff7098f986983458',
  17. 'info_dict': {
  18. 'id': 'BBqQYNE',
  19. 'display_id': 'criminal-minds-shemar-moore-shares-a-touching-goodbye-message',
  20. 'ext': 'mp4',
  21. 'title': 'Criminal Minds - Shemar Moore Shares A Touching Goodbye Message',
  22. 'description': 'md5:e8e89b897b222eb33a6b5067a8f1bc25',
  23. 'duration': 104,
  24. 'uploader': 'CBS Entertainment',
  25. 'uploader_id': 'IT0X5aoJ6bJgYerJXSDCgFmYPB1__54v',
  26. },
  27. }, {
  28. 'url': 'http://www.msn.com/en-ae/news/offbeat/meet-the-nine-year-old-self-made-millionaire/ar-BBt6ZKf',
  29. 'only_matching': True,
  30. }, {
  31. 'url': 'http://www.msn.com/en-ae/video/watch/obama-a-lot-of-people-will-be-disappointed/vi-AAhxUMH',
  32. 'only_matching': True,
  33. }, {
  34. # geo restricted
  35. 'url': 'http://www.msn.com/en-ae/foodanddrink/joinourtable/the-first-fart-makes-you-laugh-the-last-fart-makes-you-cry/vp-AAhzIBU',
  36. 'only_matching': True,
  37. }, {
  38. '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',
  39. 'only_matching': True,
  40. }]
  41. def _real_extract(self, url):
  42. mobj = re.match(self._VALID_URL, url)
  43. video_id, display_id = mobj.group('id', 'display_id')
  44. webpage = self._download_webpage(url, display_id)
  45. video = self._parse_json(
  46. self._search_regex(
  47. r'data-metadata\s*=\s*(["\'])(?P<data>.+?)\1',
  48. webpage, 'video data', default='{}', group='data'),
  49. display_id, transform_source=unescapeHTML)
  50. if not video:
  51. error = unescapeHTML(self._search_regex(
  52. r'data-error=(["\'])(?P<error>.+?)\1',
  53. webpage, 'error', group='error'))
  54. raise ExtractorError('%s said: %s' % (self.IE_NAME, error), expected=True)
  55. title = video['title']
  56. formats = []
  57. for file_ in video.get('videoFiles', []):
  58. format_url = file_.get('url')
  59. if not format_url:
  60. continue
  61. ext = determine_ext(format_url)
  62. if ext == 'ism':
  63. formats.extend(self._extract_ism_formats(
  64. format_url + '/Manifest', display_id, 'mss', fatal=False))
  65. if 'm3u8' in format_url:
  66. # m3u8_native should not be used here until
  67. # https://github.com/rg3/youtube-dl/issues/9913 is fixed
  68. m3u8_formats = self._extract_m3u8_formats(
  69. format_url, display_id, 'mp4',
  70. m3u8_id='hls', fatal=False)
  71. formats.extend(m3u8_formats)
  72. else:
  73. formats.append({
  74. 'url': format_url,
  75. 'ext': 'mp4',
  76. 'format_id': 'http',
  77. 'width': int_or_none(file_.get('width')),
  78. 'height': int_or_none(file_.get('height')),
  79. })
  80. self._sort_formats(formats)
  81. subtitles = {}
  82. for file_ in video.get('files', []):
  83. format_url = file_.get('url')
  84. format_code = file_.get('formatCode')
  85. if not format_url or not format_code:
  86. continue
  87. if compat_str(format_code) == '3100':
  88. subtitles.setdefault(file_.get('culture', 'en'), []).append({
  89. 'ext': determine_ext(format_url, 'ttml'),
  90. 'url': format_url,
  91. })
  92. return {
  93. 'id': video_id,
  94. 'display_id': display_id,
  95. 'title': title,
  96. 'description': video.get('description'),
  97. 'thumbnail': video.get('headlineImage', {}).get('url'),
  98. 'duration': int_or_none(video.get('durationSecs')),
  99. 'uploader': video.get('sourceFriendly'),
  100. 'uploader_id': video.get('providerId'),
  101. 'creator': video.get('creator'),
  102. 'subtitles': subtitles,
  103. 'formats': formats,
  104. }