4 from .common import InfoExtractor
11 class UstreamIE(InfoExtractor):
12 _VALID_URL = r'https?://www\.ustream\.tv/recorded/(?P<videoID>\d+)'
15 u'url': u'http://www.ustream.tv/recorded/20274954',
16 u'file': u'20274954.flv',
17 u'md5': u'088f151799e8f572f84eb62f17d73e5c',
19 u"uploader": u"Young Americans for Liberty",
20 u"title": u"Young Americans for Liberty February 7, 2012 2:28 AM"
24 def _real_extract(self, url):
25 m = re.match(self._VALID_URL, url)
26 video_id = m.group('videoID')
28 video_url = u'http://tcdn.ustream.tv/video/%s' % video_id
29 webpage = self._download_webpage(url, video_id)
31 self.report_extraction(video_id)
33 video_title = self._html_search_regex(r'data-title="(?P<title>.+)"',
36 uploader = self._html_search_regex(r'data-content-type="channel".*?>(?P<uploader>.*?)</a>',
37 webpage, u'uploader', fatal=False, flags=re.DOTALL)
39 thumbnail = self._html_search_regex(r'<link rel="image_src" href="(?P<thumb>.*?)"',
40 webpage, u'thumbnail', fatal=False)
48 'thumbnail': thumbnail,
52 # More robust than regular expressions
54 class ChannelParser(compat_html_parser.HTMLParser):
56 <meta name="ustream:channel_id" content="1234">
60 def handle_starttag(self, tag, attrs):
64 if values.get('name') != 'ustream:channel_id':
66 value = values.get('content', '')
68 self.channel_id = value
70 class SocialstreamParser(compat_html_parser.HTMLParser):
72 <li class="content123 video" data-content-id="123" data-length="1452"
73 data-href="/recorded/123" data-og-url="/recorded/123">
76 compat_html_parser.HTMLParser.__init__(self)
79 def handle_starttag(self, tag, attrs):
82 for (attr, value) in attrs:
83 if attr == 'data-content-id' and value.isdigit():
84 self.content_ids.append(value)
86 class UstreamChannelIE(InfoExtractor):
87 _VALID_URL = r'https?://www\.ustream\.tv/channel/(?P<slug>.+)'
88 IE_NAME = u'ustream:channel'
90 def _real_extract(self, url):
91 m = re.match(self._VALID_URL, url)
92 slug = m.group('slug')
95 p.feed(self._download_webpage(url, slug))
97 channel_id = p.channel_id
99 p = SocialstreamParser()
100 BASE = 'http://www.ustream.tv'
101 next_url = '/ajax/socialstream/videos/%s/1.json' % channel_id
103 reply = json.loads(self._download_webpage(compat_urlparse.urljoin(BASE, next_url), channel_id))
104 p.feed(reply['data'])
105 next_url = reply['nextUrl']
107 video_ids = p.content_ids
109 urls = ['http://www.ustream.tv/recorded/' + vid for vid in video_ids]
110 url_entries = [self.url_result(eurl, 'Ustream') for eurl in urls]
111 return self.playlist_result(url_entries, channel_id)