- # If the url includes the language we get the title translated
- title = self._html_search_regex(r'<span id="altHeadline" >(?P<title>.*)</span>',
- webpage, 'title')
- json_data = self._search_regex(r'<script.*?>var talkDetails = ({.*?})</script>',
- webpage, 'json data')
- info = json.loads(json_data)
- desc = self._html_search_regex(r'<div class="talk-intro">.*?<p.*?>(.*?)</p>',
- webpage, 'description', flags = re.DOTALL)
-
- thumbnail = self._search_regex(r'</span>[\s.]*</div>[\s.]*<img src="(.*?)"',
- webpage, 'thumbnail')
- info = {
- 'id': info['id'],
- 'url': info['htmlStreams'][-1]['file'],
- 'ext': 'mp4',
- 'title': title,
- 'thumbnail': thumbnail,
- 'description': desc,
- }
- return info
+
+ talk_info = self._extract_info(webpage)['talks'][0]
+
+ if talk_info.get('external') is not None:
+ self.to_screen('Found video from %s' % talk_info['external']['service'])
+ return {
+ '_type': 'url',
+ 'url': talk_info['external']['uri'],
+ }
+
+ formats = [{
+ 'url': format_url,
+ 'format_id': format_id,
+ 'format': format_id,
+ } for (format_id, format_url) in talk_info['nativeDownloads'].items() if format_url is not None]
+ if formats:
+ for f in formats:
+ finfo = self._NATIVE_FORMATS.get(f['format_id'])
+ if finfo:
+ f.update(finfo)
+ else:
+ # Use rtmp downloads
+ formats = [{
+ 'format_id': f['name'],
+ 'url': talk_info['streamer'],
+ 'play_path': f['file'],
+ 'ext': 'flv',
+ 'width': f['width'],
+ 'height': f['height'],
+ 'tbr': f['bitrate'],
+ } for f in talk_info['resources']['rtmp']]
+ self._sort_formats(formats)
+
+ video_id = compat_str(talk_info['id'])
+ # subtitles
+ video_subtitles = self.extract_subtitles(video_id, talk_info)
+ if self._downloader.params.get('listsubtitles', False):
+ self._list_available_subtitles(video_id, talk_info)
+ return
+
+ thumbnail = talk_info['thumb']
+ if not thumbnail.startswith('http'):
+ thumbnail = 'http://' + thumbnail
+ return {
+ 'id': video_id,
+ 'title': talk_info['title'].strip(),
+ 'uploader': talk_info['speaker'],
+ 'thumbnail': thumbnail,
+ 'description': self._og_search_description(webpage),
+ 'subtitles': video_subtitles,
+ 'formats': formats,
+ 'duration': talk_info.get('duration'),
+ }
+
+ def _get_available_subtitles(self, video_id, talk_info):
+ languages = [lang['languageCode'] for lang in talk_info.get('languages', [])]
+ if languages:
+ sub_lang_list = {}
+ for l in languages:
+ url = 'http://www.ted.com/talks/subtitles/id/%s/lang/%s/format/srt' % (video_id, l)
+ sub_lang_list[l] = url
+ return sub_lang_list
+ else:
+ self._downloader.report_warning('video doesn\'t have subtitles')
+ return {}
+
+ def _watch_info(self, url, name):
+ webpage = self._download_webpage(url, name)
+
+ config_json = self._html_search_regex(
+ r"data-config='([^']+)", webpage, 'config')
+ config = json.loads(config_json)
+ video_url = config['video']['url']
+ thumbnail = config.get('image', {}).get('url')
+
+ title = self._html_search_regex(
+ r"(?s)<h1(?:\s+class='[^']+')?>(.+?)</h1>", webpage, 'title')
+ description = self._html_search_regex(
+ [
+ r'(?s)<h4 class="[^"]+" id="h3--about-this-talk">.*?</h4>(.*?)</div>',
+ r'(?s)<p><strong>About this talk:</strong>\s+(.*?)</p>',
+ ],
+ webpage, 'description', fatal=False)
+
+ return {
+ 'id': name,
+ 'url': video_url,
+ 'title': title,
+ 'thumbnail': thumbnail,
+ 'description': description,
+ }