]>
Commit | Line | Data |
---|---|---|
bfd5c93a | 1 | import json |
78af8eb1 PH |
2 | import re |
3 | ||
4 | from .common import InfoExtractor | |
74ac9bdd JMF |
5 | from ..utils import ( |
6 | compat_urlparse, | |
a921f407 | 7 | get_meta_content, |
74ac9bdd | 8 | ) |
78af8eb1 PH |
9 | |
10 | ||
11 | class UstreamIE(InfoExtractor): | |
12 | _VALID_URL = r'https?://www\.ustream\.tv/recorded/(?P<videoID>\d+)' | |
13 | IE_NAME = u'ustream' | |
6f5ac90c PH |
14 | _TEST = { |
15 | u'url': u'http://www.ustream.tv/recorded/20274954', | |
16 | u'file': u'20274954.flv', | |
17 | u'md5': u'088f151799e8f572f84eb62f17d73e5c', | |
18 | u'info_dict': { | |
19 | u"uploader": u"Young Americans for Liberty", | |
20 | u"title": u"Young Americans for Liberty February 7, 2012 2:28 AM" | |
21 | } | |
22 | } | |
78af8eb1 PH |
23 | |
24 | def _real_extract(self, url): | |
25 | m = re.match(self._VALID_URL, url) | |
26 | video_id = m.group('videoID') | |
27 | ||
28 | video_url = u'http://tcdn.ustream.tv/video/%s' % video_id | |
29 | webpage = self._download_webpage(url, video_id) | |
30 | ||
31 | self.report_extraction(video_id) | |
32 | ||
33 | video_title = self._html_search_regex(r'data-title="(?P<title>.+)"', | |
34 | webpage, u'title') | |
35 | ||
36 | uploader = self._html_search_regex(r'data-content-type="channel".*?>(?P<uploader>.*?)</a>', | |
37 | webpage, u'uploader', fatal=False, flags=re.DOTALL) | |
38 | ||
39 | thumbnail = self._html_search_regex(r'<link rel="image_src" href="(?P<thumb>.*?)"', | |
40 | webpage, u'thumbnail', fatal=False) | |
41 | ||
42 | info = { | |
43 | 'id': video_id, | |
44 | 'url': video_url, | |
45 | 'ext': 'flv', | |
46 | 'title': video_title, | |
47 | 'uploader': uploader, | |
48 | 'thumbnail': thumbnail, | |
49 | } | |
50 | return info | |
bfd5c93a | 51 | |
bfd5c93a | 52 | class UstreamChannelIE(InfoExtractor): |
53 | _VALID_URL = r'https?://www\.ustream\.tv/channel/(?P<slug>.+)' | |
54 | IE_NAME = u'ustream:channel' | |
55 | ||
56 | def _real_extract(self, url): | |
57 | m = re.match(self._VALID_URL, url) | |
58 | slug = m.group('slug') | |
a921f407 JMF |
59 | webpage = self._download_webpage(url, slug) |
60 | channel_id = get_meta_content('ustream:channel_id', webpage) | |
bfd5c93a | 61 | |
bfd5c93a | 62 | BASE = 'http://www.ustream.tv' |
63 | next_url = '/ajax/socialstream/videos/%s/1.json' % channel_id | |
a921f407 | 64 | video_ids = [] |
bfd5c93a | 65 | while next_url: |
74ac9bdd | 66 | reply = json.loads(self._download_webpage(compat_urlparse.urljoin(BASE, next_url), channel_id)) |
a921f407 | 67 | video_ids.extend(re.findall(r'data-content-id="(\d.*)"', reply['data'])) |
bfd5c93a | 68 | next_url = reply['nextUrl'] |
bfd5c93a | 69 | |
bfd5c93a | 70 | urls = ['http://www.ustream.tv/recorded/' + vid for vid in video_ids] |
71 | url_entries = [self.url_result(eurl, 'Ustream') for eurl in urls] | |
74ac9bdd | 72 | return self.playlist_result(url_entries, channel_id) |