feat: add Bilibili hot video source and related interfaces (#123)
This commit is contained in:
@@ -34,6 +34,60 @@ interface WapRes {
|
||||
total_count: number
|
||||
}
|
||||
|
||||
// Interface for Bilibili Hot Video response
|
||||
interface HotVideoRes {
|
||||
code: number
|
||||
message: string
|
||||
ttl: number
|
||||
data: {
|
||||
list: {
|
||||
aid: number
|
||||
videos: number
|
||||
tid: number
|
||||
tname: string
|
||||
copyright: number
|
||||
pic: string
|
||||
title: string
|
||||
pubdate: number
|
||||
ctime: number
|
||||
desc: string
|
||||
state: number
|
||||
duration: number
|
||||
owner: {
|
||||
mid: number
|
||||
name: string
|
||||
face: string
|
||||
}
|
||||
stat: {
|
||||
view: number
|
||||
danmaku: number
|
||||
reply: number
|
||||
favorite: number
|
||||
coin: number
|
||||
share: number
|
||||
now_rank: number
|
||||
his_rank: number
|
||||
like: number
|
||||
dislike: number
|
||||
}
|
||||
dynamic: string
|
||||
cid: number
|
||||
dimension: {
|
||||
width: number
|
||||
height: number
|
||||
rotate: number
|
||||
}
|
||||
short_link: string
|
||||
short_link_v2: string
|
||||
bvid: string
|
||||
rcmd_reason: {
|
||||
content: string
|
||||
corner_mark: number
|
||||
}
|
||||
}[]
|
||||
}
|
||||
}
|
||||
|
||||
const hotSearch = defineSource(async () => {
|
||||
const url = "https://s.search.bilibili.com/main/hotword?limit=30"
|
||||
const res: WapRes = await myFetch(url)
|
||||
@@ -48,7 +102,32 @@ const hotSearch = defineSource(async () => {
|
||||
}))
|
||||
})
|
||||
|
||||
const hotVideo = defineSource(async () => {
|
||||
const url = "https://api.bilibili.com/x/web-interface/popular"
|
||||
const res: HotVideoRes = await myFetch(url)
|
||||
|
||||
return res.data.list.map(video => ({
|
||||
id: video.bvid,
|
||||
title: video.title,
|
||||
url: `https://www.bilibili.com/video/${video.bvid}`,
|
||||
pubDate: video.pubdate * 1000,
|
||||
extra: {
|
||||
info: `${video.owner.name} · ${formatNumber(video.stat.view)}观看 · ${formatNumber(video.stat.like)}点赞`,
|
||||
hover: video.desc,
|
||||
icon: proxyPicture(video.pic),
|
||||
},
|
||||
}))
|
||||
})
|
||||
|
||||
function formatNumber(num: number): string {
|
||||
if (num >= 10000) {
|
||||
return `${Math.floor(num / 10000)}w+`
|
||||
}
|
||||
return num.toString()
|
||||
}
|
||||
|
||||
export default defineSource({
|
||||
"bilibili": hotSearch,
|
||||
"bilibili-hot-search": hotSearch,
|
||||
"bilibili-hot-video": hotVideo,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user