Skip to content

Commit

Permalink
Add audio search (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
the1812 committed Mar 19, 2023
1 parent c9bc402 commit d92fb8d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
1 change: 1 addition & 0 deletions registry/lib/plugins/launch-bar/audio-search/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
在输入音频的 au 号或播放列表的 am 号时, 提供对应的跳转选项.
42 changes: 42 additions & 0 deletions registry/lib/plugins/launch-bar/audio-search/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { LaunchBarActionProvider } from '@/components/launch-bar/launch-bar-action'
import type { PluginMetadata } from '@/plugins/plugin'
import { getJson } from '@/core/ajax'

export const plugin: PluginMetadata = {
name: 'launchBar.actions.audioSearch',
displayName: '搜索栏 - 音频跳转',
async setup({ addData }) {
addData('launchBar.actions', (providers: LaunchBarActionProvider[]) => {
providers.push({
name: 'audioSearchProvider',
getActions: async input => {
const match = input.match(/^(a[um])(\d+)$/)
if (!match) {
return []
}
const type = match[1]
const id = match[2]
const indexer = `${type}${id}`
const json = await getJson(
type === 'am'
? `https://www.bilibili.com/audio/music-service-c/web/menu/info?sid=${id}`
: `https://www.bilibili.com/audio/music-service-c/web/song/info?sid=${id}`,
)
const { title } = lodash.get(json, 'data', {})
return [
{
name: title || indexer,
icon: 'mdi-open-in-new',
indexer,
description: type === 'am' ? '播放列表跳转' : '音频跳转',
action: () => {
window.open(`https://www.bilibili.com/audio/${indexer}`, '_blank')
},
order: 0,
},
]
},
})
})
},
}
1 change: 1 addition & 0 deletions registry/lib/plugins/launch-bar/cv-search/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
在输入专栏的 cv 号或专栏文集的 rl 号时, 提供对应的跳转选项.
25 changes: 22 additions & 3 deletions registry/lib/plugins/launch-bar/cv-search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,31 @@ export const plugin: PluginMetadata = {
providers.push({
name: 'cvSearchProvider',
getActions: async input => {
const match = input.match(/^cv(\d+)$/)
const match = input.match(/^(cv|rl)(\d+)$/)
if (!match) {
return []
}
const id = match[1]
const indexer = `cv${id}`
const type = match[1]
const id = match[2]
const indexer = `${type}${id}`
if (type === 'rl') {
const json = await getJson(
`https://api.bilibili.com/x/article/list/web/articles?id=${id}`,
)
const { name } = lodash.get(json, 'data.list', {})
return [
{
name: name || indexer,
icon: 'mdi-open-in-new',
indexer,
description: '文集跳转',
action: () => {
window.open(`https://www.bilibili.com/read/readlist/${indexer}`, '_blank')
},
order: 0,
},
]
}
const json = await getJson(`https://api.bilibili.com/x/article/viewinfo?id=${id}`)
const { title } = lodash.get(json, 'data', {})
return [
Expand Down

0 comments on commit d92fb8d

Please sign in to comment.