- if publisher_id:
- return self._brightcove_new_url_result(publisher_id, video_id)
- raise ExtractorError(
- 'brightcove said: %s' % error_msg, expected=True)
-
- self.report_extraction(video_id)
- info = self._search_regex(r'var experienceJSON = ({.*});', webpage, 'json')
- info = json.loads(info)['data']
- video_info = info['programmedContent']['videoPlayer']['mediaDTO']
- video_info['_youtubedl_adServerURL'] = info.get('adServerURL')
-
- return self._extract_video_info(video_info)
-
- def _get_playlist_info(self, player_key):
- info_url = 'http://c.brightcove.com/services/json/experience/runtime/?command=get_programming_for_experience&playerKey=%s' % player_key
- playlist_info = self._download_webpage(
- info_url, player_key, 'Downloading playlist information')
-
- json_data = json.loads(playlist_info)
- if 'videoList' in json_data:
- playlist_info = json_data['videoList']
- playlist_dto = playlist_info['mediaCollectionDTO']
- elif 'playlistTabs' in json_data:
- playlist_info = json_data['playlistTabs']
- playlist_dto = playlist_info['lineupListDTO']['playlistDTOs'][0]
- else:
- raise ExtractorError('Empty playlist')
-
- videos = [self._extract_video_info(video_info) for video_info in playlist_dto['videoDTOs']]
-
- return self.playlist_result(videos, playlist_id='%s' % playlist_info['id'],
- playlist_title=playlist_dto['displayName'])
-
- def _extract_video_info(self, video_info):
- video_id = compat_str(video_info['id'])
- publisher_id = video_info.get('publisherId')
- info = {
- 'id': video_id,
- 'title': video_info['displayName'].strip(),
- 'description': video_info.get('shortDescription'),
- 'thumbnail': video_info.get('videoStillURL') or video_info.get('thumbnailURL'),
- 'uploader': video_info.get('publisherName'),
- 'uploader_id': compat_str(publisher_id) if publisher_id else None,
- 'duration': float_or_none(video_info.get('length'), 1000),
- 'timestamp': int_or_none(video_info.get('creationDate'), 1000),
- }
-
- renditions = video_info.get('renditions', []) + video_info.get('IOSRenditions', [])
- if renditions:
- formats = []
- for rend in renditions:
- url = rend['defaultURL']
- if not url:
- continue
- ext = None
- if rend['remote']:
- url_comp = compat_urllib_parse_urlparse(url)
- if url_comp.path.endswith('.m3u8'):
- formats.extend(
- self._extract_m3u8_formats(
- url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
- continue
- elif 'akamaihd.net' in url_comp.netloc:
- # This type of renditions are served through
- # akamaihd.net, but they don't use f4m manifests
- url = url.replace('control/', '') + '?&v=3.3.0&fp=13&r=FEEFJ&g=RTSJIMBMPFPB'
- ext = 'flv'
- if ext is None:
- ext = determine_ext(url)
- tbr = int_or_none(rend.get('encodingRate'), 1000)
- a_format = {
- 'format_id': 'http%s' % ('-%s' % tbr if tbr else ''),
- 'url': url,
- 'ext': ext,
- 'filesize': int_or_none(rend.get('size')) or None,
- 'tbr': tbr,
- }
- if rend.get('audioOnly'):
- a_format.update({
- 'vcodec': 'none',
- })
- else:
- a_format.update({
- 'height': int_or_none(rend.get('frameHeight')),
- 'width': int_or_none(rend.get('frameWidth')),
- 'vcodec': rend.get('videoCodec'),
- })
-
- # m3u8 manifests with remote == false are media playlists
- # Not calling _extract_m3u8_formats here to save network traffic
- if ext == 'm3u8':
- a_format.update({
- 'format_id': 'hls%s' % ('-%s' % tbr if tbr else ''),
- 'ext': 'mp4',
- 'protocol': 'm3u8_native',
- })
-
- formats.append(a_format)
- self._sort_formats(formats)
- info['formats'] = formats
- elif video_info.get('FLVFullLengthURL') is not None:
- info.update({
- 'url': video_info['FLVFullLengthURL'],
- 'vcodec': self.FLV_VCODECS.get(video_info.get('FLVFullCodec')),
- 'filesize': int_or_none(video_info.get('FLVFullSize')),
- })
-
- if self._downloader.params.get('include_ads', False):
- adServerURL = video_info.get('_youtubedl_adServerURL')
- if adServerURL:
- ad_info = {
- '_type': 'url',
- 'url': adServerURL,
- }
- if 'url' in info:
- return {
- '_type': 'playlist',
- 'title': info['title'],
- 'entries': [ad_info, info],
- }
- else:
- return ad_info
-
- if not info.get('url') and not info.get('formats'):
- uploader_id = info.get('uploader_id')
- if uploader_id:
- info.update(self._brightcove_new_url_result(uploader_id, video_id))
- else:
- raise ExtractorError('Unable to extract video url for %s' % video_id)
- return info