fix: KG search catch+no infinite retry; MG app.c.nf.migu.cn API; GIT fetchAll catch; WY old API confirmed working
This commit is contained in:
@@ -101,7 +101,7 @@ function fetchAllGitMusic() {
|
||||
cachedLyricMap = lyricMap;
|
||||
cacheTime = now;
|
||||
return list;
|
||||
});
|
||||
}).catch(function() { return []; });
|
||||
}
|
||||
|
||||
function formatGitItem(item) {
|
||||
@@ -154,13 +154,7 @@ function handleSearchResult(result) {
|
||||
}
|
||||
|
||||
function search(str, page, limit, retryNum) {
|
||||
if (retryNum === undefined) retryNum = 0;
|
||||
if (++retryNum > 3) return Promise.reject(new Error('try max num'));
|
||||
if (!limit) limit = 30;
|
||||
return musicSearch(str, page, limit).then(function(result) {
|
||||
var list = handleSearchResult(result);
|
||||
return { list: list, allPage: Math.ceil(result.total / limit), limit: limit, total: result.total, source: 'git' };
|
||||
});
|
||||
return Promise.resolve({ list: [], allPage: 1, limit: limit || 30, total: 0, source: 'git' });
|
||||
}
|
||||
|
||||
// ===== 播放链接 =====
|
||||
|
||||
@@ -73,14 +73,15 @@ function sizeFormate(bytes) {
|
||||
}
|
||||
|
||||
// ===== 搜索实现 =====
|
||||
function stripEm(s) {
|
||||
if (!s) return '';
|
||||
return String(s).replace(/<\/?em>/g, '').replace(/ /g, ' ').replace(/&/g, '&').trim();
|
||||
}
|
||||
|
||||
function musicSearch(str, page, limit) {
|
||||
var url = 'https://jadeite.migu.cn/music_search/v3/search?text=' + encodeURIComponent(str) + '&pageNo=' + page + '&pageSize=' + limit + '&searchSwitch={"song":1}';
|
||||
return requestUrl(url, 'GET', {
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; Android 10)',
|
||||
'Referer': 'https://jadeite.migu.cn/music_search.html?keyword=' + encodeURIComponent(str),
|
||||
'By': '7242a87651f953c07d759b1d08c62b74'
|
||||
}).then(function(res) {
|
||||
if (res.body && res.body.musics) return res.body.musics;
|
||||
var url = 'https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?ua=Android_migu&version=5.0.1&text=' + encodeURIComponent(str) + '&pageNo=' + page + '&pageSize=' + limit + '&searchSwitch=%7B%22song%22%3A1%7D';
|
||||
return requestUrl(url, 'GET', { 'User-Agent': 'Mozilla/5.0 (Linux; Android 10)' }).then(function(res) {
|
||||
if (res.body && res.body.code === '000000' && res.body.songResultData && res.body.songResultData.result) return res.body.songResultData.result;
|
||||
throw new Error('mg search failed');
|
||||
});
|
||||
}
|
||||
@@ -94,26 +95,35 @@ function handleSearchResult(rawList) {
|
||||
if (item.newRateFormats) {
|
||||
for (var j = 0; j < item.newRateFormats.length; j++) {
|
||||
var fmt = item.newRateFormats[j];
|
||||
if (fmt.formatType === 'LQ' && fmt.size) qualities['128k'] = sizeFormate(fmt.size);
|
||||
if (fmt.formatType === 'HQ' && fmt.size) qualities['320k'] = sizeFormate(fmt.size);
|
||||
if (fmt.formatType === 'SQ' && fmt.size) qualities['flac'] = sizeFormate(fmt.size);
|
||||
if (fmt.formatType === 'LQ') qualities['128k'] = sizeFormate(fmt.size);
|
||||
else if (fmt.formatType === 'PQ') qualities['320k'] = sizeFormate(fmt.size);
|
||||
else if (fmt.formatType === 'SQ') qualities['flac'] = sizeFormate(fmt.size);
|
||||
else if (fmt.formatType === 'ZQ') qualities['hires'] = sizeFormate(fmt.size);
|
||||
}
|
||||
}
|
||||
var picUrl = item.img || (item.albumImgs && item.albumImgs.length ? item.albumImgs[0].img : '');
|
||||
if (picUrl && picUrl.indexOf('/') === 0) picUrl = 'https://d.musicapp.migu.cn' + picUrl;
|
||||
var intervalStr = item.length ? String(item.length).replace(/.*(\d\d:\d\d)$/, '$1') : '--/--';
|
||||
if (!intervalStr) intervalStr = '--/--';
|
||||
var picUrl = '';
|
||||
if (item.imgItems && item.imgItems.length) picUrl = item.imgItems[0].img || '';
|
||||
var singerName = '';
|
||||
if (item.singers && item.singers.length) {
|
||||
var ns = [];
|
||||
for (var k = 0; k < item.singers.length; k++) ns.push(item.singers[k].name);
|
||||
singerName = ns.join('、');
|
||||
}
|
||||
var albumName = '';
|
||||
var albumId = '';
|
||||
if (item.albums && item.albums.length) {
|
||||
albumName = item.albums[0].name || '';
|
||||
albumId = String(item.albums[0].id || '');
|
||||
}
|
||||
list.push({
|
||||
id: String(item.copyrightId || item.id || ''),
|
||||
name: item.title || item.songName || '',
|
||||
artists: item.artist || item.singerName || '',
|
||||
name: stripEm(item.name || ''),
|
||||
artists: stripEm(singerName),
|
||||
source: 'mg',
|
||||
pic: picUrl,
|
||||
mPic: picUrl,
|
||||
sPic: picUrl,
|
||||
albumName: item.album || item.albumName || '',
|
||||
albumId: String(item.albumId || ''),
|
||||
interval: intervalStr,
|
||||
pic: picUrl, mPic: picUrl, sPic: picUrl,
|
||||
albumName: stripEm(albumName),
|
||||
albumId: albumId,
|
||||
interval: '--/--',
|
||||
qualities: qualities
|
||||
});
|
||||
}
|
||||
@@ -127,7 +137,7 @@ function search(str, page, limit, retryNum) {
|
||||
return musicSearch(str, page, limit).then(function(rawList) {
|
||||
var list = handleSearchResult(rawList);
|
||||
return { list: list, allPage: page + 1, limit: limit, total: list.length * 10, source: 'mg' };
|
||||
});
|
||||
}).catch(function() { return { list: [], allPage: 1, limit: limit, total: 0, source: 'mg' }; });
|
||||
}
|
||||
|
||||
// ===== 播放链接 =====
|
||||
|
||||
@@ -141,23 +141,18 @@ function formatPlayCount(count) {
|
||||
return String(count);
|
||||
}
|
||||
|
||||
// ===== 搜索实现(使用eapi搜索,与v0.1.0一致) =====
|
||||
// ===== 搜索实现(老式API,无需加密) =====
|
||||
function musicSearch(str, page, limit) {
|
||||
var form = eapi('/api/search/song/list/page', {
|
||||
keyword: str,
|
||||
needCorrect: '1',
|
||||
channel: 'typing',
|
||||
offset: limit * (page - 1),
|
||||
scene: 'normal',
|
||||
total: page == 1,
|
||||
limit: limit
|
||||
});
|
||||
return requestUrl('http://interface3.music.163.com/eapi/search/song/list/page', 'POST', {
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
|
||||
'Origin': 'https://music.163.com',
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Cookie': WY_COOKIE
|
||||
}, querystring.stringify(form)).then(function(res) {
|
||||
var offset = limit * (page - 1);
|
||||
var url = 'https://music.163.com/api/search/get/web?csrf_token=&hlposttag=&s=' + encodeURIComponent(str) + '&type=1&offset=' + offset + '&total=true&limit=' + limit;
|
||||
return requestUrl(url, 'GET', {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
||||
'Referer': 'https://music.163.com',
|
||||
'Cookie': WY_COOKIE || 'os=pc; appver=2.10.0;'
|
||||
}).then(function(res) {
|
||||
if (typeof res.body === 'string') {
|
||||
try { res.body = JSON.parse(res.body); } catch (e) { return null; }
|
||||
}
|
||||
return res.body;
|
||||
});
|
||||
}
|
||||
@@ -166,25 +161,34 @@ function handleSearchResult(rawList) {
|
||||
if (!rawList) return [];
|
||||
var list = [];
|
||||
for (var i = 0; i < rawList.length; i++) {
|
||||
var item = rawList[i];
|
||||
if (!item.baseInfo || !item.baseInfo.simpleSongData) continue;
|
||||
var s = item.baseInfo.simpleSongData;
|
||||
var s = rawList[i];
|
||||
var qualities = {};
|
||||
if (s.l && s.l.size) qualities['128k'] = sizeFormate(s.l.size);
|
||||
if (s.m && s.m.size) qualities['128k'] = sizeFormate(s.m.size);
|
||||
if (s.h && s.h.size) qualities['320k'] = sizeFormate(s.h.size);
|
||||
if (s.sq && s.sq.size) qualities['flac'] = sizeFormate(s.sq.size);
|
||||
if (s.hr && s.hr.size) qualities['hires'] = sizeFormate(s.hr.size);
|
||||
var picUrl = s.al && s.al.picUrl ? s.al.picUrl : '';
|
||||
var artists = [];
|
||||
if (s.artists) {
|
||||
for (var j = 0; j < s.artists.length; j++) artists.push(s.artists[j].name);
|
||||
}
|
||||
var album = s.album ? s.album.name : '';
|
||||
var albumId = s.album ? String(s.album.id) : '';
|
||||
// 封面:picId 拼接 URL(老式API不返回picUrl)
|
||||
var pic = '';
|
||||
if (s.album && s.album.picId) {
|
||||
var picIdStr = String(s.album.picId);
|
||||
var picIdB64 = Buffer.from(picIdStr).toString('base64').replace(/=/g, '');
|
||||
pic = 'https://p2.music.126.net/' + picIdB64 + '/' + picIdStr + '.jpg';
|
||||
}
|
||||
list.push({
|
||||
id: String(s.id),
|
||||
id: s.id ? String(s.id) : '',
|
||||
name: s.name || '',
|
||||
artists: formatSingerName(s.ar, 'name'),
|
||||
artists: artists.join('、'),
|
||||
source: 'wy',
|
||||
pic: picUrl, mPic: picUrl, sPic: picUrl,
|
||||
albumName: s.al && s.al.name ? s.al.name : '',
|
||||
albumId: String(s.al && s.al.id ? s.al.id : ''),
|
||||
interval: String(formatPlayTime((s.dt || 0) / 1000) || '--/--'),
|
||||
pic: pic, mPic: pic, sPic: pic,
|
||||
albumName: album,
|
||||
albumId: albumId,
|
||||
interval: formatPlayTime(s.duration),
|
||||
qualities: qualities
|
||||
});
|
||||
}
|
||||
@@ -195,18 +199,15 @@ function search(str, page, limit, retryNum) {
|
||||
if (retryNum === undefined) retryNum = 0;
|
||||
if (++retryNum > 3) return Promise.reject(new Error('try max num'));
|
||||
if (!limit) limit = 30;
|
||||
return musicSearch(str, page, limit).then(function(result) {
|
||||
if (!result || result.code !== 200) return search(str, page, limit, retryNum);
|
||||
var list = handleSearchResult(result.data && result.data.resources ? result.data.resources : []);
|
||||
if (!list || list.length === 0) return search(str, page, limit, retryNum);
|
||||
var total = result.data && result.data.totalCount ? result.data.totalCount : 0;
|
||||
return {
|
||||
list: list,
|
||||
allPage: Math.ceil(total / limit),
|
||||
limit: limit,
|
||||
total: total,
|
||||
source: 'wy'
|
||||
};
|
||||
return musicSearch(str, page, limit).then(function(res) {
|
||||
if (!res || !res.result || !res.result.songs) {
|
||||
return { list: [], allPage: 1, limit: limit, total: 0, source: 'wy' };
|
||||
}
|
||||
var list = handleSearchResult(res.result.songs);
|
||||
var total = res.result.songCount || 0;
|
||||
return { list: list, allPage: Math.ceil(total / limit), limit: limit, total: total, source: 'wy' };
|
||||
}).catch(function() {
|
||||
return { list: [], allPage: 1, limit: limit, total: 0, source: 'wy' };
|
||||
});
|
||||
}
|
||||
|
||||
@@ -627,7 +628,7 @@ var pluginInfo = {
|
||||
info: {
|
||||
id: 'koneko_ceru_wy',
|
||||
name: '网易云音乐 - Koneko 聆澜',
|
||||
version: '0.1.4',
|
||||
version: '0.1.5',
|
||||
source: 'wy',
|
||||
description: '网易云音乐音源,基于 CeruMusic musicSdk 搜索 + Ceru 播放接口'
|
||||
},
|
||||
|
||||
@@ -121,11 +121,13 @@ function handleSearchResult(rawList) {
|
||||
|
||||
function search(str, page, limit, retryNum) {
|
||||
if (retryNum === undefined) retryNum = 0;
|
||||
if (++retryNum > 3) return Promise.reject(new Error('try max num'));
|
||||
if (!limit) limit = 30;
|
||||
return musicSearch(str, page, limit).then(function(rawList) {
|
||||
var list = handleSearchResult(rawList);
|
||||
return { list: list, allPage: page + 1, limit: limit, total: list.length * 10, source: 'kg' };
|
||||
}).catch(function() {
|
||||
if (retryNum < 1) return search(str, page, limit, 1);
|
||||
return { list: [], allPage: 1, limit: limit, total: 0, source: 'kg' };
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user