Scheme URL API新增 `music/searchPlay` 支持(#1886)
parent
8e7fd1ecef
commit
2ee7572634
|
@ -3,6 +3,7 @@
|
||||||
- 新增 设置-播放设置-使用设备能处理的最大声道数输出音频 设置(未启用时固定为2声道输出),由于这用到高级音频API,考虑到在某些设备上的兼容问题,默认禁用(#1873)
|
- 新增 设置-播放设置-使用设备能处理的最大声道数输出音频 设置(未启用时固定为2声道输出),由于这用到高级音频API,考虑到在某些设备上的兼容问题,默认禁用(#1873)
|
||||||
- 允许添加 `m4a`、`oga` 格式的本地歌曲到列表中(#1864)
|
- 允许添加 `m4a`、`oga` 格式的本地歌曲到列表中(#1864)
|
||||||
- 开放API支持跨域请求(#1872 @Ceale)
|
- 开放API支持跨域请求(#1872 @Ceale)
|
||||||
|
- Scheme URL API新增 `music/searchPlay` 支持,用于搜索并播放指定的歌曲名字,详细入参请阅读 Scheme URL 支持文档(#1886)
|
||||||
|
|
||||||
### 优化
|
### 优化
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ const getOtherSourcePromises = new Map()
|
||||||
export const existTimeExp = /\[\d{1,2}:.*\d{1,4}\]/
|
export const existTimeExp = /\[\d{1,2}:.*\d{1,4}\]/
|
||||||
|
|
||||||
export const getOtherSource = async(musicInfo: LX.Music.MusicInfo | LX.Download.ListItem, isRefresh = false): Promise<LX.Music.MusicInfoOnline[]> => {
|
export const getOtherSource = async(musicInfo: LX.Music.MusicInfo | LX.Download.ListItem, isRefresh = false): Promise<LX.Music.MusicInfoOnline[]> => {
|
||||||
if (!isRefresh) {
|
if (!isRefresh && musicInfo.id) {
|
||||||
const cachedInfo = await getOtherSourceFromStore(musicInfo.id)
|
const cachedInfo = await getOtherSourceFromStore(musicInfo.id)
|
||||||
if (cachedInfo.length) return cachedInfo
|
if (cachedInfo.length) return cachedInfo
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ export default () => {
|
||||||
console.log(params)
|
console.log(params)
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'music':
|
case 'music':
|
||||||
handleMusicAction(action, params)
|
await handleMusicAction(action, params)
|
||||||
break
|
break
|
||||||
case 'songlist':
|
case 'songlist':
|
||||||
await handleSonglistAction(action, params)
|
await handleSonglistAction(action, params)
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { focusWindow } from '@renderer/utils/ipc'
|
||||||
import { playNext } from '@renderer/core/player/action'
|
import { playNext } from '@renderer/core/player/action'
|
||||||
import { toNewMusicInfo } from '@common/utils/tools'
|
import { toNewMusicInfo } from '@common/utils/tools'
|
||||||
import { LIST_IDS } from '@common/constants'
|
import { LIST_IDS } from '@common/constants'
|
||||||
|
import { getOtherSource } from '@renderer/core/music/utils'
|
||||||
|
|
||||||
const useSearchMusic = () => {
|
const useSearchMusic = () => {
|
||||||
const router = useRouter()
|
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 () => {
|
export default () => {
|
||||||
const handleSearchMusic = useSearchMusic()
|
const handleSearchMusic = useSearchMusic()
|
||||||
const handlePlayMusic = usePlayMusic()
|
const handlePlayMusic = usePlayMusic()
|
||||||
|
const handleSearchPlayMusic = useSearchPlayMusic()
|
||||||
|
|
||||||
return (action, info) => {
|
|
||||||
|
return async(action, info) => {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'search':
|
case 'search':
|
||||||
handleSearchMusic(info)
|
handleSearchMusic(info)
|
||||||
|
@ -171,6 +229,9 @@ export default () => {
|
||||||
case 'play':
|
case 'play':
|
||||||
handlePlayMusic(info)
|
handlePlayMusic(info)
|
||||||
break
|
break
|
||||||
|
case 'searchPlay':
|
||||||
|
await handleSearchPlayMusic(info)
|
||||||
|
break
|
||||||
default: throw new Error('Unknown action: ' + action)
|
default: throw new Error('Unknown action: ' + action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue