1 from __future__ import unicode_literals
6 from .common import InfoExtractor
10 from ..utils import ExtractorError
13 class UstreamIE(InfoExtractor):
14 _VALID_URL = r'https?://www\.ustream\.tv/(?P<type>recorded|embed|embed/recorded)/(?P<videoID>\d+)'
17 'url': 'http://www.ustream.tv/recorded/20274954',
18 'md5': '088f151799e8f572f84eb62f17d73e5c',
22 'uploader': 'Young Americans for Liberty',
23 'title': 'Young Americans for Liberty February 7, 2012 2:28 AM',
26 # From http://sportscanada.tv/canadagames/index.php/week2/figure-skating/444
27 # Title and uploader available only from params JSON
28 'url': 'http://www.ustream.tv/embed/recorded/59307601?ub=ff0000&lc=ff0000&oc=ffffff&uc=ffffff&v=3&wmode=direct',
29 'md5': '5a2abf40babeac9812ed20ae12d34e10',
33 'title': '-CG11- Canada Games Figure Skating',
34 'uploader': 'sportscanadatv',
38 def _real_extract(self, url):
39 m = re.match(self._VALID_URL, url)
40 video_id = m.group('videoID')
42 # some sites use this embed format (see: http://github.com/rg3/youtube-dl/issues/2990)
43 if m.group('type') == 'embed/recorded':
44 video_id = m.group('videoID')
45 desktop_url = 'http://www.ustream.tv/recorded/' + video_id
46 return self.url_result(desktop_url, 'Ustream')
47 if m.group('type') == 'embed':
48 video_id = m.group('videoID')
49 webpage = self._download_webpage(url, video_id)
50 desktop_video_id = self._html_search_regex(
51 r'ContentVideoIds=\["([^"]*?)"\]', webpage, 'desktop_video_id')
52 desktop_url = 'http://www.ustream.tv/recorded/' + desktop_video_id
53 return self.url_result(desktop_url, 'Ustream')
55 params = self._download_json('https://api.ustream.tv/videos/' + video_id + '.json', video_id)
58 raise ExtractorError(params['error']['message'], expected=True)
60 video_url = params['video']['media_urls']['flv']
62 webpage = self._download_webpage(url, video_id)
64 self.report_extraction(video_id)
66 video_title = self._html_search_regex(r'data-title="(?P<title>.+)"',
67 webpage, 'title', default=None)
71 video_title = params['moduleConfig']['meta']['title']
76 video_title = 'Ustream video ' + video_id
78 uploader = self._html_search_regex(r'data-content-type="channel".*?>(?P<uploader>.*?)</a>',
79 webpage, 'uploader', fatal=False, flags=re.DOTALL, default=None)
83 uploader = params['moduleConfig']['meta']['userName']
87 thumbnail = self._html_search_regex(r'<link rel="image_src" href="(?P<thumb>.*?)"',
88 webpage, 'thumbnail', fatal=False)
96 'thumbnail': thumbnail,
100 class UstreamChannelIE(InfoExtractor):
101 _VALID_URL = r'https?://www\.ustream\.tv/channel/(?P<slug>.+)'
102 IE_NAME = 'ustream:channel'
104 'url': 'http://www.ustream.tv/channel/channeljapan',
108 'playlist_mincount': 17,
111 def _real_extract(self, url):
112 m = re.match(self._VALID_URL, url)
113 display_id = m.group('slug')
114 webpage = self._download_webpage(url, display_id)
115 channel_id = self._html_search_meta('ustream:channel_id', webpage)
117 BASE = 'http://www.ustream.tv'
118 next_url = '/ajax/socialstream/videos/%s/1.json' % channel_id
121 reply = self._download_json(
122 compat_urlparse.urljoin(BASE, next_url), display_id,
123 note='Downloading video information (next: %d)' % (len(video_ids) + 1))
124 video_ids.extend(re.findall(r'data-content-id="(\d.*)"', reply['data']))
125 next_url = reply['nextUrl']
128 self.url_result('http://www.ustream.tv/recorded/' + vid, 'Ustream')
129 for vid in video_ids]
133 'display_id': display_id,