- video_id = m.group('videoID')
-
- video_url = u'http://tcdn.ustream.tv/video/%s' % video_id
- webpage = self._download_webpage(url, video_id)
-
- self.report_extraction(video_id)
-
- video_title = self._html_search_regex(r'data-title="(?P<title>.+)"',
- webpage, u'title')
-
- uploader = self._html_search_regex(r'data-content-type="channel".*?>(?P<uploader>.*?)</a>',
- webpage, u'uploader', fatal=False, flags=re.DOTALL)
-
- thumbnail = self._html_search_regex(r'<link rel="image_src" href="(?P<thumb>.*?)"',
- webpage, u'thumbnail', fatal=False)
-
- info = {
- 'id': video_id,
- 'url': video_url,
- 'ext': 'flv',
- 'title': video_title,
- 'uploader': uploader,
- 'thumbnail': thumbnail,
- }
- return info
-
-# More robust than regular expressions
-
-class ChannelParser(HTMLParser):
- """
- <meta name="ustream:channel_id" content="1234">
- """
- channel_id = None
-
- def handle_starttag(self, tag, attrs):
- if tag != 'meta':
- return
- values = dict(attrs)
- if values.get('name') != 'ustream:channel_id':
- return
- value = values.get('content', '')
- if value.isdigit():
- self.channel_id = value
-
-class SocialstreamParser(HTMLParser):
- """
- <li class="content123 video" data-content-id="123" data-length="1452"
- data-href="/recorded/123" data-og-url="/recorded/123">
- """
- def __init__(self):
- HTMLParser.__init__(self)
- self.content_ids = []
-
- def handle_starttag(self, tag, attrs):
- if tag != 'li':
- return
- for (attr, value) in attrs:
- if attr == 'data-content-id' and value.isdigit():
- self.content_ids.append(value)
+ video_id = m.group('id')
+
+ # some sites use this embed format (see: http://github.com/rg3/youtube-dl/issues/2990)
+ if m.group('type') == 'embed/recorded':
+ video_id = m.group('id')
+ desktop_url = 'http://www.ustream.tv/recorded/' + video_id
+ return self.url_result(desktop_url, 'Ustream')
+ if m.group('type') == 'embed':
+ video_id = m.group('id')
+ webpage = self._download_webpage(url, video_id)
+ desktop_video_id = self._html_search_regex(
+ r'ContentVideoIds=\["([^"]*?)"\]', webpage, 'desktop_video_id')
+ desktop_url = 'http://www.ustream.tv/recorded/' + desktop_video_id
+ return self.url_result(desktop_url, 'Ustream')
+
+ params = self._download_json(
+ 'https://api.ustream.tv/videos/%s.json' % video_id, video_id)
+
+ error = params.get('error')
+ if error:
+ raise ExtractorError(
+ '%s returned error: %s' % (self.IE_NAME, error), expected=True)
+
+ video = params['video']
+
+ title = video['title']
+ filesize = float_or_none(video.get('file_size'))
+
+ formats = [{
+ 'id': video_id,
+ 'url': video_url,
+ 'ext': format_id,
+ 'filesize': filesize,
+ } for format_id, video_url in video['media_urls'].items()]
+ self._sort_formats(formats)
+
+ description = video.get('description')
+ timestamp = int_or_none(video.get('created_at'))
+ duration = float_or_none(video.get('length'))
+ view_count = int_or_none(video.get('views'))
+
+ uploader = video.get('owner', {}).get('username')
+ uploader_id = video.get('owner', {}).get('id')
+
+ thumbnails = [{
+ 'id': thumbnail_id,
+ 'url': thumbnail_url,
+ } for thumbnail_id, thumbnail_url in video.get('thumbnail', {}).items()]
+
+ return {
+ 'id': video_id,
+ 'title': title,
+ 'description': description,
+ 'thumbnails': thumbnails,
+ 'timestamp': timestamp,
+ 'duration': duration,
+ 'view_count': view_count,
+ 'uploader': uploader,
+ 'uploader_id': uploader_id,
+ 'formats': formats,
+ }
+