1 from __future__ import unicode_literals
5 from .common import InfoExtractor
16 class UstreamIE(InfoExtractor):
17 _VALID_URL = r'https?://www\.ustream\.tv/(?P<type>recorded|embed|embed/recorded)/(?P<id>\d+)'
20 'url': 'http://www.ustream.tv/recorded/20274954',
21 'md5': '088f151799e8f572f84eb62f17d73e5c',
25 'uploader': 'Young Americans for Liberty',
26 'title': 'Young Americans for Liberty February 7, 2012 2:28 AM',
29 # From http://sportscanada.tv/canadagames/index.php/week2/figure-skating/444
30 # Title and uploader available only from params JSON
31 'url': 'http://www.ustream.tv/embed/recorded/59307601?ub=ff0000&lc=ff0000&oc=ffffff&uc=ffffff&v=3&wmode=direct',
32 'md5': '5a2abf40babeac9812ed20ae12d34e10',
36 'title': '-CG11- Canada Games Figure Skating',
37 'uploader': 'sportscanadatv',
41 def _real_extract(self, url):
42 m = re.match(self._VALID_URL, url)
43 video_id = m.group('id')
45 # some sites use this embed format (see: http://github.com/rg3/youtube-dl/issues/2990)
46 if m.group('type') == 'embed/recorded':
47 video_id = m.group('id')
48 desktop_url = 'http://www.ustream.tv/recorded/' + video_id
49 return self.url_result(desktop_url, 'Ustream')
50 if m.group('type') == 'embed':
51 video_id = m.group('id')
52 webpage = self._download_webpage(url, video_id)
53 desktop_video_id = self._html_search_regex(
54 r'ContentVideoIds=\["([^"]*?)"\]', webpage, 'desktop_video_id')
55 desktop_url = 'http://www.ustream.tv/recorded/' + desktop_video_id
56 return self.url_result(desktop_url, 'Ustream')
58 params = self._download_json(
59 'https://api.ustream.tv/videos/%s.json' % video_id, video_id)
61 error = params.get('error')
64 '%s returned error: %s' % (self.IE_NAME, error), expected=True)
66 video = params['video']
68 title = video['title']
69 filesize = float_or_none(video.get('file_size'))
76 } for format_id, video_url in video['media_urls'].items()]
77 self._sort_formats(formats)
79 description = video.get('description')
80 timestamp = int_or_none(video.get('created_at'))
81 duration = float_or_none(video.get('length'))
82 view_count = int_or_none(video.get('views'))
84 uploader = video.get('owner', {}).get('username')
85 uploader_id = video.get('owner', {}).get('id')
90 } for thumbnail_id, thumbnail_url in video.get('thumbnail', {}).items()]
95 'description': description,
96 'thumbnails': thumbnails,
97 'timestamp': timestamp,
99 'view_count': view_count,
100 'uploader': uploader,
101 'uploader_id': uploader_id,
106 class UstreamChannelIE(InfoExtractor):
107 _VALID_URL = r'https?://www\.ustream\.tv/channel/(?P<slug>.+)'
108 IE_NAME = 'ustream:channel'
110 'url': 'http://www.ustream.tv/channel/channeljapan',
114 'playlist_mincount': 17,
117 def _real_extract(self, url):
118 m = re.match(self._VALID_URL, url)
119 display_id = m.group('slug')
120 webpage = self._download_webpage(url, display_id)
121 channel_id = self._html_search_meta('ustream:channel_id', webpage)
123 BASE = 'http://www.ustream.tv'
124 next_url = '/ajax/socialstream/videos/%s/1.json' % channel_id
127 reply = self._download_json(
128 compat_urlparse.urljoin(BASE, next_url), display_id,
129 note='Downloading video information (next: %d)' % (len(video_ids) + 1))
130 video_ids.extend(re.findall(r'data-content-id="(\d.*)"', reply['data']))
131 next_url = reply['nextUrl']
134 self.url_result('http://www.ustream.tv/recorded/' + vid, 'Ustream')
135 for vid in video_ids]
139 'display_id': display_id,