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