]>
Commit | Line | Data |
---|---|---|
da3f7fb7 | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
0c0a70f4 | 3 | |
e3947e2b | 4 | import re |
da3f7fb7 | 5 | |
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
0c0a70f4 S |
8 | clean_html, |
9 | parse_iso8601, | |
10 | float_or_none, | |
11 | int_or_none, | |
12 | compat_str, | |
65939eff | 13 | determine_ext, |
da3f7fb7 | 14 | ) |
15 | ||
16 | ||
17 | class HitboxIE(InfoExtractor): | |
0c0a70f4 | 18 | IE_NAME = 'hitbox' |
5f6fbcea S |
19 | _VALID_URL = r'https?://(?:www\.)?(?:hitbox|smashcast)\.tv/(?:[^/]+/)*videos?/(?P<id>[0-9]+)' |
20 | _TESTS = [{ | |
da3f7fb7 | 21 | 'url': 'http://www.hitbox.tv/video/203213', |
22 | 'info_dict': { | |
23 | 'id': '203213', | |
24 | 'title': 'hitbox @ gamescom, Sub Button Hype extended, Giveaway - hitbox News Update with Oxy', | |
25 | 'alt_title': 'hitboxlive - Aug 9th #6', | |
0c0a70f4 | 26 | 'description': '', |
da3f7fb7 | 27 | 'ext': 'mp4', |
ec85ded8 | 28 | 'thumbnail': r're:^https?://.*\.jpg$', |
0c0a70f4 | 29 | 'duration': 215.1666, |
da3f7fb7 | 30 | 'resolution': 'HD 720p', |
0c0a70f4 | 31 | 'uploader': 'hitboxlive', |
da3f7fb7 | 32 | 'view_count': int, |
0c0a70f4 | 33 | 'timestamp': 1407576133, |
da3f7fb7 | 34 | 'upload_date': '20140809', |
35 | 'categories': ['Live Show'], | |
36 | }, | |
37 | 'params': { | |
38 | # m3u8 download | |
39 | 'skip_download': True, | |
40 | }, | |
5f6fbcea S |
41 | }, { |
42 | 'url': 'https://www.smashcast.tv/hitboxlive/videos/203213', | |
43 | 'only_matching': True, | |
44 | }] | |
da3f7fb7 | 45 | |
e3947e2b | 46 | def _extract_metadata(self, url, video_id): |
da3f7fb7 | 47 | thumb_base = 'https://edge.sf.hitbox.tv' |
48 | metadata = self._download_json( | |
5f6fbcea | 49 | '%s/%s' % (url, video_id), video_id, 'Downloading metadata JSON') |
da3f7fb7 | 50 | |
e3947e2b | 51 | date = 'media_live_since' |
52 | media_type = 'livestream' | |
53 | if metadata.get('media_type') == 'video': | |
54 | media_type = 'video' | |
55 | date = 'media_date_added' | |
56 | ||
57 | video_meta = metadata.get(media_type, [])[0] | |
da3f7fb7 | 58 | title = video_meta.get('media_status') |
59 | alt_title = video_meta.get('media_title') | |
0c0a70f4 S |
60 | description = clean_html( |
61 | video_meta.get('media_description') or | |
62 | video_meta.get('media_description_md')) | |
63 | duration = float_or_none(video_meta.get('media_duration')) | |
da3f7fb7 | 64 | uploader = video_meta.get('media_user_name') |
0c0a70f4 S |
65 | views = int_or_none(video_meta.get('media_views')) |
66 | timestamp = parse_iso8601(video_meta.get(date), ' ') | |
da3f7fb7 | 67 | categories = [video_meta.get('category_name')] |
5f6fbcea S |
68 | thumbs = [{ |
69 | 'url': thumb_base + video_meta.get('media_thumbnail'), | |
70 | 'width': 320, | |
71 | 'height': 180 | |
72 | }, { | |
73 | 'url': thumb_base + video_meta.get('media_thumbnail_large'), | |
74 | 'width': 768, | |
75 | 'height': 432 | |
76 | }] | |
da3f7fb7 | 77 | |
da3f7fb7 | 78 | return { |
79 | 'id': video_id, | |
80 | 'title': title, | |
81 | 'alt_title': alt_title, | |
82 | 'description': description, | |
da3f7fb7 | 83 | 'ext': 'mp4', |
84 | 'thumbnails': thumbs, | |
85 | 'duration': duration, | |
0c0a70f4 | 86 | 'uploader': uploader, |
da3f7fb7 | 87 | 'view_count': views, |
0c0a70f4 | 88 | 'timestamp': timestamp, |
da3f7fb7 | 89 | 'categories': categories, |
da3f7fb7 | 90 | } |
e3947e2b | 91 | |
92 | def _real_extract(self, url): | |
93 | video_id = self._match_id(url) | |
94 | ||
e3947e2b | 95 | player_config = self._download_json( |
5f6fbcea | 96 | 'https://www.smashcast.tv/api/player/config/video/%s' % video_id, |
33b066bd | 97 | video_id, 'Downloading video JSON') |
e3947e2b | 98 | |
bc94bd51 S |
99 | formats = [] |
100 | for video in player_config['clip']['bitrates']: | |
101 | label = video.get('label') | |
102 | if label == 'Auto': | |
103 | continue | |
104 | video_url = video.get('url') | |
105 | if not video_url: | |
106 | continue | |
107 | bitrate = int_or_none(video.get('bitrate')) | |
108 | if determine_ext(video_url) == 'm3u8': | |
109 | if not video_url.startswith('http'): | |
110 | continue | |
111 | formats.append({ | |
112 | 'url': video_url, | |
113 | 'ext': 'mp4', | |
114 | 'tbr': bitrate, | |
115 | 'format_note': label, | |
116 | 'protocol': 'm3u8_native', | |
117 | }) | |
118 | else: | |
119 | formats.append({ | |
120 | 'url': video_url, | |
121 | 'tbr': bitrate, | |
122 | 'format_note': label, | |
123 | }) | |
29492f33 | 124 | self._sort_formats(formats) |
bc94bd51 | 125 | |
008bee0f | 126 | metadata = self._extract_metadata( |
5f6fbcea | 127 | 'https://www.smashcast.tv/api/media/video', video_id) |
bc94bd51 | 128 | metadata['formats'] = formats |
e3947e2b | 129 | |
130 | return metadata | |
131 | ||
132 | ||
133 | class HitboxLiveIE(HitboxIE): | |
0c0a70f4 | 134 | IE_NAME = 'hitbox:live' |
5f6fbcea S |
135 | _VALID_URL = r'https?://(?:www\.)?(?:hitbox|smashcast)\.tv/(?P<id>[^/?#&]+)' |
136 | _TESTS = [{ | |
e3947e2b | 137 | 'url': 'http://www.hitbox.tv/dimak', |
138 | 'info_dict': { | |
139 | 'id': 'dimak', | |
140 | 'ext': 'mp4', | |
0c0a70f4 S |
141 | 'description': 'md5:c9f80fa4410bc588d7faa40003fc7d0e', |
142 | 'timestamp': int, | |
143 | 'upload_date': compat_str, | |
144 | 'title': compat_str, | |
145 | 'uploader': 'Dimak', | |
e3947e2b | 146 | }, |
147 | 'params': { | |
148 | # live | |
149 | 'skip_download': True, | |
150 | }, | |
5f6fbcea S |
151 | }, { |
152 | 'url': 'https://www.smashcast.tv/dimak', | |
153 | 'only_matching': True, | |
154 | }] | |
155 | ||
156 | @classmethod | |
157 | def suitable(cls, url): | |
158 | return False if HitboxIE.suitable(url) else super(HitboxLiveIE, cls).suitable(url) | |
e3947e2b | 159 | |
160 | def _real_extract(self, url): | |
161 | video_id = self._match_id(url) | |
162 | ||
e3947e2b | 163 | player_config = self._download_json( |
5f6fbcea | 164 | 'https://www.smashcast.tv/api/player/config/live/%s' % video_id, |
0c0a70f4 | 165 | video_id) |
e3947e2b | 166 | |
167 | formats = [] | |
168 | cdns = player_config.get('cdns') | |
169 | servers = [] | |
170 | for cdn in cdns: | |
1e10d02f S |
171 | # Subscribe URLs are not playable |
172 | if cdn.get('rtmpSubscribe') is True: | |
173 | continue | |
e3947e2b | 174 | base_url = cdn.get('netConnectionUrl') |
ec85ded8 | 175 | host = re.search(r'.+\.([^\.]+\.[^\./]+)/.+', base_url).group(1) |
e3947e2b | 176 | if base_url not in servers: |
177 | servers.append(base_url) | |
178 | for stream in cdn.get('bitrates'): | |
179 | label = stream.get('label') | |
65939eff S |
180 | if label == 'Auto': |
181 | continue | |
182 | stream_url = stream.get('url') | |
183 | if not stream_url: | |
184 | continue | |
185 | bitrate = int_or_none(stream.get('bitrate')) | |
186 | if stream.get('provider') == 'hls' or determine_ext(stream_url) == 'm3u8': | |
187 | if not stream_url.startswith('http'): | |
188 | continue | |
e3947e2b | 189 | formats.append({ |
65939eff | 190 | 'url': stream_url, |
e3947e2b | 191 | 'ext': 'mp4', |
65939eff S |
192 | 'tbr': bitrate, |
193 | 'format_note': label, | |
194 | 'rtmp_live': True, | |
195 | }) | |
196 | else: | |
197 | formats.append({ | |
198 | 'url': '%s/%s' % (base_url, stream_url), | |
199 | 'ext': 'mp4', | |
200 | 'tbr': bitrate, | |
e3947e2b | 201 | 'rtmp_live': True, |
202 | 'format_note': host, | |
203 | 'page_url': url, | |
204 | 'player_url': 'http://www.hitbox.tv/static/player/flowplayer/flowplayer.commercial-3.2.16.swf', | |
205 | }) | |
e3947e2b | 206 | self._sort_formats(formats) |
14f41bc2 S |
207 | |
208 | metadata = self._extract_metadata( | |
5f6fbcea | 209 | 'https://www.smashcast.tv/api/media/live', video_id) |
e3947e2b | 210 | metadata['formats'] = formats |
211 | metadata['is_live'] = True | |
212 | metadata['title'] = self._live_title(metadata.get('title')) | |
14f41bc2 | 213 | |
e3947e2b | 214 | return metadata |