From 784d2fda6d3ba03c1b2fb87477a1e148e41df227 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sun, 1 Nov 2020 14:36:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B0=8F=E8=8A=B8=E6=BA=90?= =?UTF-8?q?=E9=9F=B3=E4=B9=90=E6=90=9C=E7=B4=A2=E7=BB=93=E6=9E=9C=E6=9C=80?= =?UTF-8?q?=E5=A4=9A=E5=8F=AA=E6=9C=8920=E6=9D=A1=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 4 ++ src/renderer/utils/music/wy/musicSearch.js | 58 +++++++++++++++------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index df42ba36..b6475a4d 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -6,3 +6,7 @@ - 修改播放详情页的歌曲图片的显示效果 + +### 修复 + +- 修复小芸源音乐搜索结果最多只有20条搜索结果的问题 diff --git a/src/renderer/utils/music/wy/musicSearch.js b/src/renderer/utils/music/wy/musicSearch.js index 6f99b12e..d7a40fd9 100644 --- a/src/renderer/utils/music/wy/musicSearch.js +++ b/src/renderer/utils/music/wy/musicSearch.js @@ -1,6 +1,7 @@ import { httpFetch } from '../../request' import { weapi } from './utils/crypto' -import { sizeFormate, formatPlayTime } from '../../index' +// import { sizeFormate, formatPlayTime } from '../../index' +import musicDetailApi from './musicDetail' let searchRequest export default { @@ -10,8 +11,12 @@ export default { allPage: 1, musicSearch(str, page) { if (searchRequest && searchRequest.cancelHttp) searchRequest.cancelHttp() - searchRequest = httpFetch('http://music.163.com/weapi/cloudsearch/get/web?csrf_token=', { + searchRequest = httpFetch('https://music.163.com/weapi/search/get', { method: 'post', + headers: { + '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', + }, form: weapi({ s: str, type: 1, // 1: 单曲, 10: 专辑, 100: 歌手, 1000: 歌单, 1002: 用户, 1004: MV, 1006: 歌词, 1009: 电台, 1014: 视频 @@ -19,7 +24,24 @@ export default { offset: this.limit * (page - 1), }), }) - return searchRequest.promise.then(({ body }) => body) + return searchRequest.promise.then(({ body }) => + body && body.code === 200 + ? musicDetailApi.getList(body.result.songs.map(s => s.id)).then(({ list }) => { + this.total = body.result.songCount || 0 + this.page = page + this.allPage = Math.ceil(this.total / this.limit) + return { + code: 200, + data: { + list, + allPage: this.allPage, + limit: this.limit, + total: this.total, + source: 'wy', + }, + } + }) + : body) }, getSinger(singers) { let arr = [] @@ -28,7 +50,7 @@ export default { }) return arr.join('、') }, - handleResult(rawList) { + /* handleResult(rawList) { // console.log(rawList) if (!rawList) return [] return rawList.map(item => { @@ -78,27 +100,29 @@ export default { typeUrl: {}, } }) - }, + }, */ search(str, page = 1, { limit } = {}, retryNum = 0) { if (++retryNum > 3) return Promise.reject(new Error('try max num')) if (limit != null) this.limit = limit return this.musicSearch(str, page).then(result => { + // console.log(result) if (!result || result.code !== 200) return this.search(str, page, { limit }, retryNum) - let list = this.handleResult(result.result.songs || []) + // let list = this.handleResult(result.result.songs || []) - if (list == null) return this.search(str, page, { limit }, retryNum) + // if (list == null) return this.search(str, page, { limit }, retryNum) - this.total = result.result.songCount || 0 - this.page = page - this.allPage = Math.ceil(this.total / this.limit) + // this.total = result.result.songCount || 0 + // this.page = page + // this.allPage = Math.ceil(this.total / this.limit) - return Promise.resolve({ - list, - allPage: this.allPage, - limit: this.limit, - total: this.total, - source: 'wy', - }) + // return Promise.resolve({ + // list, + // allPage: this.allPage, + // limit: this.limit, + // total: this.total, + // source: 'wy', + // }) + return result.data }) }, }