优化播放歌曲换源匹配
parent
4c44310fea
commit
1af3cd1d77
|
@ -1,3 +1,7 @@
|
||||||
### 新增
|
### 新增
|
||||||
|
|
||||||
- 搜索界面新增搜索状态的提示
|
- 搜索界面新增搜索状态的提示
|
||||||
|
|
||||||
|
### 优化
|
||||||
|
|
||||||
|
- 优化播放歌曲换源匹配
|
||||||
|
|
|
@ -57,6 +57,20 @@ const mutations = {
|
||||||
if (defaultList != null) Object.assign(state.defaultList, { list: defaultList.list, location: defaultList.location })
|
if (defaultList != null) Object.assign(state.defaultList, { list: defaultList.list, location: defaultList.location })
|
||||||
if (loveList != null) Object.assign(state.loveList, { list: loveList.list, location: loveList.location })
|
if (loveList != null) Object.assign(state.loveList, { list: loveList.list, location: loveList.location })
|
||||||
if (userList != null) state.userList = userList
|
if (userList != null) state.userList = userList
|
||||||
|
if (window.localStorage.getItem('isResetOtherSource') != '1') {
|
||||||
|
for (const item of defaultList.list) {
|
||||||
|
if (item.otherSource) item.otherSource = null
|
||||||
|
}
|
||||||
|
for (const item of loveList.list) {
|
||||||
|
if (item.otherSource) item.otherSource = null
|
||||||
|
}
|
||||||
|
for (const list of userList) {
|
||||||
|
for (const item of list.list) {
|
||||||
|
if (item.otherSource) item.otherSource = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.localStorage.setItem('isResetOtherSource', '1')
|
||||||
|
}
|
||||||
allListInit(state.defaultList, state.loveList, state.userList)
|
allListInit(state.defaultList, state.loveList, state.userList)
|
||||||
state.isInitedList = true
|
state.isInitedList = true
|
||||||
},
|
},
|
||||||
|
|
|
@ -59,25 +59,37 @@ export default {
|
||||||
|
|
||||||
async findMusic(musicInfo) {
|
async findMusic(musicInfo) {
|
||||||
const tasks = []
|
const tasks = []
|
||||||
|
const sortSingle = singer => singer.includes('、') ? singer.split('、').sort((a, b) => a.charCodeAt(0) - b.charCodeAt(0)).join('、') : singer
|
||||||
|
const sortMusic = (arr, callback) => {
|
||||||
|
const tempResult = []
|
||||||
|
for (let i = arr.length - 1; i > -1; i--) {
|
||||||
|
const item = arr[i]
|
||||||
|
if (callback(item)) {
|
||||||
|
delete item.sortedSinger
|
||||||
|
tempResult.push(item)
|
||||||
|
arr.splice(i, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tempResult.reverse()
|
||||||
|
}
|
||||||
|
const trimStr = str => typeof str == 'string' ? str.trim() : str
|
||||||
|
const sortedSinger = sortSingle(musicInfo.singer)
|
||||||
|
const musicName = trimStr(musicInfo.name)
|
||||||
for (const source of sources.sources) {
|
for (const source of sources.sources) {
|
||||||
if (!sources[source.id].musicSearch || source.id === musicInfo.source || source.id === 'xm') continue
|
if (!sources[source.id].musicSearch || source.id === musicInfo.source || source.id === 'xm') continue
|
||||||
const sortedSinger = musicInfo.singer.includes('、') ? musicInfo.singer.split('、').sort((a, b) => a.charCodeAt(0) - b.charCodeAt(0)).join('、') : null
|
|
||||||
|
|
||||||
tasks.push(sources[source.id].musicSearch.search(`${musicInfo.name} ${musicInfo.singer || ''}`.trim(), 1, { limit: 10 }).then(res => {
|
tasks.push(sources[source.id].musicSearch.search(`${musicName} ${musicInfo.singer || ''}`.trim(), 1, { limit: 10 }).then(res => {
|
||||||
for (const item of res.list) {
|
for (const item of res.list) {
|
||||||
|
item.sortedSinger = sortSingle(item.singer)
|
||||||
|
item.name = trimStr(item.name)
|
||||||
if (
|
if (
|
||||||
(
|
(
|
||||||
item.singer === musicInfo.singer &&
|
item.sortedSinger === sortedSinger &&
|
||||||
(item.name === musicInfo.name || item.interval === musicInfo.interval)
|
(item.name === musicName || item.interval === musicInfo.interval)
|
||||||
) ||
|
) ||
|
||||||
(
|
(
|
||||||
item.interval === musicInfo.interval && item.name === musicInfo.name &&
|
item.interval === musicInfo.interval && item.name === musicName &&
|
||||||
(item.singer.includes(musicInfo.singer) || musicInfo.singer.includes(item.singer))
|
(item.sortedSinger.includes(sortedSinger) || sortedSinger.includes(item.sortedSinger))
|
||||||
) ||
|
|
||||||
(
|
|
||||||
sortedSinger &&
|
|
||||||
item.singer.includes('、') &&
|
|
||||||
item.singer.split('、').sort((a, b) => a.charCodeAt(0) - b.charCodeAt(0)).join('、') === sortedSinger
|
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return item
|
return item
|
||||||
|
@ -89,35 +101,13 @@ export default {
|
||||||
const result = (await Promise.all(tasks)).filter(s => s)
|
const result = (await Promise.all(tasks)).filter(s => s)
|
||||||
const newResult = []
|
const newResult = []
|
||||||
if (result.length) {
|
if (result.length) {
|
||||||
for (let i = result.length - 1; i > -1; i--) {
|
newResult.push(...sortMusic(result, item => item.sortedSinger === sortedSinger && item.name === musicName && item.interval === musicInfo.interval))
|
||||||
const item = result[i]
|
newResult.push(...sortMusic(result, item => item.sortedSinger === sortedSinger && item.interval === musicInfo.interval))
|
||||||
if (item.singer === musicInfo.singer && item.name === musicInfo.name && item.interval === musicInfo.interval) {
|
newResult.push(...sortMusic(result, item => item.name === musicName && item.sortedSinger === sortedSinger && item.albumName === musicInfo.albumName))
|
||||||
newResult.push(item)
|
newResult.push(...sortMusic(result, item => item.sortedSinger === sortedSinger && item.name === musicName))
|
||||||
result.splice(i, 1)
|
for (const item of result) {
|
||||||
}
|
delete item.sortedSinger
|
||||||
}
|
}
|
||||||
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.name === musicInfo.name && item.singer === musicInfo.singer && item.albumName === musicInfo.albumName) {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
newResult.reverse()
|
|
||||||
newResult.push(...result)
|
newResult.push(...result)
|
||||||
}
|
}
|
||||||
// console.log(newResult)
|
// console.log(newResult)
|
||||||
|
|
Loading…
Reference in New Issue