]>
Commit | Line | Data |
---|---|---|
22a510ff THD |
1 | from __future__ import unicode_literals |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import ( | |
5 | ExtractorError, | |
6 | traverse_obj, | |
7 | ) | |
8 | ||
9 | ||
10 | class MixchIE(InfoExtractor): | |
11 | IE_NAME = 'mixch' | |
12 | _VALID_URL = r'https?://(?:www\.)?mixch\.tv/u/(?P<id>\d+)' | |
13 | ||
14 | TESTS = [{ | |
15 | 'url': 'https://mixch.tv/u/16236849/live', | |
16 | 'skip': 'don\'t know if this live persists', | |
17 | 'info_dict': { | |
18 | 'id': '16236849', | |
19 | 'title': '24配信シェア⭕️投票🙏💦', | |
20 | 'comment_count': 13145, | |
21 | 'view_count': 28348, | |
22 | 'timestamp': 1636189377, | |
23 | 'uploader': '🦥伊咲👶🏻#フレアワ', | |
24 | 'uploader_id': '16236849', | |
25 | } | |
26 | }, { | |
27 | 'url': 'https://mixch.tv/u/16137876/live', | |
28 | 'only_matching': True, | |
29 | }] | |
30 | ||
31 | def _real_extract(self, url): | |
32 | video_id = self._match_id(url) | |
33 | webpage = self._download_webpage(f'https://mixch.tv/u/{video_id}/live', video_id) | |
34 | ||
35 | initial_js_state = self._parse_json(self._search_regex( | |
36 | r'(?m)^\s*window\.__INITIAL_JS_STATE__\s*=\s*(\{.+?\});\s*$', webpage, 'initial JS state'), video_id) | |
37 | if not initial_js_state.get('liveInfo'): | |
38 | raise ExtractorError('Livestream has ended.', expected=True) | |
39 | ||
40 | return { | |
41 | 'id': video_id, | |
42 | 'title': traverse_obj(initial_js_state, ('liveInfo', 'title')), | |
43 | 'comment_count': traverse_obj(initial_js_state, ('liveInfo', 'comments')), | |
44 | 'view_count': traverse_obj(initial_js_state, ('liveInfo', 'visitor')), | |
45 | 'timestamp': traverse_obj(initial_js_state, ('liveInfo', 'created')), | |
46 | 'uploader': traverse_obj(initial_js_state, ('broadcasterInfo', 'name')), | |
47 | 'uploader_id': video_id, | |
48 | 'formats': [{ | |
49 | 'format_id': 'hls', | |
50 | 'url': traverse_obj(initial_js_state, ('liveInfo', 'hls')) or 'https://d1hd0ww6piyb43.cloudfront.net/hls/torte_%s.m3u8' % video_id, | |
51 | 'ext': 'mp4', | |
52 | 'protocol': 'm3u8', | |
53 | }], | |
54 | 'is_live': True, | |
55 | } |