feat: bilibili video link parser support specific episode selection (#892)

This commit is contained in:
Ye 2023-08-12 07:01:08 +08:00 committed by GitHub
parent 59f406de6f
commit 6efad96133
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -16,12 +16,15 @@ const getTimeValueInSeconds = (timeValue: string) => {
}
const getBilibiliIFrameSrc = (url: URL) => {
const match = url.pathname.match(/\/video\/([A-Za-z0-9]+)\//)
const match = url.pathname.match(/\/video\/([A-Za-z0-9]+)\/?/)
if (!match || match.length < 1) return
const bvid = match[1]
const page = url.searchParams.get('p')
const pageParam = (page) ? `&page=${page}` : ''
const embedUrl = new URL(
`https://player.bilibili.com/player.html?bvid=${bvid}&autoplay=false`,
`https://player.bilibili.com/player.html?bvid=${bvid}&autoplay=false` + pageParam,
)
return embedUrl.toString()