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