You've already forked bilibili-subtitle
获取章节列表
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { setAuthor, setCtime, setCurFetched, setCurInfo, setData, setInfos, setTitle, setUrl } from '@/redux/envReducer'
|
||||
import { setAuthor, setChapters, setCtime, setCurFetched, setCurInfo, setData, setInfos, setTitle, setUrl } from '@/redux/envReducer'
|
||||
import { useAppDispatch, useAppSelector } from './redux'
|
||||
import { AllAPPMessages, AllExtensionMessages, AllInjectMessages } from '@/message-typings'
|
||||
import { useMessaging, useMessagingService } from '@kky002/kky-message'
|
||||
@@ -19,6 +19,7 @@ const useMessageService = () => {
|
||||
dispatch(setData(undefined))
|
||||
},
|
||||
SET_VIDEO_INFO: async (params, context: MethodContext) => {
|
||||
dispatch(setChapters(params.chapters))
|
||||
dispatch(setInfos(params.infos))
|
||||
dispatch(setUrl(params.url))
|
||||
dispatch(setTitle(params.title))
|
||||
|
@@ -161,6 +161,21 @@ const debug = (...args: any[]) => {
|
||||
if (aidOrBvid) {
|
||||
// aid,pages
|
||||
let cid: string | undefined
|
||||
/**
|
||||
* [
|
||||
{
|
||||
"type": 2,
|
||||
"from": 0,
|
||||
"to": 152, //单位秒
|
||||
"content": "发现美",
|
||||
"imgUrl": "http://i0.hdslb.com/bfs/vchapter/29168372111_0.jpg",
|
||||
"logoUrl": "",
|
||||
"team_type": "",
|
||||
"team_name": ""
|
||||
}
|
||||
]
|
||||
*/
|
||||
let chapters: any[] = []
|
||||
let subtitles
|
||||
if (aidOrBvid.toLowerCase().startsWith('av')) { // avxxx
|
||||
aid = parseInt(aidOrBvid.slice(2))
|
||||
@@ -170,6 +185,7 @@ const debug = (...args: any[]) => {
|
||||
author = pages[0].owner?.name
|
||||
title = pages[0].part
|
||||
await fetch(`https://api.bilibili.com/x/player/wbi/v2?aid=${aid}&cid=${cid!}`, { credentials: 'include' }).then(async res => await res.json()).then(res => {
|
||||
chapters = res.data.view_points ?? []
|
||||
subtitles = res.data.subtitle.subtitles
|
||||
})
|
||||
} else { // bvxxx
|
||||
@@ -182,10 +198,14 @@ const debug = (...args: any[]) => {
|
||||
pages = res.data.pages
|
||||
})
|
||||
await fetch(`https://api.bilibili.com/x/player/wbi/v2?aid=${aid!}&cid=${cid!}`, { credentials: 'include' }).then(async res => await res.json()).then(res => {
|
||||
chapters = res.data.view_points ?? []
|
||||
subtitles = res.data.subtitle.subtitles
|
||||
})
|
||||
}
|
||||
|
||||
//筛选chapters里type为2的
|
||||
chapters = chapters.filter(chapter => chapter.type === 2)
|
||||
|
||||
// pagesMap
|
||||
pagesMap = {}
|
||||
pages.forEach(page => {
|
||||
@@ -202,6 +222,7 @@ const debug = (...args: any[]) => {
|
||||
ctime,
|
||||
author,
|
||||
pages,
|
||||
chapters,
|
||||
infos: subtitles,
|
||||
})
|
||||
}
|
||||
|
2
src/message-typings.d.ts
vendored
2
src/message-typings.d.ts
vendored
@@ -80,7 +80,7 @@ interface AppSetInfosMessage extends AppMessage<{ infos: any }> {
|
||||
method: 'SET_INFOS'
|
||||
}
|
||||
|
||||
interface AppSetVideoInfoMessage extends AppMessage<{ url: string, title: string, aid: number | null, ctime: number | null, author?: string, pages: any, infos: any }> {
|
||||
interface AppSetVideoInfoMessage extends AppMessage<{ url: string, title: string, aid: number | null, ctime: number | null, author?: string, pages: any, chapters: any, infos: any }> {
|
||||
method: 'SET_VIDEO_INFO'
|
||||
}
|
||||
|
||||
|
@@ -23,6 +23,7 @@ interface EnvState {
|
||||
totalHeight: number
|
||||
curIdx?: number // 从0开始
|
||||
needScroll?: boolean
|
||||
chapters?: Chapter[]
|
||||
infos?: any[]
|
||||
curInfo?: any
|
||||
curFetched?: boolean
|
||||
@@ -274,6 +275,9 @@ export const slice = createSlice({
|
||||
setAuthor: (state, action: PayloadAction<string | undefined>) => {
|
||||
state.author = action.payload
|
||||
},
|
||||
setChapters: (state, action: PayloadAction<Chapter[]>) => {
|
||||
state.chapters = action.payload
|
||||
},
|
||||
setInfos: (state, action: PayloadAction<any[]>) => {
|
||||
state.infos = action.payload
|
||||
},
|
||||
@@ -346,6 +350,7 @@ export const {
|
||||
mergeAskInfo,
|
||||
setCtime,
|
||||
setAuthor,
|
||||
setChapters,
|
||||
} = slice.actions
|
||||
|
||||
export default slice.reducer
|
||||
|
6
src/typings.d.ts
vendored
6
src/typings.d.ts
vendored
@@ -88,6 +88,12 @@ interface TranscriptItem {
|
||||
idx: number
|
||||
}
|
||||
|
||||
interface Chapter {
|
||||
from: number
|
||||
to: number
|
||||
content: string // 标题
|
||||
}
|
||||
|
||||
interface Segment {
|
||||
items: TranscriptItem[]
|
||||
startIdx: number // 从1开始
|
||||
|
Reference in New Issue
Block a user