From 03af3be7cde3defbc18e28b14d51a677266cf97d Mon Sep 17 00:00:00 2001 From: Folltoshe Date: Thu, 13 Apr 2023 00:01:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/utils/musicSdk/mg/lyric.js | 2 +- src/renderer/utils/musicSdk/mg/musicSearch.js | 93 +++++++++++- .../utils/musicSdk/mg/musicSearchOld.js | 134 ------------------ 3 files changed, 93 insertions(+), 136 deletions(-) delete mode 100644 src/renderer/utils/musicSdk/mg/musicSearchOld.js diff --git a/src/renderer/utils/musicSdk/mg/lyric.js b/src/renderer/utils/musicSdk/mg/lyric.js index e00cc2c5..7a211944 100644 --- a/src/renderer/utils/musicSdk/mg/lyric.js +++ b/src/renderer/utils/musicSdk/mg/lyric.js @@ -1,5 +1,5 @@ import { httpFetch } from '../../request' -import musicSearch from './musicSearchOld' +import musicSearch from './musicSearch' import { decrypt } from './mrc' const mrcTools = { diff --git a/src/renderer/utils/musicSdk/mg/musicSearch.js b/src/renderer/utils/musicSdk/mg/musicSearch.js index cc4e2344..cee4f57f 100644 --- a/src/renderer/utils/musicSdk/mg/musicSearch.js +++ b/src/renderer/utils/musicSdk/mg/musicSearch.js @@ -7,6 +7,98 @@ export default { total: 0, page: 0, allPage: 1, + + // 旧版API + // musicSearch(str, page, limit) { + // const searchRequest = httpFetch(`http://pd.musicapp.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%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A0%2C%22mvSong%22%3A0%2C%22songlist%22%3A0%2C%22bestShow%22%3A1%7D`, { + // // searchRequest = httpFetch(`http://jadeite.migu.cn:7090/music_search/v2/search/searchAll?sid=4f87090d01c84984a11976b828e2b02c18946be88a6b4c47bcdc92fbd40762db&isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, { + // headers: { + // // sign: 'c3b7ae985e2206e97f1b2de8f88691e2', + // // timestamp: 1578225871982, + // // appId: 'yyapp2', + // // mode: 'android', + // // ua: 'Android_migu', + // // version: '6.9.4', + // osVersion: 'android 7.0', + // 'User-Agent': 'okhttp/3.9.1', + // }, + // }) + // // searchRequest = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${limit}&searchSwitch={%22song%22:1,%22album%22:0,%22singer%22:0,%22tagSong%22:0,%22mvSong%22:0,%22songlist%22:0,%22bestShow%22:0}&sort=0&text=${encodeURIComponent(str)}`) + // return searchRequest.promise.then(({ body }) => body) + // }, + // handleResult(rawData) { + // // console.log(rawData) + // let ids = new Set() + // const list = [] + // rawData.forEach(item => { + // if (ids.has(item.id)) return + // ids.add(item.id) + // const types = [] + // const _types = {} + // item.newRateFormats && item.newRateFormats.forEach(type => { + // let size + // switch (type.formatType) { + // case 'PQ': + // size = sizeFormate(type.size ?? type.androidSize) + // types.push({ type: '128k', size }) + // _types['128k'] = { + // size, + // } + // break + // case 'HQ': + // size = sizeFormate(type.size ?? type.androidSize) + // types.push({ type: '320k', size }) + // _types['320k'] = { + // size, + // } + // break + // case 'SQ': + // size = sizeFormate(type.size ?? type.androidSize) + // types.push({ type: 'flac', size }) + // _types.flac = { + // size, + // } + // break + // case 'ZQ': + // size = sizeFormate(type.size ?? type.androidSize) + // types.push({ type: 'flac24bit', size }) + // _types.flac24bit = { + // size, + // } + // break + // } + // }) + + // const albumNInfo = item.albums && item.albums.length + // ? { + // id: item.albums[0].id, + // name: item.albums[0].name, + // } + // : {} + + // list.push({ + // singer: this.getSinger(item.singers), + // name: item.name, + // albumName: albumNInfo.name, + // albumId: albumNInfo.id, + // songmid: item.songId, + // copyrightId: item.copyrightId, + // source: 'mg', + // interval: null, + // img: item.imgItems && item.imgItems.length ? item.imgItems[0].img : null, + // lrc: null, + // lrcUrl: item.lyricUrl, + // mrcUrl: item.mrcurl, + // trcUrl: item.trcUrl, + // otherSource: null, + // types, + // _types, + // typeUrl: {}, + // }) + // }) + // return list + // }, + musicSearch(str, page, limit) { const time = Date.now().toString() const signData = this.signWithSearch(time, str) @@ -20,7 +112,6 @@ export default { 'User-Agent': 'Mozilla/5.0 (Linux; U; Android 11.0.0; zh-cn; MI 11 Build/OPR1.170623.032) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30', }, }) - // searchRequest = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${limit}&searchSwitch={%22song%22:1,%22album%22:0,%22singer%22:0,%22tagSong%22:0,%22mvSong%22:0,%22songlist%22:0,%22bestShow%22:0}&sort=0&text=${encodeURIComponent(str)}`) return searchRequest.promise.then(({ body }) => body) }, getSinger(singers) { diff --git a/src/renderer/utils/musicSdk/mg/musicSearchOld.js b/src/renderer/utils/musicSdk/mg/musicSearchOld.js deleted file mode 100644 index a67065ec..00000000 --- a/src/renderer/utils/musicSdk/mg/musicSearchOld.js +++ /dev/null @@ -1,134 +0,0 @@ -// import '../../polyfill/array.find' - -import { httpFetch } from '../../request' -import { sizeFormate } from '../../index' -// import { debug } from '../../utils/env' -// import { formatSinger } from './util' - -export default { - limit: 20, - total: 0, - page: 0, - allPage: 1, - musicSearch(str, page, limit) { - const searchRequest = httpFetch(`http://pd.musicapp.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%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A0%2C%22mvSong%22%3A0%2C%22songlist%22%3A0%2C%22bestShow%22%3A1%7D`, { - // searchRequest = httpFetch(`http://jadeite.migu.cn:7090/music_search/v2/search/searchAll?sid=4f87090d01c84984a11976b828e2b02c18946be88a6b4c47bcdc92fbd40762db&isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, { - headers: { - // sign: 'c3b7ae985e2206e97f1b2de8f88691e2', - // timestamp: 1578225871982, - // appId: 'yyapp2', - // mode: 'android', - // ua: 'Android_migu', - // version: '6.9.4', - osVersion: 'android 7.0', - 'User-Agent': 'okhttp/3.9.1', - }, - }) - // searchRequest = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${limit}&searchSwitch={%22song%22:1,%22album%22:0,%22singer%22:0,%22tagSong%22:0,%22mvSong%22:0,%22songlist%22:0,%22bestShow%22:0}&sort=0&text=${encodeURIComponent(str)}`) - return searchRequest.promise.then(({ body }) => body) - }, - getSinger(singers) { - let arr = [] - singers.forEach(singer => { - arr.push(singer.name) - }) - return arr.join('、') - }, - handleResult(rawData) { - // console.log(rawData) - let ids = new Set() - const list = [] - rawData.forEach(item => { - if (ids.has(item.id)) return - ids.add(item.id) - const types = [] - const _types = {} - item.newRateFormats && item.newRateFormats.forEach(type => { - let size - switch (type.formatType) { - case 'PQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: '128k', size }) - _types['128k'] = { - size, - } - break - case 'HQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: '320k', size }) - _types['320k'] = { - size, - } - break - case 'SQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: 'flac', size }) - _types.flac = { - size, - } - break - case 'ZQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: 'flac24bit', size }) - _types.flac24bit = { - size, - } - break - } - }) - - const albumNInfo = item.albums && item.albums.length - ? { - id: item.albums[0].id, - name: item.albums[0].name, - } - : {} - - list.push({ - singer: this.getSinger(item.singers), - name: item.name, - albumName: albumNInfo.name, - albumId: albumNInfo.id, - songmid: item.songId, - copyrightId: item.copyrightId, - source: 'mg', - interval: null, - img: item.imgItems && item.imgItems.length ? item.imgItems[0].img : null, - lrc: null, - lrcUrl: item.lyricUrl, - mrcUrl: item.mrcurl, - trcUrl: item.trcUrl, - otherSource: null, - types, - _types, - typeUrl: {}, - }) - }) - return list - }, - search(str, page = 1, limit, retryNum = 0) { - if (++retryNum > 3) return Promise.reject(new Error('try max num')) - if (limit == null) limit = this.limit - // http://newlyric.kuwo.cn/newlyric.lrc?62355680 - return this.musicSearch(str, page, limit).then(result => { - // console.log(result) - if (!result || result.code !== '000000') return Promise.reject(new Error(result ? result.info : '搜索失败')) - const songResultData = result.songResultData || { result: [], totalCount: 0 } - - let list = this.handleResult(songResultData.result) - if (list == null) return this.search(str, page, limit, retryNum) - - this.total = parseInt(songResultData.totalCount) - this.page = page - this.allPage = Math.ceil(this.total / limit) - - return Promise.resolve({ - list, - allPage: this.allPage, - limit, - total: this.total, - source: 'mg', - }) - }) - }, -}