]>
Commit | Line | Data |
---|---|---|
0eb799ba JMF |
1 | from __future__ import unicode_literals |
2 | ||
78af8eb1 PH |
3 | import re |
4 | ||
5 | from .common import InfoExtractor | |
74ac9bdd JMF |
6 | from ..utils import ( |
7 | compat_urlparse, | |
74ac9bdd | 8 | ) |
78af8eb1 PH |
9 | |
10 | ||
11 | class UstreamIE(InfoExtractor): | |
b702eceb | 12 | _VALID_URL = r'https?://www\.ustream\.tv/(?P<type>recorded|embed|embed/recorded)/(?P<videoID>\d+)' |
0eb799ba | 13 | IE_NAME = 'ustream' |
ca6aada4 | 14 | _TEST = { |
0eb799ba | 15 | 'url': 'http://www.ustream.tv/recorded/20274954', |
0eb799ba JMF |
16 | 'md5': '088f151799e8f572f84eb62f17d73e5c', |
17 | 'info_dict': { | |
9e875391 S |
18 | 'id': '20274954', |
19 | 'ext': 'flv', | |
20 | 'uploader': 'Young Americans for Liberty', | |
21 | 'title': 'Young Americans for Liberty February 7, 2012 2:28 AM', | |
0eb799ba | 22 | }, |
6f5ac90c | 23 | } |
78af8eb1 PH |
24 | |
25 | def _real_extract(self, url): | |
26 | m = re.match(self._VALID_URL, url) | |
b702eceb | 27 | video_id = m.group('videoID') |
28 | ||
9e875391 S |
29 | # some sites use this embed format (see: http://github.com/rg3/youtube-dl/issues/2990) |
30 | if m.group('type') == 'embed/recorded': | |
b702eceb | 31 | video_id = m.group('videoID') |
b702eceb | 32 | desktop_url = 'http://www.ustream.tv/recorded/' + video_id |
33 | return self.url_result(desktop_url, 'Ustream') | |
5c386252 | 34 | if m.group('type') == 'embed': |
35 | video_id = m.group('videoID') | |
36 | webpage = self._download_webpage(url, video_id) | |
9e875391 S |
37 | desktop_video_id = self._html_search_regex( |
38 | r'ContentVideoIds=\["([^"]*?)"\]', webpage, 'desktop_video_id') | |
5c386252 | 39 | desktop_url = 'http://www.ustream.tv/recorded/' + desktop_video_id |
40 | return self.url_result(desktop_url, 'Ustream') | |
41 | ||
0eb799ba | 42 | video_url = 'http://tcdn.ustream.tv/video/%s' % video_id |
78af8eb1 PH |
43 | webpage = self._download_webpage(url, video_id) |
44 | ||
45 | self.report_extraction(video_id) | |
46 | ||
47 | video_title = self._html_search_regex(r'data-title="(?P<title>.+)"', | |
9e1a5b84 | 48 | webpage, 'title') |
78af8eb1 PH |
49 | |
50 | uploader = self._html_search_regex(r'data-content-type="channel".*?>(?P<uploader>.*?)</a>', | |
9e1a5b84 | 51 | webpage, 'uploader', fatal=False, flags=re.DOTALL) |
78af8eb1 PH |
52 | |
53 | thumbnail = self._html_search_regex(r'<link rel="image_src" href="(?P<thumb>.*?)"', | |
9e1a5b84 | 54 | webpage, 'thumbnail', fatal=False) |
0eb799ba JMF |
55 | |
56 | return { | |
57 | 'id': video_id, | |
58 | 'url': video_url, | |
59 | 'ext': 'flv', | |
60 | 'title': video_title, | |
61 | 'uploader': uploader, | |
62 | 'thumbnail': thumbnail, | |
63 | } | |
64 | ||
bfd5c93a | 65 | |
bfd5c93a | 66 | class UstreamChannelIE(InfoExtractor): |
67 | _VALID_URL = r'https?://www\.ustream\.tv/channel/(?P<slug>.+)' | |
0eb799ba | 68 | IE_NAME = 'ustream:channel' |
22a6f150 PH |
69 | _TEST = { |
70 | 'url': 'http://www.ustream.tv/channel/channeljapan', | |
71 | 'info_dict': { | |
72 | 'id': '10874166', | |
73 | }, | |
446a03bd | 74 | 'playlist_mincount': 17, |
22a6f150 | 75 | } |
bfd5c93a | 76 | |
77 | def _real_extract(self, url): | |
78 | m = re.match(self._VALID_URL, url) | |
22a6f150 PH |
79 | display_id = m.group('slug') |
80 | webpage = self._download_webpage(url, display_id) | |
44789f24 | 81 | channel_id = self._html_search_meta('ustream:channel_id', webpage) |
bfd5c93a | 82 | |
bfd5c93a | 83 | BASE = 'http://www.ustream.tv' |
84 | next_url = '/ajax/socialstream/videos/%s/1.json' % channel_id | |
a921f407 | 85 | video_ids = [] |
bfd5c93a | 86 | while next_url: |
22a6f150 PH |
87 | reply = self._download_json( |
88 | compat_urlparse.urljoin(BASE, next_url), display_id, | |
89 | note='Downloading video information (next: %d)' % (len(video_ids) + 1)) | |
a921f407 | 90 | video_ids.extend(re.findall(r'data-content-id="(\d.*)"', reply['data'])) |
bfd5c93a | 91 | next_url = reply['nextUrl'] |
bfd5c93a | 92 | |
22a6f150 PH |
93 | entries = [ |
94 | self.url_result('http://www.ustream.tv/recorded/' + vid, 'Ustream') | |
95 | for vid in video_ids] | |
96 | return { | |
97 | '_type': 'playlist', | |
98 | 'id': channel_id, | |
99 | 'display_id': display_id, | |
100 | 'entries': entries, | |
101 | } |