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