新增“不喜欢歌曲”功能&新增“收藏歌曲”、“取消收藏”、“不喜欢该歌曲”快捷键设置
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// import { throttle } from '@common/utils'
|
||||
|
||||
import { SPLIT_CHAR } from '@common/constants'
|
||||
import { filterFileName, sortInsert, similar, arrPushByPosition, arrShuffle } from '@common/utils/common'
|
||||
import { joinPath, saveStrToFile } from '@common/utils/nodejs'
|
||||
import { createLocalMusicInfo } from '@renderer/utils/music'
|
||||
@@ -8,7 +9,7 @@ import { createLocalMusicInfo } from '@renderer/utils/music'
|
||||
/**
|
||||
* 过滤列表中已播放的歌曲
|
||||
*/
|
||||
export const filterMusicList = async({ playedList, listId, list, savePath, playerMusicInfo }: {
|
||||
export const filterMusicList = async({ playedList, listId, list, savePath, playerMusicInfo, dislikeInfo, isNext }: {
|
||||
/**
|
||||
* 已播放列表
|
||||
*/
|
||||
@@ -29,15 +30,34 @@ export const filterMusicList = async({ playedList, listId, list, savePath, playe
|
||||
* 播放器内当前歌曲(`playInfo.playerPlayIndex`指向的歌曲)
|
||||
*/
|
||||
playerMusicInfo?: LX.Music.MusicInfo | LX.Download.ListItem
|
||||
/**
|
||||
* 不喜欢的歌曲名字列表
|
||||
*/
|
||||
dislikeInfo: Omit<LX.Dislike.DislikeInfo, 'rules'>
|
||||
|
||||
isNext: boolean
|
||||
}) => {
|
||||
let playerIndex = -1
|
||||
|
||||
let canPlayList: Array<LX.Music.MusicInfo | LX.Download.ListItem> = []
|
||||
const filteredPlayedList = playedList.filter(pmInfo => pmInfo.listId == listId && !pmInfo.isTempPlay).map(({ musicInfo }) => musicInfo)
|
||||
const hasDislike = (info: LX.Music.MusicInfo) => {
|
||||
const name = info.name?.replaceAll(SPLIT_CHAR.DISLIKE_NAME, SPLIT_CHAR.DISLIKE_NAME_ALIAS).toLocaleLowerCase().trim() ?? ''
|
||||
const singer = info.singer?.replaceAll(SPLIT_CHAR.DISLIKE_NAME, SPLIT_CHAR.DISLIKE_NAME_ALIAS).toLocaleLowerCase().trim() ?? ''
|
||||
|
||||
return dislikeInfo.musicNames.has(name) || dislikeInfo.singerNames.has(singer) ||
|
||||
dislikeInfo.names.has(`${name}${SPLIT_CHAR.DISLIKE_NAME}${singer}`)
|
||||
}
|
||||
|
||||
let isDislike = false
|
||||
const filteredList: Array<LX.Music.MusicInfo | LX.Download.ListItem> = list.filter(s => {
|
||||
// if (!assertApiSupport(s.source)) return false
|
||||
if ('progress' in s && !s.isComplate) return false
|
||||
if ('progress' in s) {
|
||||
if (!s.isComplate) return false
|
||||
} else if (hasDislike(s)) {
|
||||
if (s.id != playerMusicInfo?.id) return false
|
||||
isDislike = true
|
||||
}
|
||||
|
||||
canPlayList.push(s)
|
||||
|
||||
@@ -49,7 +69,34 @@ export const filterMusicList = async({ playedList, listId, list, savePath, playe
|
||||
return true
|
||||
})
|
||||
if (playerMusicInfo) {
|
||||
playerIndex = (filteredList.length ? filteredList : canPlayList).findIndex(m => m.id == playerMusicInfo.id)
|
||||
if (isDislike) {
|
||||
if (filteredList.length <= 1) {
|
||||
filteredList.splice(0, 1)
|
||||
if (canPlayList.length > 1) {
|
||||
let currentMusicIndex = canPlayList.findIndex(m => m.id == playerMusicInfo.id)
|
||||
if (isNext) {
|
||||
playerIndex = currentMusicIndex - 1
|
||||
if (playerIndex < 0 && canPlayList.length > 1) playerIndex = canPlayList.length - 2
|
||||
} else {
|
||||
playerIndex = currentMusicIndex
|
||||
if (canPlayList.length <= 1) playerIndex = -1
|
||||
}
|
||||
canPlayList.splice(currentMusicIndex, 1)
|
||||
} else canPlayList.splice(0, 1)
|
||||
} else {
|
||||
let currentMusicIndex = filteredList.findIndex(m => m.id == playerMusicInfo.id)
|
||||
if (isNext) {
|
||||
playerIndex = currentMusicIndex - 1
|
||||
if (playerIndex < 0 && filteredList.length > 1) playerIndex = filteredList.length - 2
|
||||
} else {
|
||||
playerIndex = currentMusicIndex
|
||||
if (filteredList.length <= 1) playerIndex = -1
|
||||
}
|
||||
filteredList.splice(currentMusicIndex, 1)
|
||||
}
|
||||
} else {
|
||||
playerIndex = (filteredList.length ? filteredList : canPlayList).findIndex(m => m.id == playerMusicInfo.id)
|
||||
}
|
||||
}
|
||||
return {
|
||||
filteredList,
|
||||
|
||||
Reference in New Issue
Block a user