From b019b0e296d160a37690fec7239a7347842cf9c0 Mon Sep 17 00:00:00 2001 From: TRAE Bot Date: Sun, 5 Jul 2026 22:24:42 +0000 Subject: [PATCH] fix(kg,kw): restore old search API params + field parsing from v0.0.6, fix cover and quality --- 聆澜/Koneko_聆澜_酷我音乐_v0.1.4_QZv2.js | 59 ++++++++++++++---------- 聆澜/Koneko_聆澜_酷狗音乐_v0.1.4_QZv2.js | 23 ++++----- 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/聆澜/Koneko_聆澜_酷我音乐_v0.1.4_QZv2.js b/聆澜/Koneko_聆澜_酷我音乐_v0.1.4_QZv2.js index 54b72c0..b47d63d 100644 --- a/聆澜/Koneko_聆澜_酷我音乐_v0.1.4_QZv2.js +++ b/聆澜/Koneko_聆澜_酷我音乐_v0.1.4_QZv2.js @@ -79,8 +79,7 @@ function stripEm(s) { } function musicSearch(str, page, limit) { - var pn = (page - 1) * limit; - var url = 'http://search.kuwo.cn/r.s?all=' + encodeURIComponent(str) + '&ft=music&itemset=1&rformat=json&encoding=utf8&pn=' + pn + '&rn=' + limit; + var url = 'http://search.kuwo.cn/r.s?client=kt&all=' + encodeURIComponent(str) + '&pn=' + (page - 1) + '&rn=' + limit + '&uid=794762570&ver=kwplayer_ar_9.2.2.1&vipver=1&show_copyright_off=1&newver=1&ft=music&cluster=0&strategy=2012&encoding=utf8&rformat=json&vermerge=1&mobi=1&issubtitle=1'; return requestUrl(url, 'GET', { 'User-Agent': 'Mozilla/5.0 (Linux; Android 10)', 'Referer': 'http://www.kuwo.cn/' @@ -98,34 +97,44 @@ function handleSearchResult(rawList) { var list = []; if (!rawList) return list; for (var i = 0; i < rawList.length; i++) { - var item = rawList[i]; - var rid = ''; - if (item.MUSICRID) rid = String(item.MUSICRID).replace('MUSIC_', ''); - else if (item.DC_TARGETID) rid = String(item.DC_TARGETID); - else rid = String(item.rid || item.id || ''); + var info = rawList[i]; + var songId = (info.MUSICRID || '').replace('MUSIC_', ''); + if (!songId) songId = String(info.DC_TARGETID || info.rid || info.id || ''); + // 音质:从 N_MINFO 解析 var qualities = {}; - var formats = String(item.FORMATS || ''); - var minfo = String(item.MINFO || ''); - if (formats.indexOf('MP3128') !== -1 || minfo.indexOf('bitrate:128') !== -1) qualities['128k'] = ''; - if (formats.indexOf('MP3H') !== -1 || minfo.indexOf('bitrate:320') !== -1) qualities['320k'] = ''; - if (formats.indexOf('ALFLAC') !== -1 || minfo.indexOf('format:flac') !== -1) qualities['flac'] = ''; - var name = stripEm(item.SONGNAME || item.NAME || ''); - var artist = stripEm(item.ARTIST || ''); - var albumName = stripEm(item.ALBUM || ''); - var picUrl = item.web_albumpic_short || item.albumpic || item.ALBUMPIC || ''; - if (picUrl && picUrl.indexOf('http') !== 0 && picUrl.length > 2) picUrl = 'http://img1.kuwo.cn/star/albumcover/' + picUrl; - var duration = parseInt(item.DURATION || '0', 10); + if (info.N_MINFO) { + var parts = String(info.N_MINFO).split(';'); + for (var j = 0; j < parts.length; j++) { + var m = parts[j].match(/level:(\w+),bitrate:(\d+),format:(\w+),size:([\w.]+)/); + if (m) { + if (m[2] === '20900') qualities['master'] = m[4]; + else if (m[2] === '4000') qualities['hires'] = m[4]; + else if (m[2] === '2000') qualities['flac'] = m[4]; + else if (m[2] === '320') qualities['320k'] = m[4]; + else if (m[2] === '128') qualities['128k'] = m[4]; + } + } + } + // 封面:用 ALBUMID 拼 kuwo 封面 URL + var picUrl = ''; + if (info.ALBUMID) { + picUrl = 'https://img2.kuwo.cn/star/albumcover/300/' + info.ALBUMID + '.jpg'; + } else { + picUrl = 'http://artistpicserver.kuwo.cn/pic.web?corp=kuwo&type=rid_pic&pictype=500&size=500&rid=' + songId; + } + var artistStr = stripEm(info.ARTIST || '').replace(/&/g, '、'); + var duration = parseInt(info.DURATION || '0', 10); list.push({ - id: rid, - name: name, - artists: artist, + id: String(songId), + name: stripEm(info.SONGNAME || ''), + artists: artistStr, source: 'kw', pic: picUrl, mPic: picUrl, sPic: picUrl, - albumName: albumName, - albumId: String(item.ALBUMID || ''), - interval: String(formatPlayTime(duration) || '--/--'), + albumName: stripEm(info.ALBUM || ''), + albumId: String(info.ALBUMID || ''), + interval: isNaN(duration) ? '--/--' : String(formatPlayTime(duration) || '--/--'), qualities: qualities }); } @@ -141,7 +150,7 @@ function search(str, page, limit, retryNum) { var total = parseInt(data.TOTAL || '0', 10) || rawList.length * 10; var list = handleSearchResult(rawList); return { list: list, allPage: Math.ceil(total / limit), limit: limit, total: total, source: 'kw' }; - }); + }).catch(function() { return { list: [], allPage: 1, limit: limit, total: 0, source: 'kw' }; }); } // ===== 播放链接 ===== diff --git a/聆澜/Koneko_聆澜_酷狗音乐_v0.1.4_QZv2.js b/聆澜/Koneko_聆澜_酷狗音乐_v0.1.4_QZv2.js index 1b803ec..9e31ece 100644 --- a/聆澜/Koneko_聆澜_酷狗音乐_v0.1.4_QZv2.js +++ b/聆澜/Koneko_聆澜_酷狗音乐_v0.1.4_QZv2.js @@ -79,7 +79,7 @@ function stripEm(s) { } function musicSearch(str, page, limit) { - var url = 'http://mobilecdn.kugou.com/api/v3/search/song?showtype=14&highlight=&pagesize=' + limit + '&page=' + page + '&keyword=' + encodeURIComponent(str); + var url = 'http://mobilecdn.kugou.com/api/v3/search/song?format=json&keyword=' + encodeURIComponent(str) + '&page=' + page + '&pagesize=' + limit; return requestUrl(url, 'GET', { 'User-Agent': 'Mozilla/5.0 (Linux; Android 10)' }).then(function(res) { if (res.body && res.body.data && res.body.data.info) return res.body.data; throw new Error('kg search failed'); @@ -95,27 +95,24 @@ function handleSearchResult(rawList) { if (item.filesize) qualities['128k'] = sizeFormate(item.filesize); if (item['320filesize']) qualities['320k'] = sizeFormate(item['320filesize']); if (item.sqfilesize) qualities['flac'] = sizeFormate(item.sqfilesize); - // 封面:用 album_id 拼 kugou 封面 URL - var albumId = String(item.album_id || ''); + // 封面:优先 imgurl(带 {size} 占位符),其次 album_img,再次 union_cover var picUrl = ''; - if (albumId) picUrl = 'http://imge.kugou.com/stdmusic/150/' + albumId + '.jpg'; - var name = stripEm(item.songname || item.filename || ''); - var singerName = stripEm(item.singername || ''); - // filename 格式 "歌手 - 歌名",如果没有 songname 就从 filename 拆 - if (!name && item.filename) { - var parts = String(item.filename).split(' - '); - name = stripEm(parts[1] || parts[0]); + if (item.imgurl && typeof item.imgurl === 'string') { + picUrl = item.imgurl.replace('{size}', '400'); + if (picUrl && picUrl.indexOf('http') !== 0 && picUrl.indexOf('https') !== 0) picUrl = 'https://' + picUrl; } + if (!picUrl && item.album_img) picUrl = item.album_img; + if (!picUrl && item.trans_param && item.trans_param.union_cover) picUrl = item.trans_param.union_cover; list.push({ id: String(item.hash || ''), - name: name, - artists: singerName, + name: stripEm(item.songname || item.song_name || item.filename || ''), + artists: stripEm(item.singername || item.singer_name || ''), source: 'kg', pic: picUrl, mPic: picUrl, sPic: picUrl, albumName: stripEm(item.album_name || ''), - albumId: albumId, + albumId: String(item.album_id || ''), interval: String(formatPlayTime(item.duration) || '--/--'), qualities: qualities });