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 { useAppDispatch, useAppSelector } from './redux'
|
||||||
import { AllAPPMessages, AllExtensionMessages, AllInjectMessages } from '@/message-typings'
|
import { AllAPPMessages, AllExtensionMessages, AllInjectMessages } from '@/message-typings'
|
||||||
import { useMessaging, useMessagingService } from '@kky002/kky-message'
|
import { useMessaging, useMessagingService } from '@kky002/kky-message'
|
||||||
@@ -19,6 +19,7 @@ const useMessageService = () => {
|
|||||||
dispatch(setData(undefined))
|
dispatch(setData(undefined))
|
||||||
},
|
},
|
||||||
SET_VIDEO_INFO: async (params, context: MethodContext) => {
|
SET_VIDEO_INFO: async (params, context: MethodContext) => {
|
||||||
|
dispatch(setChapters(params.chapters))
|
||||||
dispatch(setInfos(params.infos))
|
dispatch(setInfos(params.infos))
|
||||||
dispatch(setUrl(params.url))
|
dispatch(setUrl(params.url))
|
||||||
dispatch(setTitle(params.title))
|
dispatch(setTitle(params.title))
|
||||||
|
@@ -161,6 +161,21 @@ const debug = (...args: any[]) => {
|
|||||||
if (aidOrBvid) {
|
if (aidOrBvid) {
|
||||||
// aid,pages
|
// aid,pages
|
||||||
let cid: string | undefined
|
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
|
let subtitles
|
||||||
if (aidOrBvid.toLowerCase().startsWith('av')) { // avxxx
|
if (aidOrBvid.toLowerCase().startsWith('av')) { // avxxx
|
||||||
aid = parseInt(aidOrBvid.slice(2))
|
aid = parseInt(aidOrBvid.slice(2))
|
||||||
@@ -170,6 +185,7 @@ const debug = (...args: any[]) => {
|
|||||||
author = pages[0].owner?.name
|
author = pages[0].owner?.name
|
||||||
title = pages[0].part
|
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 => {
|
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
|
subtitles = res.data.subtitle.subtitles
|
||||||
})
|
})
|
||||||
} else { // bvxxx
|
} else { // bvxxx
|
||||||
@@ -182,10 +198,14 @@ const debug = (...args: any[]) => {
|
|||||||
pages = res.data.pages
|
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 => {
|
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
|
subtitles = res.data.subtitle.subtitles
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//筛选chapters里type为2的
|
||||||
|
chapters = chapters.filter(chapter => chapter.type === 2)
|
||||||
|
|
||||||
// pagesMap
|
// pagesMap
|
||||||
pagesMap = {}
|
pagesMap = {}
|
||||||
pages.forEach(page => {
|
pages.forEach(page => {
|
||||||
@@ -202,6 +222,7 @@ const debug = (...args: any[]) => {
|
|||||||
ctime,
|
ctime,
|
||||||
author,
|
author,
|
||||||
pages,
|
pages,
|
||||||
|
chapters,
|
||||||
infos: subtitles,
|
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'
|
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'
|
method: 'SET_VIDEO_INFO'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@ interface EnvState {
|
|||||||
totalHeight: number
|
totalHeight: number
|
||||||
curIdx?: number // 从0开始
|
curIdx?: number // 从0开始
|
||||||
needScroll?: boolean
|
needScroll?: boolean
|
||||||
|
chapters?: Chapter[]
|
||||||
infos?: any[]
|
infos?: any[]
|
||||||
curInfo?: any
|
curInfo?: any
|
||||||
curFetched?: boolean
|
curFetched?: boolean
|
||||||
@@ -274,6 +275,9 @@ export const slice = createSlice({
|
|||||||
setAuthor: (state, action: PayloadAction<string | undefined>) => {
|
setAuthor: (state, action: PayloadAction<string | undefined>) => {
|
||||||
state.author = action.payload
|
state.author = action.payload
|
||||||
},
|
},
|
||||||
|
setChapters: (state, action: PayloadAction<Chapter[]>) => {
|
||||||
|
state.chapters = action.payload
|
||||||
|
},
|
||||||
setInfos: (state, action: PayloadAction<any[]>) => {
|
setInfos: (state, action: PayloadAction<any[]>) => {
|
||||||
state.infos = action.payload
|
state.infos = action.payload
|
||||||
},
|
},
|
||||||
@@ -346,6 +350,7 @@ export const {
|
|||||||
mergeAskInfo,
|
mergeAskInfo,
|
||||||
setCtime,
|
setCtime,
|
||||||
setAuthor,
|
setAuthor,
|
||||||
|
setChapters,
|
||||||
} = slice.actions
|
} = slice.actions
|
||||||
|
|
||||||
export default slice.reducer
|
export default slice.reducer
|
||||||
|
6
src/typings.d.ts
vendored
6
src/typings.d.ts
vendored
@@ -88,6 +88,12 @@ interface TranscriptItem {
|
|||||||
idx: number
|
idx: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Chapter {
|
||||||
|
from: number
|
||||||
|
to: number
|
||||||
|
content: string // 标题
|
||||||
|
}
|
||||||
|
|
||||||
interface Segment {
|
interface Segment {
|
||||||
items: TranscriptItem[]
|
items: TranscriptItem[]
|
||||||
startIdx: number // 从1开始
|
startIdx: number // 从1开始
|
||||||
|
Reference in New Issue
Block a user