]>
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 | ||
7fd4ed99 | 55 | params = self._download_json('https://api.ustream.tv/videos/' + video_id + '.json', video_id) |
f8610ba1 | 56 | |
762155cc YCH |
57 | if 'error' in params: |
58 | raise ExtractorError(params['error']['message'], expected=True) | |
59 | ||
7fd4ed99 | 60 | video_url = params['video']['media_urls']['flv'] |
f8610ba1 | 61 | |
78af8eb1 PH |
62 | webpage = self._download_webpage(url, video_id) |
63 | ||
64 | self.report_extraction(video_id) | |
65 | ||
66 | video_title = self._html_search_regex(r'data-title="(?P<title>.+)"', | |
2a813727 YCH |
67 | webpage, 'title', default=None) |
68 | ||
69 | if not video_title: | |
70 | try: | |
71 | video_title = params['moduleConfig']['meta']['title'] | |
72 | except KeyError: | |
73 | pass | |
74 | ||
75 | if not video_title: | |
76 | video_title = 'Ustream video ' + video_id | |
78af8eb1 PH |
77 | |
78 | uploader = self._html_search_regex(r'data-content-type="channel".*?>(?P<uploader>.*?)</a>', | |
cd9fdccd YCH |
79 | webpage, 'uploader', fatal=False, flags=re.DOTALL, default=None) |
80 | ||
81 | if not uploader: | |
82 | try: | |
83 | uploader = params['moduleConfig']['meta']['userName'] | |
84 | except KeyError: | |
85 | uploader = None | |
78af8eb1 PH |
86 | |
87 | thumbnail = self._html_search_regex(r'<link rel="image_src" href="(?P<thumb>.*?)"', | |
9e1a5b84 | 88 | webpage, 'thumbnail', fatal=False) |
0eb799ba JMF |
89 | |
90 | return { | |
91 | 'id': video_id, | |
92 | 'url': video_url, | |
93 | 'ext': 'flv', | |
94 | 'title': video_title, | |
95 | 'uploader': uploader, | |
96 | 'thumbnail': thumbnail, | |
97 | } | |
98 | ||
bfd5c93a | 99 | |
bfd5c93a | 100 | class UstreamChannelIE(InfoExtractor): |
101 | _VALID_URL = r'https?://www\.ustream\.tv/channel/(?P<slug>.+)' | |
0eb799ba | 102 | IE_NAME = 'ustream:channel' |
22a6f150 PH |
103 | _TEST = { |
104 | 'url': 'http://www.ustream.tv/channel/channeljapan', | |
105 | 'info_dict': { | |
106 | 'id': '10874166', | |
107 | }, | |
446a03bd | 108 | 'playlist_mincount': 17, |
22a6f150 | 109 | } |
bfd5c93a | 110 | |
111 | def _real_extract(self, url): | |
112 | m = re.match(self._VALID_URL, url) | |
22a6f150 PH |
113 | display_id = m.group('slug') |
114 | webpage = self._download_webpage(url, display_id) | |
44789f24 | 115 | channel_id = self._html_search_meta('ustream:channel_id', webpage) |
bfd5c93a | 116 | |
bfd5c93a | 117 | BASE = 'http://www.ustream.tv' |
118 | next_url = '/ajax/socialstream/videos/%s/1.json' % channel_id | |
a921f407 | 119 | video_ids = [] |
bfd5c93a | 120 | while next_url: |
22a6f150 PH |
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)) | |
a921f407 | 124 | video_ids.extend(re.findall(r'data-content-id="(\d.*)"', reply['data'])) |
bfd5c93a | 125 | next_url = reply['nextUrl'] |
bfd5c93a | 126 | |
22a6f150 PH |
127 | entries = [ |
128 | self.url_result('http://www.ustream.tv/recorded/' + vid, 'Ustream') | |
129 | for vid in video_ids] | |
130 | return { | |
131 | '_type': 'playlist', | |
132 | 'id': channel_id, | |
133 | 'display_id': display_id, | |
134 | 'entries': entries, | |
135 | } |