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