[cleanup] Mark broken and remove dead extractors (#9238)
[yt-dlp3.git] / yt_dlp / extractor / kuwo.py
blob3c93dedac2f9ea2a886e840286213bce83f0b02c
1 import re
3 from .common import InfoExtractor
4 from ..compat import compat_urlparse
5 from ..utils import (
6 get_element_by_id,
7 clean_html,
8 ExtractorError,
9 InAdvancePagedList,
10 remove_start,
14 class KuwoBaseIE(InfoExtractor):
15 _FORMATS = [
16 {'format': 'ape', 'ext': 'ape', 'preference': 100},
17 {'format': 'mp3-320', 'ext': 'mp3', 'br': '320kmp3', 'abr': 320, 'preference': 80},
18 {'format': 'mp3-192', 'ext': 'mp3', 'br': '192kmp3', 'abr': 192, 'preference': 70},
19 {'format': 'mp3-128', 'ext': 'mp3', 'br': '128kmp3', 'abr': 128, 'preference': 60},
20 {'format': 'wma', 'ext': 'wma', 'preference': 20},
21 {'format': 'aac', 'ext': 'aac', 'abr': 48, 'preference': 10}
24 def _get_formats(self, song_id, tolerate_ip_deny=False):
25 formats = []
26 for file_format in self._FORMATS:
27 query = {
28 'format': file_format['ext'],
29 'br': file_format.get('br', ''),
30 'rid': 'MUSIC_%s' % song_id,
31 'type': 'convert_url',
32 'response': 'url'
35 song_url = self._download_webpage(
36 'http://antiserver.kuwo.cn/anti.s',
37 song_id, note='Download %s url info' % file_format['format'],
38 query=query, headers=self.geo_verification_headers(),
41 if song_url == 'IPDeny' and not tolerate_ip_deny:
42 raise ExtractorError('This song is blocked in this region', expected=True)
44 if song_url.startswith('http://') or song_url.startswith('https://'):
45 formats.append({
46 'url': song_url,
47 'format_id': file_format['format'],
48 'format': file_format['format'],
49 'quality': file_format['preference'],
50 'abr': file_format.get('abr'),
53 return formats
56 class KuwoIE(KuwoBaseIE):
57 _WORKING = False
58 IE_NAME = 'kuwo:song'
59 IE_DESC = '酷我音乐'
60 _VALID_URL = r'https?://(?:www\.)?kuwo\.cn/yinyue/(?P<id>\d+)'
61 _TESTS = [{
62 'url': 'http://www.kuwo.cn/yinyue/635632/',
63 'info_dict': {
64 'id': '635632',
65 'ext': 'ape',
66 'title': '爱我别走',
67 'creator': '张震岳',
68 'upload_date': '20080122',
69 'description': 'md5:ed13f58e3c3bf3f7fd9fbc4e5a7aa75c'
71 'skip': 'this song has been offline because of copyright issues',
72 }, {
73 'url': 'http://www.kuwo.cn/yinyue/6446136/',
74 'info_dict': {
75 'id': '6446136',
76 'ext': 'mp3',
77 'title': '心',
78 'description': 'md5:5d0e947b242c35dc0eb1d2fce9fbf02c',
79 'creator': 'IU',
80 'upload_date': '20150518',
82 'params': {
83 'format': 'mp3-320',
85 }, {
86 'url': 'http://www.kuwo.cn/yinyue/3197154?catalog=yueku2016',
87 'only_matching': True,
90 def _real_extract(self, url):
91 song_id = self._match_id(url)
92 webpage, urlh = self._download_webpage_handle(
93 url, song_id, note='Download song detail info',
94 errnote='Unable to get song detail info')
95 if song_id not in urlh.url or '对不起,该歌曲由于版权问题已被下线,将返回网站首页' in webpage:
96 raise ExtractorError('this song has been offline because of copyright issues', expected=True)
98 song_name = self._html_search_regex(
99 r'<p[^>]+id="lrcName">([^<]+)</p>', webpage, 'song name')
100 singer_name = remove_start(self._html_search_regex(
101 r'<a[^>]+href="http://www\.kuwo\.cn/artist/content\?name=([^"]+)">',
102 webpage, 'singer name', fatal=False), '歌手')
103 lrc_content = clean_html(get_element_by_id('lrcContent', webpage))
104 if lrc_content == '暂无': # indicates no lyrics
105 lrc_content = None
107 formats = self._get_formats(song_id)
109 album_id = self._html_search_regex(
110 r'<a[^>]+href="http://www\.kuwo\.cn/album/(\d+)/"',
111 webpage, 'album id', fatal=False)
113 publish_time = None
114 if album_id is not None:
115 album_info_page = self._download_webpage(
116 'http://www.kuwo.cn/album/%s/' % album_id, song_id,
117 note='Download album detail info',
118 errnote='Unable to get album detail info')
120 publish_time = self._html_search_regex(
121 r'发行时间:(\d{4}-\d{2}-\d{2})', album_info_page,
122 'publish time', fatal=False)
123 if publish_time:
124 publish_time = publish_time.replace('-', '')
126 return {
127 'id': song_id,
128 'title': song_name,
129 'creator': singer_name,
130 'upload_date': publish_time,
131 'description': lrc_content,
132 'formats': formats,
136 class KuwoAlbumIE(InfoExtractor):
137 _WORKING = False
138 IE_NAME = 'kuwo:album'
139 IE_DESC = '酷我音乐 - 专辑'
140 _VALID_URL = r'https?://(?:www\.)?kuwo\.cn/album/(?P<id>\d+?)/'
141 _TEST = {
142 'url': 'http://www.kuwo.cn/album/502294/',
143 'info_dict': {
144 'id': '502294',
145 'title': 'Made\xa0Series\xa0《M》',
146 'description': 'md5:d463f0d8a0ff3c3ea3d6ed7452a9483f',
148 'playlist_count': 2,
151 def _real_extract(self, url):
152 album_id = self._match_id(url)
154 webpage = self._download_webpage(
155 url, album_id, note='Download album info',
156 errnote='Unable to get album info')
158 album_name = self._html_search_regex(
159 r'<div[^>]+class="comm"[^<]+<h1[^>]+title="([^"]+)"', webpage,
160 'album name')
161 album_intro = remove_start(
162 clean_html(get_element_by_id('intro', webpage)),
163 '%s简介:' % album_name)
165 entries = [
166 self.url_result(song_url, 'Kuwo') for song_url in re.findall(
167 r'<p[^>]+class="listen"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+/)"',
168 webpage)
170 return self.playlist_result(entries, album_id, album_name, album_intro)
173 class KuwoChartIE(InfoExtractor):
174 _WORKING = False
175 IE_NAME = 'kuwo:chart'
176 IE_DESC = '酷我音乐 - 排行榜'
177 _VALID_URL = r'https?://yinyue\.kuwo\.cn/billboard_(?P<id>[^.]+).htm'
178 _TEST = {
179 'url': 'http://yinyue.kuwo.cn/billboard_香港中文龙虎榜.htm',
180 'info_dict': {
181 'id': '香港中文龙虎榜',
183 'playlist_mincount': 7,
186 def _real_extract(self, url):
187 chart_id = self._match_id(url)
188 webpage = self._download_webpage(
189 url, chart_id, note='Download chart info',
190 errnote='Unable to get chart info')
192 entries = [
193 self.url_result(song_url, 'Kuwo') for song_url in re.findall(
194 r'<a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+)', webpage)
196 return self.playlist_result(entries, chart_id)
199 class KuwoSingerIE(InfoExtractor):
200 _WORKING = False
201 IE_NAME = 'kuwo:singer'
202 IE_DESC = '酷我音乐 - 歌手'
203 _VALID_URL = r'https?://(?:www\.)?kuwo\.cn/mingxing/(?P<id>[^/]+)'
204 _TESTS = [{
205 'url': 'http://www.kuwo.cn/mingxing/bruno+mars/',
206 'info_dict': {
207 'id': 'bruno+mars',
208 'title': 'Bruno\xa0Mars',
210 'playlist_mincount': 329,
211 }, {
212 'url': 'http://www.kuwo.cn/mingxing/Ali/music.htm',
213 'info_dict': {
214 'id': 'Ali',
215 'title': 'Ali',
217 'playlist_mincount': 95,
218 'skip': 'Regularly stalls travis build', # See https://travis-ci.org/ytdl-org/youtube-dl/jobs/78878540
221 PAGE_SIZE = 15
223 def _real_extract(self, url):
224 singer_id = self._match_id(url)
225 webpage = self._download_webpage(
226 url, singer_id, note='Download singer info',
227 errnote='Unable to get singer info')
229 singer_name = self._html_search_regex(
230 r'<h1>([^<]+)</h1>', webpage, 'singer name')
232 artist_id = self._html_search_regex(
233 r'data-artistid="(\d+)"', webpage, 'artist id')
235 page_count = int(self._html_search_regex(
236 r'data-page="(\d+)"', webpage, 'page count'))
238 def page_func(page_num):
239 webpage = self._download_webpage(
240 'http://www.kuwo.cn/artist/contentMusicsAjax',
241 singer_id, note='Download song list page #%d' % (page_num + 1),
242 errnote='Unable to get song list page #%d' % (page_num + 1),
243 query={'artistId': artist_id, 'pn': page_num, 'rn': self.PAGE_SIZE})
245 return [
246 self.url_result(compat_urlparse.urljoin(url, song_url), 'Kuwo')
247 for song_url in re.findall(
248 r'<div[^>]+class="name"><a[^>]+href="(/yinyue/\d+)',
249 webpage)
252 entries = InAdvancePagedList(page_func, page_count, self.PAGE_SIZE)
254 return self.playlist_result(entries, singer_id, singer_name)
257 class KuwoCategoryIE(InfoExtractor):
258 _WORKING = False
259 IE_NAME = 'kuwo:category'
260 IE_DESC = '酷我音乐 - 分类'
261 _VALID_URL = r'https?://yinyue\.kuwo\.cn/yy/cinfo_(?P<id>\d+?).htm'
262 _TEST = {
263 'url': 'http://yinyue.kuwo.cn/yy/cinfo_86375.htm',
264 'info_dict': {
265 'id': '86375',
266 'title': '八十年代精选',
267 'description': '这些都是属于八十年代的回忆!',
269 'playlist_mincount': 24,
272 def _real_extract(self, url):
273 category_id = self._match_id(url)
274 webpage = self._download_webpage(
275 url, category_id, note='Download category info',
276 errnote='Unable to get category info')
278 category_name = self._html_search_regex(
279 r'<h1[^>]+title="([^<>]+?)">[^<>]+?</h1>', webpage, 'category name')
281 category_desc = remove_start(
282 get_element_by_id('intro', webpage).strip(),
283 '%s简介:' % category_name)
284 if category_desc == '暂无':
285 category_desc = None
287 jsonm = self._parse_json(self._html_search_regex(
288 r'var\s+jsonm\s*=\s*([^;]+);', webpage, 'category songs'), category_id)
290 entries = [
291 self.url_result('http://www.kuwo.cn/yinyue/%s/' % song['musicrid'], 'Kuwo')
292 for song in jsonm['musiclist']
294 return self.playlist_result(entries, category_id, category_name, category_desc)
297 class KuwoMvIE(KuwoBaseIE):
298 _WORKING = False
299 IE_NAME = 'kuwo:mv'
300 IE_DESC = '酷我音乐 - MV'
301 _VALID_URL = r'https?://(?:www\.)?kuwo\.cn/mv/(?P<id>\d+?)/'
302 _TEST = {
303 'url': 'http://www.kuwo.cn/mv/6480076/',
304 'info_dict': {
305 'id': '6480076',
306 'ext': 'mp4',
307 'title': 'My HouseMV',
308 'creator': '2PM',
310 # In this video, music URLs (anti.s) are blocked outside China and
311 # USA, while the MV URL (mvurl) is available globally, so force the MV
312 # URL for consistent results in different countries
313 'params': {
314 'format': 'mv',
317 _FORMATS = KuwoBaseIE._FORMATS + [
318 {'format': 'mkv', 'ext': 'mkv', 'preference': 250},
319 {'format': 'mp4', 'ext': 'mp4', 'preference': 200},
322 def _real_extract(self, url):
323 song_id = self._match_id(url)
324 webpage = self._download_webpage(
325 url, song_id, note='Download mv detail info: %s' % song_id,
326 errnote='Unable to get mv detail info: %s' % song_id)
328 mobj = re.search(
329 r'<h1[^>]+title="(?P<song>[^"]+)">[^<]+<span[^>]+title="(?P<singer>[^"]+)"',
330 webpage)
331 if mobj:
332 song_name = mobj.group('song')
333 singer_name = mobj.group('singer')
334 else:
335 raise ExtractorError('Unable to find song or singer names')
337 formats = self._get_formats(song_id, tolerate_ip_deny=True)
339 mv_url = self._download_webpage(
340 'http://www.kuwo.cn/yy/st/mvurl?rid=MUSIC_%s' % song_id,
341 song_id, note='Download %s MV URL' % song_id)
342 formats.append({
343 'url': mv_url,
344 'format_id': 'mv',
347 return {
348 'id': song_id,
349 'title': song_name,
350 'creator': singer_name,
351 'formats': formats,