]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/mixch.py
[extractor/mixch] Support `--wait-for-video`
[yt-dlp.git] / yt_dlp / extractor / mixch.py
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
12 _TESTS = [{
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
36 is_live = initial_js_state.get('liveInfo')
37 if not is_live:
38 self.raise_no_formats('Livestream has ended or has not started', 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 }] if is_live else [],
54 'live_status': 'is_live' if is_live else 'is_upcoming',
55 }
56
57
58 class MixchArchiveIE(InfoExtractor):
59 IE_NAME = 'mixch:archive'
60 _VALID_URL = r'https?://(?:www\.)?mixch\.tv/archive/(?P<id>\d+)'
61
62 _TESTS = [{
63 'url': 'https://mixch.tv/archive/421',
64 'skip': 'paid video, no DRM. expires at Jan 23',
65 'info_dict': {
66 'id': '421',
67 'title': '96NEKO SHOW TIME',
68 }
69 }]
70
71 def _real_extract(self, url):
72 video_id = self._match_id(url)
73 webpage = self._download_webpage(url, video_id)
74
75 html5_videos = self._parse_html5_media_entries(
76 url, webpage.replace('video-js', 'video'), video_id, 'hls')
77 if not html5_videos:
78 self.raise_login_required(method='cookies')
79 infodict = html5_videos[0]
80 infodict.update({
81 'id': video_id,
82 'title': self._html_search_regex(r'class="archive-title">(.+?)</', webpage, 'title')
83 })
84
85 return infodict