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