[ie/dropbox] Fix password-protected video extraction (#11636)
[yt-dlp3.git] / yt_dlp / extractor / mixch.py
blob4bccc81bdcfd81bab76832bf68dd90a3b6f9c86b
1 from .common import InfoExtractor
2 from ..networking.exceptions import HTTPError
3 from ..utils import (
4 ExtractorError,
5 UserNotLive,
6 int_or_none,
7 str_or_none,
8 url_or_none,
10 from ..utils.traversal import traverse_obj
13 class MixchIE(InfoExtractor):
14 IE_NAME = 'mixch'
15 _VALID_URL = r'https?://mixch\.tv/u/(?P<id>\d+)'
17 _TESTS = [{
18 'url': 'https://mixch.tv/u/16943797/live',
19 'skip': 'don\'t know if this live persists',
20 'info_dict': {
21 'id': '16943797',
22 'ext': 'mp4',
23 'title': '#EntView #カリナ #セブチ 2024-05-05 06:58',
24 'comment_count': int,
25 'view_count': int,
26 'timestamp': 1714726805,
27 'uploader': 'Ent.View K-news🎶💕',
28 'uploader_id': '16943797',
29 'live_status': 'is_live',
30 'upload_date': '20240503',
32 }, {
33 'url': 'https://mixch.tv/u/16137876/live',
34 'only_matching': True,
37 def _real_extract(self, url):
38 video_id = self._match_id(url)
39 data = self._download_json(f'https://mixch.tv/api-web/users/{video_id}/live', video_id)
40 if not traverse_obj(data, ('liveInfo', {dict})):
41 raise UserNotLive(video_id=video_id)
43 return {
44 'id': video_id,
45 'uploader_id': video_id,
46 **traverse_obj(data, {
47 'title': ('liveInfo', 'title', {str}),
48 'comment_count': ('liveInfo', 'comments', {int_or_none}),
49 'view_count': ('liveInfo', 'visitor', {int_or_none}),
50 'timestamp': ('liveInfo', 'created', {int_or_none}),
51 'uploader': ('broadcasterInfo', 'name', {str}),
52 }),
53 'formats': [{
54 'format_id': 'hls',
55 'url': data['liveInfo']['hls'],
56 'ext': 'mp4',
57 'protocol': 'm3u8',
58 }],
59 'is_live': True,
60 '__post_extractor': self.extract_comments(video_id),
63 def _get_comments(self, video_id):
64 yield from traverse_obj(self._download_json(
65 f'https://mixch.tv/api-web/lives/{video_id}/messages', video_id,
66 note='Downloading comments', errnote='Failed to download comments'), (..., {
67 'author': ('name', {str}),
68 'author_id': ('user_id', {str_or_none}),
69 'id': ('message_id', {str}, filter),
70 'text': ('body', {str}),
71 'timestamp': ('created', {int}),
72 }))
75 class MixchArchiveIE(InfoExtractor):
76 IE_NAME = 'mixch:archive'
77 _VALID_URL = r'https?://mixch\.tv/archive/(?P<id>\d+)'
79 _TESTS = [{
80 'url': 'https://mixch.tv/archive/421',
81 'skip': 'paid video, no DRM. expires at Jan 23',
82 'info_dict': {
83 'id': '421',
84 'ext': 'mp4',
85 'title': '96NEKO SHOW TIME',
87 }, {
88 'url': 'https://mixch.tv/archive/1213',
89 'skip': 'paid video, no DRM. expires at Dec 31, 2023',
90 'info_dict': {
91 'id': '1213',
92 'ext': 'mp4',
93 'title': '【特別トーク番組アーカイブス】Merm4id×燐舞曲 2nd LIVE「VERSUS」',
94 'release_date': '20231201',
95 'thumbnail': str,
97 }, {
98 'url': 'https://mixch.tv/archive/1214',
99 'only_matching': True,
102 def _real_extract(self, url):
103 video_id = self._match_id(url)
105 try:
106 info_json = self._download_json(
107 f'https://mixch.tv/api-web/archive/{video_id}', video_id)['archive']
108 except ExtractorError as e:
109 if isinstance(e.cause, HTTPError) and e.cause.status == 401:
110 self.raise_login_required()
111 raise
113 return {
114 'id': video_id,
115 'title': traverse_obj(info_json, ('title', {str})),
116 'formats': self._extract_m3u8_formats(info_json['archiveURL'], video_id),
117 'thumbnail': traverse_obj(info_json, ('thumbnailURL', {url_or_none})),
121 class MixchMovieIE(InfoExtractor):
122 IE_NAME = 'mixch:movie'
123 _VALID_URL = r'https?://mixch\.tv/m/(?P<id>\w+)'
125 _TESTS = [{
126 'url': 'https://mixch.tv/m/Ve8KNkJ5',
127 'info_dict': {
128 'id': 'Ve8KNkJ5',
129 'title': '夏☀️\nムービーへのポイントは本イベントに加算されないので配信にてお願い致します🙇🏻\u200d♀️\n#TGCCAMPUS #ミス東大 #ミス東大2024 ',
130 'ext': 'mp4',
131 'uploader': 'ミス東大No.5 松藤百香🍑💫',
132 'uploader_id': '12299174',
133 'channel_follower_count': int,
134 'view_count': int,
135 'like_count': int,
136 'comment_count': int,
137 'timestamp': 1724070828,
138 'uploader_url': 'https://mixch.tv/u/12299174',
139 'live_status': 'not_live',
140 'upload_date': '20240819',
142 }, {
143 'url': 'https://mixch.tv/m/61DzpIKE',
144 'only_matching': True,
147 def _real_extract(self, url):
148 video_id = self._match_id(url)
149 data = self._download_json(
150 f'https://mixch.tv/api-web/movies/{video_id}', video_id)
151 return {
152 'id': video_id,
153 'formats': [{
154 'format_id': 'mp4',
155 'url': data['movie']['file'],
156 'ext': 'mp4',
158 **traverse_obj(data, {
159 'title': ('movie', 'title', {str}),
160 'thumbnail': ('movie', 'thumbnailURL', {url_or_none}),
161 'uploader': ('ownerInfo', 'name', {str}),
162 'uploader_id': ('ownerInfo', 'id', {int}, {str_or_none}),
163 'channel_follower_count': ('ownerInfo', 'fan', {int_or_none}),
164 'view_count': ('ownerInfo', 'view', {int_or_none}),
165 'like_count': ('movie', 'favCount', {int_or_none}),
166 'comment_count': ('movie', 'commentCount', {int_or_none}),
167 'timestamp': ('movie', 'published', {int_or_none}),
168 'uploader_url': ('ownerInfo', 'id', {lambda x: x and f'https://mixch.tv/u/{x}'}, filter),
170 'live_status': 'not_live',