]>
Commit | Line | Data |
---|---|---|
cd7ee7aa JMF |
1 | from __future__ import unicode_literals |
2 | ||
0bc56fa6 | 3 | import re |
0bc56fa6 JMF |
4 | |
5 | from .common import InfoExtractor | |
d890b4cc | 6 | from ..compat import compat_HTTPError |
1cc79574 | 7 | from ..utils import ( |
37e64add PH |
8 | ExtractorError, |
9 | find_xpath_attr, | |
0fe2ff78 | 10 | lowercase_escape, |
b46b65ed | 11 | smuggle_url, |
0fe2ff78 | 12 | unescapeHTML, |
37e64add | 13 | ) |
0bc56fa6 JMF |
14 | |
15 | ||
020cf5eb | 16 | class NBCIE(InfoExtractor): |
cb88671e | 17 | _VALID_URL = r'https?://www\.nbc\.com/(?:[^/]+/)+(?P<id>n?\d+)' |
58c1f6f0 S |
18 | |
19 | _TESTS = [ | |
20 | { | |
5c8a3f86 | 21 | 'url': 'http://www.nbc.com/the-tonight-show/segments/112966', |
58c1f6f0 | 22 | 'info_dict': { |
e881c4bc YCH |
23 | 'id': '112966', |
24 | 'ext': 'mp4', | |
5c8a3f86 JMF |
25 | 'title': 'Jimmy Fallon Surprises Fans at Ben & Jerry\'s', |
26 | 'description': 'Jimmy gives out free scoops of his new "Tonight Dough" ice cream flavor by surprising customers at the Ben & Jerry\'s scoop shop.', | |
58c1f6f0 | 27 | }, |
e881c4bc YCH |
28 | 'params': { |
29 | # m3u8 download | |
30 | 'skip_download': True, | |
31 | }, | |
020cf5eb | 32 | }, |
58c1f6f0 S |
33 | { |
34 | 'url': 'http://www.nbc.com/the-tonight-show/episodes/176', | |
35 | 'info_dict': { | |
e881c4bc | 36 | 'id': '176', |
58c1f6f0 S |
37 | 'ext': 'flv', |
38 | 'title': 'Ricky Gervais, Steven Van Zandt, ILoveMakonnen', | |
39 | 'description': 'A brand new episode of The Tonight Show welcomes Ricky Gervais, Steven Van Zandt and ILoveMakonnen.', | |
40 | }, | |
e881c4bc | 41 | 'skip': '404 Not Found', |
58c1f6f0 | 42 | }, |
b9b3ab45 YCH |
43 | { |
44 | 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821', | |
45 | 'info_dict': { | |
e881c4bc YCH |
46 | 'id': '2832821', |
47 | 'ext': 'mp4', | |
b9b3ab45 YCH |
48 | 'title': 'Star Wars Teaser', |
49 | 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442', | |
50 | }, | |
e881c4bc YCH |
51 | 'params': { |
52 | # m3u8 download | |
53 | 'skip_download': True, | |
54 | }, | |
b9b3ab45 | 55 | 'skip': 'Only works from US', |
0fe2ff78 YCH |
56 | }, |
57 | { | |
58 | # This video has expired but with an escaped embedURL | |
59 | 'url': 'http://www.nbc.com/parenthood/episode-guide/season-5/just-like-at-home/515', | |
3e18700d | 60 | 'only_matching': True, |
b9b3ab45 | 61 | } |
58c1f6f0 | 62 | ] |
020cf5eb JMF |
63 | |
64 | def _real_extract(self, url): | |
10e3d734 | 65 | video_id = self._match_id(url) |
020cf5eb | 66 | webpage = self._download_webpage(url, video_id) |
0fe2ff78 | 67 | theplatform_url = unescapeHTML(lowercase_escape(self._html_search_regex( |
b9b3ab45 YCH |
68 | [ |
69 | r'(?:class="video-player video-player-full" data-mpx-url|class="player" src)="(.*?)"', | |
b09c1223 | 70 | r'<iframe[^>]+src="((?:https?:)?//player\.theplatform\.com/[^"]+)"', |
b9b3ab45 YCH |
71 | r'"embedURL"\s*:\s*"([^"]+)"' |
72 | ], | |
0fe2ff78 | 73 | webpage, 'theplatform url').replace('_no_endcard', '').replace('\\/', '/'))) |
020cf5eb JMF |
74 | if theplatform_url.startswith('//'): |
75 | theplatform_url = 'http:' + theplatform_url | |
e881c4bc YCH |
76 | return { |
77 | '_type': 'url_transparent', | |
78 | 'url': smuggle_url(theplatform_url, {'source_url': url}), | |
79 | 'id': video_id, | |
80 | } | |
020cf5eb JMF |
81 | |
82 | ||
a2a4d5fa | 83 | class NBCSportsVPlayerIE(InfoExtractor): |
a2edf2e7 | 84 | _VALID_URL = r'https?://vplayer\.nbcsports\.com/(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)' |
a28ccbab | 85 | |
5cbb2699 | 86 | _TESTS = [{ |
a28ccbab | 87 | 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_share/select/9CsDKds0kvHI', |
a28ccbab YCH |
88 | 'info_dict': { |
89 | 'id': '9CsDKds0kvHI', | |
90 | 'ext': 'flv', | |
91 | 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d', | |
92 | 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson', | |
93 | } | |
5cbb2699 | 94 | }, { |
5cbb2699 YCH |
95 | 'url': 'http://vplayer.nbcsports.com/p/BxmELC/nbc_embedshare/select/_hqLjQ95yx8Z', |
96 | 'only_matching': True, | |
97 | }] | |
a28ccbab | 98 | |
a2a4d5fa YCH |
99 | @staticmethod |
100 | def _extract_url(webpage): | |
101 | iframe_m = re.search( | |
102 | r'<iframe[^>]+src="(?P<url>https?://vplayer\.nbcsports\.com/[^"]+)"', webpage) | |
103 | if iframe_m: | |
104 | return iframe_m.group('url') | |
105 | ||
a28ccbab YCH |
106 | def _real_extract(self, url): |
107 | video_id = self._match_id(url) | |
108 | webpage = self._download_webpage(url, video_id) | |
109 | theplatform_url = self._og_search_video_url(webpage) | |
110 | return self.url_result(theplatform_url, 'ThePlatform') | |
111 | ||
112 | ||
a2a4d5fa | 113 | class NBCSportsIE(InfoExtractor): |
dfb1b146 | 114 | # Does not include https because its certificate is invalid |
a2a4d5fa YCH |
115 | _VALID_URL = r'http://www\.nbcsports\.com//?(?:[^/]+/)+(?P<id>[0-9a-z-]+)' |
116 | ||
117 | _TEST = { | |
118 | 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke', | |
a2a4d5fa YCH |
119 | 'info_dict': { |
120 | 'id': 'PHJSaFWbrTY9', | |
121 | 'ext': 'flv', | |
122 | 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke', | |
123 | 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113', | |
124 | } | |
125 | } | |
126 | ||
127 | def _real_extract(self, url): | |
128 | video_id = self._match_id(url) | |
129 | webpage = self._download_webpage(url, video_id) | |
130 | return self.url_result( | |
131 | NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer') | |
132 | ||
133 | ||
0bc56fa6 | 134 | class NBCNewsIE(InfoExtractor): |
a4f3d779 S |
135 | _VALID_URL = r'''(?x)https?://(?:www\.)?nbcnews\.com/ |
136 | (?:video/.+?/(?P<id>\d+)| | |
3f125c8c | 137 | (?:watch|feature|nightly-news)/[^/]+/(?P<title>.+)) |
87fe568c | 138 | ''' |
0bc56fa6 | 139 | |
87fe568c JMF |
140 | _TESTS = [ |
141 | { | |
142 | 'url': 'http://www.nbcnews.com/video/nbc-news/52753292', | |
143 | 'md5': '47abaac93c6eaf9ad37ee6c4463a5179', | |
144 | 'info_dict': { | |
145 | 'id': '52753292', | |
146 | 'ext': 'flv', | |
147 | 'title': 'Crew emerges after four-month Mars food study', | |
148 | 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1', | |
149 | }, | |
0bc56fa6 | 150 | }, |
87fe568c JMF |
151 | { |
152 | 'url': 'http://www.nbcnews.com/feature/edward-snowden-interview/how-twitter-reacted-snowden-interview-n117236', | |
153 | 'md5': 'b2421750c9f260783721d898f4c42063', | |
154 | 'info_dict': { | |
155 | 'id': 'I1wpAI_zmhsQ', | |
10e3d734 | 156 | 'ext': 'mp4', |
87fe568c JMF |
157 | 'title': 'How Twitter Reacted To The Snowden Interview', |
158 | 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64', | |
159 | }, | |
160 | 'add_ie': ['ThePlatform'], | |
161 | }, | |
2df54b4b S |
162 | { |
163 | 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156', | |
164 | 'md5': 'fdbf39ab73a72df5896b6234ff98518a', | |
165 | 'info_dict': { | |
166 | 'id': 'Wjf9EDR3A_60', | |
167 | 'ext': 'mp4', | |
168 | 'title': 'FULL EPISODE: Family Business', | |
169 | 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04', | |
170 | }, | |
171 | }, | |
d9aa2b78 RS |
172 | { |
173 | 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844', | |
174 | 'md5': 'b5dda8cddd8650baa0dcb616dd2cf60d', | |
175 | 'info_dict': { | |
176 | 'id': 'sekXqyTVnmN3', | |
177 | 'ext': 'mp4', | |
178 | 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)', | |
179 | 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5', | |
180 | }, | |
181 | }, | |
3f125c8c S |
182 | { |
183 | 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952', | |
184 | 'only_matching': True, | |
185 | }, | |
87fe568c | 186 | ] |
0bc56fa6 JMF |
187 | |
188 | def _real_extract(self, url): | |
189 | mobj = re.match(self._VALID_URL, url) | |
190 | video_id = mobj.group('id') | |
87fe568c JMF |
191 | if video_id is not None: |
192 | all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id) | |
193 | info = all_info.find('video') | |
0bc56fa6 | 194 | |
87fe568c JMF |
195 | return { |
196 | 'id': video_id, | |
197 | 'title': info.find('headline').text, | |
198 | 'ext': 'flv', | |
199 | 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text, | |
d890b4cc | 200 | 'description': info.find('caption').text, |
87fe568c JMF |
201 | 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text, |
202 | } | |
203 | else: | |
d9aa2b78 | 204 | # "feature" and "nightly-news" pages use theplatform.com |
87fe568c JMF |
205 | title = mobj.group('title') |
206 | webpage = self._download_webpage(url, title) | |
a4f3d779 S |
207 | bootstrap_json = self._search_regex( |
208 | r'var\s+(?:bootstrapJson|playlistData)\s*=\s*({.+});?\s*$', | |
209 | webpage, 'bootstrap json', flags=re.MULTILINE) | |
210 | bootstrap = self._parse_json(bootstrap_json, video_id) | |
87fe568c | 211 | info = bootstrap['results'][0]['video'] |
87fe568c | 212 | mpxid = info['mpxId'] |
754d8a03 PH |
213 | |
214 | base_urls = [ | |
215 | info['fallbackPlaylistUrl'], | |
216 | info['associatedPlaylistUrl'], | |
217 | ] | |
218 | ||
219 | for base_url in base_urls: | |
10e3d734 PH |
220 | if not base_url: |
221 | continue | |
754d8a03 | 222 | playlist_url = base_url + '?form=MPXNBCNewsAPI' |
754d8a03 PH |
223 | |
224 | try: | |
2df54b4b S |
225 | all_videos = self._download_json(playlist_url, title) |
226 | except ExtractorError as ee: | |
227 | if isinstance(ee.cause, compat_HTTPError): | |
228 | continue | |
229 | raise | |
230 | ||
47e0e1e0 | 231 | if not all_videos or 'videos' not in all_videos: |
2df54b4b S |
232 | continue |
233 | ||
234 | try: | |
235 | info = next(v for v in all_videos['videos'] if v['mpxId'] == mpxid) | |
754d8a03 PH |
236 | break |
237 | except StopIteration: | |
238 | continue | |
239 | ||
240 | if info is None: | |
241 | raise ExtractorError('Could not find video in playlists') | |
87fe568c JMF |
242 | |
243 | return { | |
244 | '_type': 'url', | |
245 | # We get the best quality video | |
246 | 'url': info['videoAssets'][-1]['publicUrl'], | |
247 | 'ie_key': 'ThePlatform', | |
248 | } | |
dac14bf3 YCH |
249 | |
250 | ||
251 | class MSNBCIE(InfoExtractor): | |
252 | # https URLs redirect to corresponding http ones | |
253 | _VALID_URL = r'http://www\.msnbc\.com/[^/]+/watch/(?P<id>[^/]+)' | |
254 | _TEST = { | |
255 | 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924', | |
256 | 'md5': '6d236bf4f3dddc226633ce6e2c3f814d', | |
257 | 'info_dict': { | |
258 | 'id': 'n_hayes_Aimm_140801_272214', | |
259 | 'ext': 'mp4', | |
260 | 'title': 'The chaotic GOP immigration vote', | |
261 | 'description': 'The Republican House votes on a border bill that has no chance of getting through the Senate or signed by the President and is drawing criticism from all sides.', | |
262 | 'thumbnail': 're:^https?://.*\.jpg$', | |
263 | 'timestamp': 1406937606, | |
264 | 'upload_date': '20140802', | |
265 | 'categories': ['MSNBC/Topics/Franchise/Best of last night', 'MSNBC/Topics/General/Congress'], | |
266 | }, | |
267 | } | |
268 | ||
269 | def _real_extract(self, url): | |
270 | video_id = self._match_id(url) | |
271 | webpage = self._download_webpage(url, video_id) | |
272 | embed_url = self._html_search_meta('embedURL', webpage) | |
273 | return self.url_result(embed_url) |