]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/mixch.py
b980fd01a82d59e7532f8eaa5339f89a4953a330
[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, int_or_none, 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 data = self._download_json(f'https://mixch.tv/api-web/users/{video_id}/live', video_id)
31 if not traverse_obj(data, ('liveInfo', {dict})):
32 raise UserNotLive(video_id=video_id)
33
34 return {
35 'id': video_id,
36 'uploader_id': video_id,
37 **traverse_obj(data, {
38 'title': ('liveInfo', 'title', {str}),
39 'comment_count': ('liveInfo', 'comments', {int_or_none}),
40 'view_count': ('liveInfo', 'visitor', {int_or_none}),
41 'timestamp': ('liveInfo', 'created', {int_or_none}),
42 'uploader': ('broadcasterInfo', 'name', {str}),
43 }),
44 'formats': [{
45 'format_id': 'hls',
46 'url': data['liveInfo']['hls'],
47 'ext': 'mp4',
48 'protocol': 'm3u8',
49 }],
50 'is_live': True,
51 }
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 'ext': 'mp4',
64 'title': '96NEKO SHOW TIME',
65 }
66 }, {
67 'url': 'https://mixch.tv/archive/1213',
68 'skip': 'paid video, no DRM. expires at Dec 31, 2023',
69 'info_dict': {
70 'id': '1213',
71 'ext': 'mp4',
72 'title': '【特別トーク番組アーカイブス】Merm4id×燐舞曲 2nd LIVE「VERSUS」',
73 'release_date': '20231201',
74 'thumbnail': str,
75 }
76 }, {
77 'url': 'https://mixch.tv/archive/1214',
78 'only_matching': True,
79 }]
80
81 def _real_extract(self, url):
82 video_id = self._match_id(url)
83
84 try:
85 info_json = self._download_json(
86 f'https://mixch.tv/api-web/archive/{video_id}', video_id)['archive']
87 except ExtractorError as e:
88 if isinstance(e.cause, HTTPError) and e.cause.status == 401:
89 self.raise_login_required()
90 raise
91
92 return {
93 'id': video_id,
94 'title': traverse_obj(info_json, ('title', {str})),
95 'formats': self._extract_m3u8_formats(info_json['archiveURL'], video_id),
96 'thumbnail': traverse_obj(info_json, ('thumbnailURL', {url_or_none})),
97 }