diff --git a/youtube_dl/extractor/ustream.py b/youtube_dl/extractor/ustream.py index 18add908e..3065c9f31 100644 --- a/youtube_dl/extractor/ustream.py +++ b/youtube_dl/extractor/ustream.py @@ -7,7 +7,11 @@ from ..compat import ( compat_urlparse, ) -from ..utils import ExtractorError +from ..utils import ( + ExtractorError, + int_or_none, + float_or_none, +) class UstreamIE(InfoExtractor): @@ -54,46 +58,47 @@ def _real_extract(self, url): params = self._download_json('https://api.ustream.tv/videos/' + video_id + '.json', video_id) - if 'error' in params: - raise ExtractorError(params['error']['message'], expected=True) + error = params.get('error') + if error: + raise ExtractorError( + '%s returned error: %s' % (self.IE_NAME, error), expected=True) - video_url = params['video']['media_urls']['flv'] + video = params['video'] - webpage = self._download_webpage(url, video_id) + formats = [{ + 'id': format_id, + 'url': video_url, + 'ext': format_id, + } for format_id, video_url in video['media_urls'].items()] + self._sort_formats(formats) - self.report_extraction(video_id) + title = video['title'] + description = video.get('description') + timestamp = int_or_none(video.get('created_at')) + duration = float_or_none(video.get('length')) + filesize = float_or_none(video.get('file_size')) + view_count = int_or_none(video.get('views')) - video_title = self._html_search_regex(r'data-title="(?P