2 from __future__ import unicode_literals
5 from .common import InfoExtractor
11 class HitboxIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?hitbox\.tv/video/(?P<id>[0-9]+)'
14 'url': 'http://www.hitbox.tv/video/203213',
17 'title': 'hitbox @ gamescom, Sub Button Hype extended, Giveaway - hitbox News Update with Oxy',
18 'alt_title': 'hitboxlive - Aug 9th #6',
21 'thumbnail': 're:^https?://.*\.jpg$',
23 'resolution': 'HD 720p',
24 'uploader_id': 'hitboxlive',
26 'upload_date': '20140809',
27 'categories': ['Live Show'],
31 'skip_download': True,
35 def _extract_metadata(self, url, video_id):
36 thumb_base = 'https://edge.sf.hitbox.tv'
37 metadata = self._download_json(
38 '%s/%s' % (url, video_id), video_id
41 date = 'media_live_since'
42 media_type = 'livestream'
43 if metadata.get('media_type') == 'video':
45 date = 'media_date_added'
47 video_meta = metadata.get(media_type, [])[0]
48 title = video_meta.get('media_status')
49 alt_title = video_meta.get('media_title')
50 description = video_meta.get('media_description_md')
51 duration = int(float(video_meta.get('media_duration')))
52 uploader = video_meta.get('media_user_name')
53 views = int(video_meta.get('media_views'))
54 upload_date = unified_strdate(video_meta.get(date))
55 categories = [video_meta.get('category_name')]
57 {'url': thumb_base + video_meta.get('media_thumbnail'),
60 {'url': thumb_base + video_meta.get('media_thumbnail_large'),
68 'alt_title': alt_title,
69 'description': description,
73 'uploader_id': uploader,
75 'upload_date': upload_date,
76 'categories': categories,
79 def _real_extract(self, url):
80 video_id = self._match_id(url)
82 metadata = self._extract_metadata(
83 'https://www.hitbox.tv/api/media/video',
87 player_config = self._download_json(
88 'https://www.hitbox.tv/api/player/config/video/%s' % (video_id),
92 clip = player_config.get('clip')
93 video_url = clip.get('url')
94 res = clip.get('bitrates', [])[0].get('label')
96 metadata['resolution'] = res
97 metadata['url'] = video_url
98 metadata['protocol'] = 'm3u8'
103 class HitboxLiveIE(HitboxIE):
104 _VALID_URL = r'https?://(?:www\.)?hitbox\.tv/(?!video)(?P<id>.+)'
106 'url': 'http://www.hitbox.tv/dimak',
113 'uploader_id': 'Dimak',
117 'skip_download': True,
121 def _real_extract(self, url):
122 video_id = self._match_id(url)
124 metadata = self._extract_metadata(
125 'https://www.hitbox.tv/api/media/live',
129 player_config = self._download_json(
130 'https://www.hitbox.tv/api/player/config/live/%s' % (video_id),
135 cdns = player_config.get('cdns')
138 base_url = cdn.get('netConnectionUrl')
139 host = re.search('.+\.([^\.]+\.[^\./]+)/.+', base_url).group(1)
140 if base_url not in servers:
141 servers.append(base_url)
142 for stream in cdn.get('bitrates'):
143 label = stream.get('label')
146 'url': '%s/%s' % (base_url, stream.get('url')),
148 'vbr': stream.get('bitrate'),
153 'player_url': 'http://www.hitbox.tv/static/player/flowplayer/flowplayer.commercial-3.2.16.swf',
156 self._sort_formats(formats)
157 metadata['formats'] = formats
158 metadata['is_live'] = True
159 metadata['title'] = self._live_title(metadata.get('title'))