Scheme URL API新增 music/searchPlay 支持(#1886)
This commit is contained in:
@@ -10,6 +10,7 @@ import { focusWindow } from '@renderer/utils/ipc'
|
||||
import { playNext } from '@renderer/core/player/action'
|
||||
import { toNewMusicInfo } from '@common/utils/tools'
|
||||
import { LIST_IDS } from '@common/constants'
|
||||
import { getOtherSource } from '@renderer/core/music/utils'
|
||||
|
||||
const useSearchMusic = () => {
|
||||
const router = useRouter()
|
||||
@@ -159,11 +160,68 @@ const usePlayMusic = () => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const useSearchPlayMusic = () => {
|
||||
const verifyInfo = (info) => {
|
||||
return dataVerify([
|
||||
{ key: 'name', types: ['string'], required: true, max: 200 },
|
||||
{ key: 'singer', types: ['string'], max: 200 },
|
||||
{ key: 'albumName', types: ['string'], max: 64 },
|
||||
{ key: 'interval', types: ['string'], max: 64 },
|
||||
{ key: 'playLater', types: ['boolean'] },
|
||||
], info)
|
||||
}
|
||||
|
||||
const searchMusic = async(name, singer, albumName, interval) => {
|
||||
return getOtherSource({
|
||||
name,
|
||||
singer,
|
||||
interval,
|
||||
meta: {
|
||||
albumName,
|
||||
},
|
||||
source: 'local',
|
||||
id: `sp_${name}_s${singer}_a${albumName}_i${interval ?? ''}`,
|
||||
})
|
||||
}
|
||||
return async({ paths, data }) => {
|
||||
// console.log(paths, data)
|
||||
let info
|
||||
if (paths.length) {
|
||||
let name = paths[0]
|
||||
let singer = ''
|
||||
if (name.includes('-')) [name, singer] = name.split('-').map(val => val.trim())
|
||||
info = {
|
||||
name,
|
||||
singer,
|
||||
}
|
||||
} else info = data
|
||||
info = verifyInfo(info)
|
||||
const musicList = await searchMusic(info.name, info.singer || '', info.albumName || '', info.interval || null)
|
||||
if (musicList.length) {
|
||||
console.log('find music:', musicList)
|
||||
const musicInfo = musicList[0]
|
||||
markRaw(musicInfo)
|
||||
const isPlaying = !!playMusicInfo.musicInfo
|
||||
if (info.playLater) {
|
||||
addTempPlayList([{ listId: LIST_IDS.PLAY_LATER, musicInfo }])
|
||||
} else {
|
||||
addTempPlayList([{ listId: LIST_IDS.PLAY_LATER, musicInfo, isTop: true }])
|
||||
if (isPlaying) playNext()
|
||||
}
|
||||
} else {
|
||||
console.log('msuic not found:', info)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default () => {
|
||||
const handleSearchMusic = useSearchMusic()
|
||||
const handlePlayMusic = usePlayMusic()
|
||||
const handleSearchPlayMusic = useSearchPlayMusic()
|
||||
|
||||
return (action, info) => {
|
||||
|
||||
return async(action, info) => {
|
||||
switch (action) {
|
||||
case 'search':
|
||||
handleSearchMusic(info)
|
||||
@@ -171,6 +229,9 @@ export default () => {
|
||||
case 'play':
|
||||
handlePlayMusic(info)
|
||||
break
|
||||
case 'searchPlay':
|
||||
await handleSearchPlayMusic(info)
|
||||
break
|
||||
default: throw new Error('Unknown action: ' + action)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user