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