+ }
+ else:
+ # "feature" and "nightly-news" pages use theplatform.com
+ display_id = mobj.group('display_id')
+ webpage = self._download_webpage(url, display_id)
+ info = None
+ bootstrap_json = self._search_regex(
+ r'(?m)var\s+(?:bootstrapJson|playlistData)\s*=\s*({.+});?\s*$',
+ webpage, 'bootstrap json', default=None)
+ if bootstrap_json:
+ bootstrap = self._parse_json(bootstrap_json, display_id)
+ info = bootstrap['results'][0]['video']
+ else:
+ player_instance_json = self._search_regex(
+ r'videoObj\s*:\s*({.+})', webpage, 'player instance')
+ info = self._parse_json(player_instance_json, display_id)
+ video_id = info['mpxId']
+ title = info['title']
+
+ subtitles = {}
+ caption_links = info.get('captionLinks')
+ if caption_links:
+ for (sub_key, sub_ext) in (('smpte-tt', 'ttml'), ('web-vtt', 'vtt'), ('srt', 'srt')):
+ sub_url = caption_links.get(sub_key)
+ if sub_url:
+ subtitles.setdefault('en', []).append({
+ 'url': sub_url,
+ 'ext': sub_ext,
+ })
+
+ formats = []
+ for video_asset in info['videoAssets']:
+ video_url = video_asset.get('publicUrl')
+ if not video_url:
+ continue
+ container = video_asset.get('format')
+ asset_type = video_asset.get('assetType') or ''
+ if container == 'ISM' or asset_type == 'FireTV-Once':
+ continue
+ elif asset_type == 'OnceURL':
+ tp_formats, tp_subtitles = self._extract_theplatform_smil(
+ video_url, video_id)
+ formats.extend(tp_formats)
+ subtitles = self._merge_subtitles(subtitles, tp_subtitles)
+ else:
+ tbr = int_or_none(video_asset.get('bitRate'), 1000)
+ format_id = 'http%s' % ('-%d' % tbr if tbr else '')
+ video_url = update_url_query(
+ video_url, {'format': 'redirect'})
+ # resolve the url so that we can check availability and detect the correct extension
+ head = self._request_webpage(
+ HEADRequest(video_url), video_id,
+ 'Checking %s url' % format_id,
+ '%s is not available' % format_id,
+ fatal=False)
+ if head:
+ video_url = head.geturl()
+ formats.append({
+ 'format_id': format_id,
+ 'url': video_url,
+ 'width': int_or_none(video_asset.get('width')),
+ 'height': int_or_none(video_asset.get('height')),
+ 'tbr': tbr,
+ 'container': video_asset.get('format'),
+ })
+ self._sort_formats(formats)
+
+ return {
+ 'id': video_id,
+ 'title': title,
+ 'description': info.get('description'),
+ 'thumbnail': info.get('description'),
+ 'thumbnail': info.get('thumbnail'),
+ 'duration': int_or_none(info.get('duration')),
+ 'timestamp': parse_iso8601(info.get('pubDate')),
+ 'formats': formats,
+ 'subtitles': subtitles,
+ }
+
+
+class MSNBCIE(InfoExtractor):
+ # https URLs redirect to corresponding http ones
+ _VALID_URL = r'http://www\.msnbc\.com/[^/]+/watch/(?P<id>[^/]+)'
+ _TEST = {
+ 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
+ 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
+ 'info_dict': {
+ 'id': 'n_hayes_Aimm_140801_272214',
+ 'ext': 'mp4',
+ 'title': 'The chaotic GOP immigration vote',
+ '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.',
+ 'thumbnail': 're:^https?://.*\.jpg$',
+ 'timestamp': 1406937606,
+ 'upload_date': '20140802',
+ 'categories': ['MSNBC/Topics/Franchise/Best of last night', 'MSNBC/Topics/General/Congress'],
+ },
+ }
+
+ def _real_extract(self, url):
+ video_id = self._match_id(url)
+ webpage = self._download_webpage(url, video_id)
+ embed_url = self._html_search_meta('embedURL', webpage)
+ return self.url_result(embed_url)