From 9a1a537bfd84af018e8f85923ba6be09701a425d Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sat, 9 Jan 2021 00:45:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=92=AD=E6=94=BE=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=8D=A2=E6=BA=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 1 + src/renderer/components/core/Player.vue | 32 +++++++++++++--- src/renderer/store/modules/player.js | 3 +- src/renderer/utils/music/index.js | 43 ++++++++++++++++++++++ src/renderer/utils/music/kg/leaderboard.js | 1 + src/renderer/utils/music/kg/musicSearch.js | 1 + src/renderer/utils/music/kg/songList.js | 1 + src/renderer/utils/music/kw/leaderboard.js | 1 + src/renderer/utils/music/kw/musicSearch.js | 1 + src/renderer/utils/music/kw/songList.js | 1 + src/renderer/utils/music/mg/leaderboard.js | 1 + src/renderer/utils/music/mg/musicSearch.js | 3 +- src/renderer/utils/music/mg/songList.js | 1 + src/renderer/utils/music/tx/leaderboard.js | 1 + src/renderer/utils/music/tx/musicSearch.js | 1 + src/renderer/utils/music/tx/songList.js | 1 + src/renderer/utils/music/wy/musicDetail.js | 1 + src/renderer/utils/music/wy/songList.js | 1 + src/renderer/utils/music/xm/leaderboard.js | 1 + src/renderer/utils/music/xm/musicSearch.js | 1 + src/renderer/utils/music/xm/songList.js | 1 + 21 files changed, 90 insertions(+), 8 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index 243b09a0..aca1681f 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -7,6 +7,7 @@ - 添加桌面歌词字体、透明度调整按钮微调提示(你可能不知道的操作->对于字体、透明度可右击微调) - 我的列表右键菜单添加搜索当前歌曲功能 - 新增`-dha`参数,添加此启动参数将禁用硬件加速启动(Disable Hardware Acceleration),窗口显示有问题时可以尝试添加此参数启动,Linux系统的界面显示有问题时可尝试添加此参数启动,若不行可尝试添加`-dt`参数启动 +- 新增播放自动换源功能~ ### 变更 diff --git a/src/renderer/components/core/Player.vue b/src/renderer/components/core/Player.vue index debac354..7e08d9f7 100644 --- a/src/renderer/components/core/Player.vue +++ b/src/renderer/components/core/Player.vue @@ -92,6 +92,7 @@ import { mapGetters, mapActions, mapMutations } from 'vuex' import { requestMsg } from '../../utils/message' import { isMac } from '../../../common/utils' import { player as eventPlayerNames } from '../../../common/hotKey' +import musicSdk from '@renderer/utils/music' import path from 'path' let audio @@ -694,20 +695,39 @@ export default { if (highQuality && songInfo._types['320k'] && list && list.includes('320k')) type = '320k' return type }, - setUrl(targetSong, isRefresh, isRetryed = false) { + setUrl(targetSong, isRefresh, isRetryed = false, retryedSource = [], originMusic = null) { + if (!retryedSource.includes(targetSong.source)) retryedSource.push(targetSong.source) + let type = this.getPlayType(this.setting.player.highQuality, targetSong) this.musicInfo.url = targetSong.typeUrl[type] this.status = this.statusText = this.$t('core.player.geting_url') - return this.getUrl({ musicInfo: targetSong, type, isRefresh }).then(() => { + return this.getUrl({ musicInfo: targetSong, originMusic, type, isRefresh }).then(() => { audio.src = this.musicInfo.url = targetSong.typeUrl[type] }).catch(err => { // console.log('err', err.message) if (err.message == requestMsg.cancelRequest) return - if (!isRetryed) return this.setUrl(targetSong, isRefresh, true) - this.status = this.statusText = err.message - this.addDelayNextTimeout() - return Promise.reject(err) + if (!isRetryed) return this.setUrl(targetSong, isRefresh, true, retryedSource, originMusic) + if (!originMusic) originMusic = targetSong + + this.status = this.statusText = 'Try toggle source...' + + return (originMusic.otherSource ? Promise.resolve(originMusic.otherSource) : musicSdk.findMusic(originMusic)).then(res => { + this.updateMusicInfo({ id: this.listId, index: this.playIndex, data: { otherSource: res } }) + return res + }).then(otherSource => { + console.log('find otherSource', otherSource) + if (otherSource.length) { + for (const item of otherSource) { + if (retryedSource.includes(item.source)) continue + console.log('try toggle to: ', item.source, item.name, item.singer, item.interval) + return this.setUrl(item, isRefresh, false, retryedSource, originMusic) + } + } + this.status = this.statusText = err.message + this.addDelayNextTimeout() + return Promise.reject(err) + }) }) }, setImg(targetSong) { diff --git a/src/renderer/store/modules/player.js b/src/renderer/store/modules/player.js index 80a38b5b..62c12804 100644 --- a/src/renderer/store/modules/player.js +++ b/src/renderer/store/modules/player.js @@ -28,7 +28,7 @@ const getters = { // actions const actions = { - getUrl({ commit, state }, { musicInfo, type, isRefresh }) { + getUrl({ commit, state }, { musicInfo, originMusic, type, isRefresh }) { if (!musicInfo._types[type]) { // 兼容旧版酷我源搜索列表过滤128k音质的bug if (!(musicInfo.source == 'kw' && type == '128k')) return Promise.reject(new Error('该歌曲没有可播放的音频')) @@ -39,6 +39,7 @@ const actions = { if (musicInfo.typeUrl[type] && !isRefresh) return Promise.resolve() urlRequest = music[musicInfo.source].getMusicUrl(musicInfo, type) return urlRequest.promise.then(result => { + if (originMusic) commit('setUrl', { musicInfo: originMusic, url: result.url, type }) commit('setUrl', { musicInfo, url: result.url, type }) urlRequest = null }).catch(err => { diff --git a/src/renderer/utils/music/index.js b/src/renderer/utils/music/index.js index ae882ab5..5453c952 100644 --- a/src/renderer/utils/music/index.js +++ b/src/renderer/utils/music/index.js @@ -56,4 +56,47 @@ export default { } }, supportQuality, + + async findMusic(musicInfo) { + const tasks = [] + for (const source of sources.sources) { + if (!sources[source.id].musicSearch || source.id === musicInfo.source || source.id === 'xm') continue + + tasks.push(sources[source.id].musicSearch.search(`${musicInfo.name} ${musicInfo.singer || ''} ${musicInfo.albumName || ''}`.trim(), 1, { limit: 5 }).then(res => { + for (const item of res.list) { + if (item.singer === musicInfo.singer && (item.name === musicInfo.name || item.interval === musicInfo.interval)) { + return item + } + } + return null + }).catch(_ => null)) + } + const result = (await Promise.all(tasks)).filter(s => s) + const newResult = [] + if (result.length) { + for (let i = result.length - 1; i > -1; i--) { + const item = result[i] + if (item.singer === musicInfo.singer && item.name === musicInfo.name && item.interval === musicInfo.interval) { + newResult.push(item) + result.splice(i, 1) + } + } + for (let i = result.length - 1; i > -1; i--) { + const item = result[i] + if (item.singer === musicInfo.singer && item.interval === musicInfo.interval) { + newResult.push(item) + result.splice(i, 1) + } + } + for (let i = result.length - 1; i > -1; i--) { + const item = result[i] + if (item.singer === musicInfo.singer && item.name === musicInfo.name) { + newResult.push(item) + result.splice(i, 1) + } + } + } + // console.log(newResult) + return newResult + }, } diff --git a/src/renderer/utils/music/kg/leaderboard.js b/src/renderer/utils/music/kg/leaderboard.js index c5c34741..7a6c3fb7 100644 --- a/src/renderer/utils/music/kg/leaderboard.js +++ b/src/renderer/utils/music/kg/leaderboard.js @@ -144,6 +144,7 @@ export default { img: null, lrc: null, hash: item.HASH, + otherSource: null, types, _types, typeUrl: {}, diff --git a/src/renderer/utils/music/kg/musicSearch.js b/src/renderer/utils/music/kg/musicSearch.js index 98aeeddb..364229f1 100644 --- a/src/renderer/utils/music/kg/musicSearch.js +++ b/src/renderer/utils/music/kg/musicSearch.js @@ -60,6 +60,7 @@ export default { _interval: item.duration, img: null, lrc: null, + otherSource: null, hash: item.hash, types, _types, diff --git a/src/renderer/utils/music/kg/songList.js b/src/renderer/utils/music/kg/songList.js index 2bf3ff76..97f5e0cf 100644 --- a/src/renderer/utils/music/kg/songList.js +++ b/src/renderer/utils/music/kg/songList.js @@ -517,6 +517,7 @@ export default { img: null, lrc: null, hash: item.audio_info.hash, + otherSource: null, types, _types, typeUrl: {}, diff --git a/src/renderer/utils/music/kw/leaderboard.js b/src/renderer/utils/music/kw/leaderboard.js index 3ca926dc..a54b42ac 100644 --- a/src/renderer/utils/music/kw/leaderboard.js +++ b/src/renderer/utils/music/kw/leaderboard.js @@ -142,6 +142,7 @@ export default { interval: formatPlayTime(parseInt(item.song_duration)), img: item.pic, lrc: null, + otherSource: null, types, _types, typeUrl: {}, diff --git a/src/renderer/utils/music/kw/musicSearch.js b/src/renderer/utils/music/kw/musicSearch.js index cc689cc6..4f201de9 100644 --- a/src/renderer/utils/music/kw/musicSearch.js +++ b/src/renderer/utils/music/kw/musicSearch.js @@ -115,6 +115,7 @@ export default { albumName: info.ALBUM ? decodeName(info.ALBUM) : '', lrc: null, img: null, + otherSource: null, types, _types, typeUrl: {}, diff --git a/src/renderer/utils/music/kw/songList.js b/src/renderer/utils/music/kw/songList.js index ab5b8c79..ce8f8796 100644 --- a/src/renderer/utils/music/kw/songList.js +++ b/src/renderer/utils/music/kw/songList.js @@ -237,6 +237,7 @@ export default { interval: formatPlayTime(parseInt(item.duration)), img: null, lrc: null, + otherSource: null, types, _types, typeUrl: {}, diff --git a/src/renderer/utils/music/mg/leaderboard.js b/src/renderer/utils/music/mg/leaderboard.js index 37dba46c..0d1cbef4 100644 --- a/src/renderer/utils/music/mg/leaderboard.js +++ b/src/renderer/utils/music/mg/leaderboard.js @@ -144,6 +144,7 @@ export default { img: item.albumImgs && item.albumImgs.length ? item.albumImgs[0].img : null, lrc: null, lrcUrl: item.lrcUrl, + otherSource: null, types, _types, typeUrl: {}, diff --git a/src/renderer/utils/music/mg/musicSearch.js b/src/renderer/utils/music/mg/musicSearch.js index 9e370395..8ed3d238 100644 --- a/src/renderer/utils/music/mg/musicSearch.js +++ b/src/renderer/utils/music/mg/musicSearch.js @@ -36,7 +36,7 @@ export default { return arr.join('、') }, handleResult(rawData) { - console.log(rawData) + // console.log(rawData) let ids = new Set() const list = [] rawData.forEach(item => { @@ -89,6 +89,7 @@ export default { img: item.imgItems && item.imgItems.length ? item.imgItems[0].img : null, lrc: null, lrcUrl: item.lyricUrl, + otherSource: null, types, _types, typeUrl: {}, diff --git a/src/renderer/utils/music/mg/songList.js b/src/renderer/utils/music/mg/songList.js index 2def8cce..5eaf869d 100644 --- a/src/renderer/utils/music/mg/songList.js +++ b/src/renderer/utils/music/mg/songList.js @@ -141,6 +141,7 @@ export default { img: item.albumImgs && item.albumImgs.length ? item.albumImgs[0].img : null, lrc: null, lrcUrl: item.lrcUrl, + otherSource: null, types, _types, typeUrl: {}, diff --git a/src/renderer/utils/music/tx/leaderboard.js b/src/renderer/utils/music/tx/leaderboard.js index 78fdb525..d798fdc7 100644 --- a/src/renderer/utils/music/tx/leaderboard.js +++ b/src/renderer/utils/music/tx/leaderboard.js @@ -167,6 +167,7 @@ export default { ? `https://y.gtimg.cn/music/photo_new/T001R500x500M000${item.singer[0].mid}.jpg` : `https://y.gtimg.cn/music/photo_new/T002R500x500M000${item.album.mid}.jpg`, lrc: null, + otherSource: null, types, _types, typeUrl: {}, diff --git a/src/renderer/utils/music/tx/musicSearch.js b/src/renderer/utils/music/tx/musicSearch.js index 188943f7..c2d21f92 100644 --- a/src/renderer/utils/music/tx/musicSearch.js +++ b/src/renderer/utils/music/tx/musicSearch.js @@ -78,6 +78,7 @@ export default { ? `https://y.gtimg.cn/music/photo_new/T001R500x500M000${item.singer[0].mid}.jpg` : `https://y.gtimg.cn/music/photo_new/T002R500x500M000${item.album.mid}.jpg`, lrc: null, + otherSource: null, types, _types, typeUrl: {}, diff --git a/src/renderer/utils/music/tx/songList.js b/src/renderer/utils/music/tx/songList.js index bfa1525b..4684c389 100644 --- a/src/renderer/utils/music/tx/songList.js +++ b/src/renderer/utils/music/tx/songList.js @@ -281,6 +281,7 @@ export default { ? `https://y.gtimg.cn/music/photo_new/T001R500x500M000${item.singer[0].mid}.jpg` : `https://y.gtimg.cn/music/photo_new/T002R500x500M000${item.album.mid}.jpg`, lrc: null, + otherSource: null, types, _types, typeUrl: {}, diff --git a/src/renderer/utils/music/wy/musicDetail.js b/src/renderer/utils/music/wy/musicDetail.js index 695caed9..a53d99b5 100644 --- a/src/renderer/utils/music/wy/musicDetail.js +++ b/src/renderer/utils/music/wy/musicDetail.js @@ -60,6 +60,7 @@ export default { songmid: item.id, img: item.al.picUrl, lrc: null, + otherSource: null, types, _types, typeUrl: {}, diff --git a/src/renderer/utils/music/wy/songList.js b/src/renderer/utils/music/wy/songList.js index 145c37d0..45f7b769 100644 --- a/src/renderer/utils/music/wy/songList.js +++ b/src/renderer/utils/music/wy/songList.js @@ -161,6 +161,7 @@ export default { songmid: item.id, img: item.al.picUrl, lrc: null, + otherSource: null, types, _types, typeUrl: {}, diff --git a/src/renderer/utils/music/xm/leaderboard.js b/src/renderer/utils/music/xm/leaderboard.js index 34dca4b1..5831e56b 100644 --- a/src/renderer/utils/music/xm/leaderboard.js +++ b/src/renderer/utils/music/xm/leaderboard.js @@ -127,6 +127,7 @@ export default { songStringId: songData.songStringId, lrc: null, lrcUrl: songData.lyricInfo && songData.lyricInfo.lyricFile, + otherSource: null, types, _types, typeUrl: {}, diff --git a/src/renderer/utils/music/xm/musicSearch.js b/src/renderer/utils/music/xm/musicSearch.js index 47c6b218..b4a7ff6c 100644 --- a/src/renderer/utils/music/xm/musicSearch.js +++ b/src/renderer/utils/music/xm/musicSearch.js @@ -79,6 +79,7 @@ export default { songStringId: songData.songStringId, lrc: null, lrcUrl: songData.lyricInfo && songData.lyricInfo.lyricFile, + otherSource: null, types, _types, typeUrl: {}, diff --git a/src/renderer/utils/music/xm/songList.js b/src/renderer/utils/music/xm/songList.js index 0ca81450..5389cff0 100644 --- a/src/renderer/utils/music/xm/songList.js +++ b/src/renderer/utils/music/xm/songList.js @@ -142,6 +142,7 @@ export default { img: songData.albumLogo || songData.albumLogoS, lrc: null, lrcUrl: songData.lyricInfo && songData.lyricInfo.lyricFile, + otherSource: null, types, _types, typeUrl: {},