1 from __future__ import unicode_literals
6 from .common import InfoExtractor
14 class NBCIE(InfoExtractor):
15 _VALID_URL = r'http://www\.nbc\.com/(?:[^/]+/)+(?P<id>n?\d+)'
19 'url': 'http://www.nbc.com/chicago-fire/video/i-am-a-firefighter/2734188',
20 # md5 checksum is not stable
24 'title': 'I Am a Firefighter',
25 'description': 'An emergency puts Dawson\'sf irefighter skills to the ultimate test in this four-part digital series.',
29 'url': 'http://www.nbc.com/the-tonight-show/episodes/176',
33 'title': 'Ricky Gervais, Steven Van Zandt, ILoveMakonnen',
34 'description': 'A brand new episode of The Tonight Show welcomes Ricky Gervais, Steven Van Zandt and ILoveMakonnen.',
36 'skip': 'Only works from US',
40 def _real_extract(self, url):
41 video_id = self._match_id(url)
42 webpage = self._download_webpage(url, video_id)
43 theplatform_url = self._search_regex(
44 '(?:class="video-player video-player-full" data-mpx-url|class="player" src)="(.*?)"',
45 webpage, 'theplatform url').replace('_no_endcard', '')
46 if theplatform_url.startswith('//'):
47 theplatform_url = 'http:' + theplatform_url
48 return self.url_result(theplatform_url)
51 class NBCNewsIE(InfoExtractor):
52 _VALID_URL = r'''(?x)https?://www\.nbcnews\.com/
53 ((video/.+?/(?P<id>\d+))|
54 (feature/[^/]+/(?P<title>.+)))
59 'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
60 'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
64 'title': 'Crew emerges after four-month Mars food study',
65 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
69 'url': 'http://www.nbcnews.com/feature/edward-snowden-interview/how-twitter-reacted-snowden-interview-n117236',
70 'md5': 'b2421750c9f260783721d898f4c42063',
74 'title': 'How Twitter Reacted To The Snowden Interview',
75 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
77 'add_ie': ['ThePlatform'],
81 def _real_extract(self, url):
82 mobj = re.match(self._VALID_URL, url)
83 video_id = mobj.group('id')
84 if video_id is not None:
85 all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
86 info = all_info.find('video')
90 'title': info.find('headline').text,
92 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
93 'description': compat_str(info.find('caption').text),
94 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
97 # "feature" pages use theplatform.com
98 title = mobj.group('title')
99 webpage = self._download_webpage(url, title)
100 bootstrap_json = self._search_regex(
101 r'var bootstrapJson = ({.+})\s*$', webpage, 'bootstrap json',
103 bootstrap = json.loads(bootstrap_json)
104 info = bootstrap['results'][0]['video']
105 mpxid = info['mpxId']
108 info['fallbackPlaylistUrl'],
109 info['associatedPlaylistUrl'],
112 for base_url in base_urls:
115 playlist_url = base_url + '?form=MPXNBCNewsAPI'
116 all_videos = self._download_json(playlist_url, title)['videos']
119 info = next(v for v in all_videos if v['mpxId'] == mpxid)
121 except StopIteration:
125 raise ExtractorError('Could not find video in playlists')
129 # We get the best quality video
130 'url': info['videoAssets'][-1]['publicUrl'],
131 'ie_key': 'ThePlatform',