fix(kg): use http + fallback for search, fix cover field Image with {size} replace

This commit is contained in:
TRAE Bot
2026-07-05 18:45:49 +00:00
parent 85bb259e36
commit 89d0c1557c

View File

@@ -79,10 +79,29 @@ function stripEm(s) {
}
function musicSearch(str, page, limit) {
var url = 'https://songsearch.kugou.com/song_search_v2?keyword=' + encodeURIComponent(str) + '&page=' + page + '&pagesize=' + limit + '&showtype=10&utf8=1';
var url = 'http://songsearch.kugou.com/song_search_v2?keyword=' + encodeURIComponent(str) + '&page=' + page + '&pagesize=' + limit + '&showtype=10&utf8=1';
return requestUrl(url, 'GET', { 'User-Agent': 'Mozilla/5.0 (Linux; Android 10)' }).then(function(res) {
if (res.body && res.body.data && res.body.data.lists) return res.body.data;
throw new Error('kg search failed');
// fallback to mobilecdn http
var url2 = 'http://mobilecdn.kugou.com/api/v3/search/song?showtype=14&pagesize=' + limit + '&page=' + page + '&keyword=' + encodeURIComponent(str);
return requestUrl(url2, 'GET', { 'User-Agent': 'Mozilla/5.0 (Linux; Android 10)' }).then(function(res2) {
if (res2.body && res2.body.data && res2.body.data.info) {
// map mobilecdn format to songsearch format
var info = res2.body.data.info;
var mapped = [];
for (var i = 0; i < info.length; i++) {
var it = info[i];
mapped.push({
FileName: it.songname, SingerName: it.singername, AlbumName: it.album_name,
AlbumID: it.album_id, FileHash: it.hash, Image: it.img,
FileSize: it.filesize, HQFileSize: it.sqfilesize, SQFileSize: it.flacfilesize,
Duration: it.duration
});
}
return { lists: mapped, total: res2.body.data.total || mapped.length * 10 };
}
throw new Error('kg search failed');
});
});
}
@@ -95,7 +114,8 @@ function handleSearchResult(rawList) {
if (item.FileSize) qualities['128k'] = sizeFormate(item.FileSize);
if (item.HQFileSize) qualities['320k'] = sizeFormate(item.HQFileSize);
if (item.SQFileSize) qualities['flac'] = sizeFormate(item.SQFileSize);
var picUrl = item.AblumPic || '';
var picUrl = item.Image || item.AblumPic || item.AlbumImage || '';
if (picUrl) picUrl = picUrl.replace('{size}', '480');
if (picUrl && picUrl.indexOf('http') !== 0) picUrl = 'https://' + picUrl.replace(/^\/+/, '');
var name = stripEm(item.FileName || item.SongName || '');
var singerName = stripEm(item.SingerName || '');