]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/mixch.py
[ie/mixch:archive] Fix extractor (#8761)
[yt-dlp.git] / yt_dlp / extractor / mixch.py
1 from .common import InfoExtractor
2 from ..networking.exceptions import HTTPError
3 from ..utils import ExtractorError, UserNotLive, url_or_none
4 from ..utils.traversal import traverse_obj
5
6
7 class MixchIE(InfoExtractor):
8 IE_NAME = 'mixch'
9 _VALID_URL = r'https?://(?:www\.)?mixch\.tv/u/(?P<id>\d+)'
10
11 _TESTS = [{
12 'url': 'https://mixch.tv/u/16236849/live',
13 'skip': 'don\'t know if this live persists',
14 'info_dict': {
15 'id': '16236849',
16 'title': '24配信シェア⭕️投票🙏💦',
17 'comment_count': 13145,
18 'view_count': 28348,
19 'timestamp': 1636189377,
20 'uploader': '🦥伊咲👶🏻#フレアワ',
21 'uploader_id': '16236849',
22 }
23 }, {
24 'url': 'https://mixch.tv/u/16137876/live',
25 'only_matching': True,
26 }]
27
28 def _real_extract(self, url):
29 video_id = self._match_id(url)
30 webpage = self._download_webpage(f'https://mixch.tv/u/{video_id}/live', video_id)
31
32 initial_js_state = self._parse_json(self._search_regex(
33 r'(?m)^\s*window\.__INITIAL_JS_STATE__\s*=\s*(\{.+?\});\s*$', webpage, 'initial JS state'), video_id)
34 if not initial_js_state.get('liveInfo'):
35 raise UserNotLive(video_id=video_id)
36
37 return {
38 'id': video_id,
39 'title': traverse_obj(initial_js_state, ('liveInfo', 'title')),
40 'comment_count': traverse_obj(initial_js_state, ('liveInfo', 'comments')),
41 'view_count': traverse_obj(initial_js_state, ('liveInfo', 'visitor')),
42 'timestamp': traverse_obj(initial_js_state, ('liveInfo', 'created')),
43 'uploader': traverse_obj(initial_js_state, ('broadcasterInfo', 'name')),
44 'uploader_id': video_id,
45 'formats': [{
46 'format_id': 'hls',
47 'url': (traverse_obj(initial_js_state, ('liveInfo', 'hls'))
48 or f'https://d1hd0ww6piyb43.cloudfront.net/hls/torte_{video_id}.m3u8'),
49 'ext': 'mp4',
50 'protocol': 'm3u8',
51 }],
52 'is_live': True,
53 }
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 'ext': 'mp4',
66 'title': '96NEKO SHOW TIME',
67 }
68 }, {
69 'url': 'https://mixch.tv/archive/1213',
70 'skip': 'paid video, no DRM. expires at Dec 31, 2023',
71 'info_dict': {
72 'id': '1213',
73 'ext': 'mp4',
74 'title': '【特別トーク番組アーカイブス】Merm4id×燐舞曲 2nd LIVE「VERSUS」',
75 'release_date': '20231201',
76 'thumbnail': str,
77 }
78 }, {
79 'url': 'https://mixch.tv/archive/1214',
80 'only_matching': True,
81 }]
82
83 def _real_extract(self, url):
84 video_id = self._match_id(url)
85
86 try:
87 info_json = self._download_json(
88 f'https://mixch.tv/api-web/archive/{video_id}', video_id)['archive']
89 except ExtractorError as e:
90 if isinstance(e.cause, HTTPError) and e.cause.status == 401:
91 self.raise_login_required()
92 raise
93
94 return {
95 'id': video_id,
96 'title': traverse_obj(info_json, ('title', {str})),
97 'formats': self._extract_m3u8_formats(info_json['archiveURL'], video_id),
98 'thumbnail': traverse_obj(info_json, ('thumbnailURL', {url_or_none})),
99 }