Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

116 строки
4.5KB

  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. if 'm3u8' in format_url:
  62. # m3u8_native should not be used here until
  63. # https://github.com/ytdl-org/youtube-dl/issues/9913 is fixed
  64. m3u8_formats = self._extract_m3u8_formats(
  65. format_url, display_id, 'mp4',
  66. m3u8_id='hls', fatal=False)
  67. formats.extend(m3u8_formats)
  68. elif determine_ext(format_url) == 'ism':
  69. formats.extend(self._extract_ism_formats(
  70. format_url + '/Manifest', display_id, 'mss', fatal=False))
  71. else:
  72. formats.append({
  73. 'url': format_url,
  74. 'ext': 'mp4',
  75. 'format_id': 'http',
  76. 'width': int_or_none(file_.get('width')),
  77. 'height': int_or_none(file_.get('height')),
  78. })
  79. self._sort_formats(formats)
  80. subtitles = {}
  81. for file_ in video.get('files', []):
  82. format_url = file_.get('url')
  83. format_code = file_.get('formatCode')
  84. if not format_url or not format_code:
  85. continue
  86. if compat_str(format_code) == '3100':
  87. subtitles.setdefault(file_.get('culture', 'en'), []).append({
  88. 'ext': determine_ext(format_url, 'ttml'),
  89. 'url': format_url,
  90. })
  91. return {
  92. 'id': video_id,
  93. 'display_id': display_id,
  94. 'title': title,
  95. 'description': video.get('description'),
  96. 'thumbnail': video.get('headlineImage', {}).get('url'),
  97. 'duration': int_or_none(video.get('durationSecs')),
  98. 'uploader': video.get('sourceFriendly'),
  99. 'uploader_id': video.get('providerId'),
  100. 'creator': video.get('creator'),
  101. 'subtitles': subtitles,
  102. 'formats': formats,
  103. }