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