]>
Commit | Line | Data |
---|---|---|
22a510ff THD |
1 | from .common import InfoExtractor |
2 | from ..utils import ( | |
3 | ExtractorError, | |
4 | traverse_obj, | |
5 | ) | |
6 | ||
7 | ||
8 | class MixchIE(InfoExtractor): | |
9 | IE_NAME = 'mixch' | |
10 | _VALID_URL = r'https?://(?:www\.)?mixch\.tv/u/(?P<id>\d+)' | |
11 | ||
ba1c671d | 12 | _TESTS = [{ |
22a510ff THD |
13 | 'url': 'https://mixch.tv/u/16236849/live', |
14 | 'skip': 'don\'t know if this live persists', | |
15 | 'info_dict': { | |
16 | 'id': '16236849', | |
17 | 'title': '24配信シェア⭕️投票🙏💦', | |
18 | 'comment_count': 13145, | |
19 | 'view_count': 28348, | |
20 | 'timestamp': 1636189377, | |
21 | 'uploader': '🦥伊咲👶🏻#フレアワ', | |
22 | 'uploader_id': '16236849', | |
23 | } | |
24 | }, { | |
25 | 'url': 'https://mixch.tv/u/16137876/live', | |
26 | 'only_matching': True, | |
27 | }] | |
28 | ||
29 | def _real_extract(self, url): | |
30 | video_id = self._match_id(url) | |
31 | webpage = self._download_webpage(f'https://mixch.tv/u/{video_id}/live', video_id) | |
32 | ||
33 | initial_js_state = self._parse_json(self._search_regex( | |
34 | r'(?m)^\s*window\.__INITIAL_JS_STATE__\s*=\s*(\{.+?\});\s*$', webpage, 'initial JS state'), video_id) | |
35 | if not initial_js_state.get('liveInfo'): | |
36 | raise ExtractorError('Livestream has ended.', expected=True) | |
37 | ||
38 | return { | |
39 | 'id': video_id, | |
40 | 'title': traverse_obj(initial_js_state, ('liveInfo', 'title')), | |
41 | 'comment_count': traverse_obj(initial_js_state, ('liveInfo', 'comments')), | |
42 | 'view_count': traverse_obj(initial_js_state, ('liveInfo', 'visitor')), | |
43 | 'timestamp': traverse_obj(initial_js_state, ('liveInfo', 'created')), | |
44 | 'uploader': traverse_obj(initial_js_state, ('broadcasterInfo', 'name')), | |
45 | 'uploader_id': video_id, | |
46 | 'formats': [{ | |
47 | 'format_id': 'hls', | |
48 | 'url': traverse_obj(initial_js_state, ('liveInfo', 'hls')) or 'https://d1hd0ww6piyb43.cloudfront.net/hls/torte_%s.m3u8' % video_id, | |
49 | 'ext': 'mp4', | |
50 | 'protocol': 'm3u8', | |
51 | }], | |
52 | 'is_live': True, | |
53 | } | |
ba1c671d LNO |
54 | |
55 | ||
56 | class MixchArchiveIE(InfoExtractor): | |
57 | IE_NAME = 'mixch:archive' | |
58 | _VALID_URL = r'https?://(?:www\.)?mixch\.tv/archive/(?P<id>\d+)' | |
59 | ||
60 | _TESTS = [{ | |
61 | 'url': 'https://mixch.tv/archive/421', | |
62 | 'skip': 'paid video, no DRM. expires at Jan 23', | |
63 | 'info_dict': { | |
64 | 'id': '421', | |
65 | 'title': '96NEKO SHOW TIME', | |
66 | } | |
67 | }] | |
68 | ||
69 | def _real_extract(self, url): | |
70 | video_id = self._match_id(url) | |
71 | webpage = self._download_webpage(url, video_id) | |
72 | ||
73 | html5_videos = self._parse_html5_media_entries( | |
74 | url, webpage.replace('video-js', 'video'), video_id, 'hls') | |
75 | if not html5_videos: | |
76 | self.raise_login_required(method='cookies') | |
77 | infodict = html5_videos[0] | |
78 | infodict.update({ | |
79 | 'id': video_id, | |
80 | 'title': self._html_search_regex(r'class="archive-title">(.+?)</', webpage, 'title') | |
81 | }) | |
82 | ||
83 | return infodict |