]>
Commit | Line | Data |
---|---|---|
0eb799ba JMF |
1 | from __future__ import unicode_literals |
2 | ||
f8610ba1 | 3 | import json |
78af8eb1 PH |
4 | import re |
5 | ||
6 | from .common import InfoExtractor | |
1cc79574 | 7 | from ..compat import ( |
74ac9bdd | 8 | compat_urlparse, |
74ac9bdd | 9 | ) |
762155cc | 10 | from ..utils import ExtractorError |
78af8eb1 PH |
11 | |
12 | ||
13 | class UstreamIE(InfoExtractor): | |
b702eceb | 14 | _VALID_URL = r'https?://www\.ustream\.tv/(?P<type>recorded|embed|embed/recorded)/(?P<videoID>\d+)' |
0eb799ba | 15 | IE_NAME = 'ustream' |
cd9fdccd | 16 | _TESTS = [{ |
0eb799ba | 17 | 'url': 'http://www.ustream.tv/recorded/20274954', |
0eb799ba JMF |
18 | 'md5': '088f151799e8f572f84eb62f17d73e5c', |
19 | 'info_dict': { | |
9e875391 S |
20 | 'id': '20274954', |
21 | 'ext': 'flv', | |
22 | 'uploader': 'Young Americans for Liberty', | |
23 | 'title': 'Young Americans for Liberty February 7, 2012 2:28 AM', | |
0eb799ba | 24 | }, |
cd9fdccd YCH |
25 | }, { |
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', | |
30 | 'info_dict': { | |
31 | 'id': '59307601', | |
32 | 'ext': 'flv', | |
33 | 'title': '-CG11- Canada Games Figure Skating', | |
34 | 'uploader': 'sportscanadatv', | |
35 | } | |
36 | }] | |
78af8eb1 PH |
37 | |
38 | def _real_extract(self, url): | |
39 | m = re.match(self._VALID_URL, url) | |
b702eceb | 40 | video_id = m.group('videoID') |
41 | ||
9e875391 S |
42 | # some sites use this embed format (see: http://github.com/rg3/youtube-dl/issues/2990) |
43 | if m.group('type') == 'embed/recorded': | |
b702eceb | 44 | video_id = m.group('videoID') |
b702eceb | 45 | desktop_url = 'http://www.ustream.tv/recorded/' + video_id |
46 | return self.url_result(desktop_url, 'Ustream') | |
5c386252 | 47 | if m.group('type') == 'embed': |
48 | video_id = m.group('videoID') | |
49 | webpage = self._download_webpage(url, video_id) | |
9e875391 S |
50 | desktop_video_id = self._html_search_regex( |
51 | r'ContentVideoIds=\["([^"]*?)"\]', webpage, 'desktop_video_id') | |
5c386252 | 52 | desktop_url = 'http://www.ustream.tv/recorded/' + desktop_video_id |
53 | return self.url_result(desktop_url, 'Ustream') | |
54 | ||
f8610ba1 YCH |
55 | params = self._download_json( |
56 | 'http://cdngw.ustream.tv/rgwjson/Viewer.getVideo/' + json.dumps({ | |
57 | 'brandId': 1, | |
58 | 'videoId': int(video_id), | |
59 | 'autoplay': False, | |
60 | }), video_id) | |
61 | ||
762155cc YCH |
62 | if 'error' in params: |
63 | raise ExtractorError(params['error']['message'], expected=True) | |
64 | ||
f8610ba1 YCH |
65 | video_url = params['flv'] |
66 | ||
78af8eb1 PH |
67 | webpage = self._download_webpage(url, video_id) |
68 | ||
69 | self.report_extraction(video_id) | |
70 | ||
71 | video_title = self._html_search_regex(r'data-title="(?P<title>.+)"', | |
2a813727 YCH |
72 | webpage, 'title', default=None) |
73 | ||
74 | if not video_title: | |
75 | try: | |
76 | video_title = params['moduleConfig']['meta']['title'] | |
77 | except KeyError: | |
78 | pass | |
79 | ||
80 | if not video_title: | |
81 | video_title = 'Ustream video ' + video_id | |
78af8eb1 PH |
82 | |
83 | uploader = self._html_search_regex(r'data-content-type="channel".*?>(?P<uploader>.*?)</a>', | |
cd9fdccd YCH |
84 | webpage, 'uploader', fatal=False, flags=re.DOTALL, default=None) |
85 | ||
86 | if not uploader: | |
87 | try: | |
88 | uploader = params['moduleConfig']['meta']['userName'] | |
89 | except KeyError: | |
90 | uploader = None | |
78af8eb1 PH |
91 | |
92 | thumbnail = self._html_search_regex(r'<link rel="image_src" href="(?P<thumb>.*?)"', | |
9e1a5b84 | 93 | webpage, 'thumbnail', fatal=False) |
0eb799ba JMF |
94 | |
95 | return { | |
96 | 'id': video_id, | |
97 | 'url': video_url, | |
98 | 'ext': 'flv', | |
99 | 'title': video_title, | |
100 | 'uploader': uploader, | |
101 | 'thumbnail': thumbnail, | |
102 | } | |
103 | ||
bfd5c93a | 104 | |
bfd5c93a | 105 | class UstreamChannelIE(InfoExtractor): |
106 | _VALID_URL = r'https?://www\.ustream\.tv/channel/(?P<slug>.+)' | |
0eb799ba | 107 | IE_NAME = 'ustream:channel' |
22a6f150 PH |
108 | _TEST = { |
109 | 'url': 'http://www.ustream.tv/channel/channeljapan', | |
110 | 'info_dict': { | |
111 | 'id': '10874166', | |
112 | }, | |
446a03bd | 113 | 'playlist_mincount': 17, |
22a6f150 | 114 | } |
bfd5c93a | 115 | |
116 | def _real_extract(self, url): | |
117 | m = re.match(self._VALID_URL, url) | |
22a6f150 PH |
118 | display_id = m.group('slug') |
119 | webpage = self._download_webpage(url, display_id) | |
44789f24 | 120 | channel_id = self._html_search_meta('ustream:channel_id', webpage) |
bfd5c93a | 121 | |
bfd5c93a | 122 | BASE = 'http://www.ustream.tv' |
123 | next_url = '/ajax/socialstream/videos/%s/1.json' % channel_id | |
a921f407 | 124 | video_ids = [] |
bfd5c93a | 125 | while next_url: |
22a6f150 PH |
126 | reply = self._download_json( |
127 | compat_urlparse.urljoin(BASE, next_url), display_id, | |
128 | note='Downloading video information (next: %d)' % (len(video_ids) + 1)) | |
a921f407 | 129 | video_ids.extend(re.findall(r'data-content-id="(\d.*)"', reply['data'])) |
bfd5c93a | 130 | next_url = reply['nextUrl'] |
bfd5c93a | 131 | |
22a6f150 PH |
132 | entries = [ |
133 | self.url_result('http://www.ustream.tv/recorded/' + vid, 'Ustream') | |
134 | for vid in video_ids] | |
135 | return { | |
136 | '_type': 'playlist', | |
137 | 'id': channel_id, | |
138 | 'display_id': display_id, | |
139 | 'entries': entries, | |
140 | } |