优化字幕复制

This commit is contained in:
IndieKKY
2024-03-18 19:17:02 +08:00
parent e6db674755
commit 2ba841c8f2
4 changed files with 15 additions and 6 deletions

View File

@@ -66,6 +66,7 @@ const MoreBtn = (props: Props) => {
const [moreVisible, setMoreVisible] = useState(false) const [moreVisible, setMoreVisible] = useState(false)
const eventBus = useContext(EventBusContext) const eventBus = useContext(EventBusContext)
const segments = useAppSelector(state => state.env.segments) const segments = useAppSelector(state => state.env.segments)
const url = useAppSelector(state => state.env.url)
const title = useAppSelector(state => state.env.title) const title = useAppSelector(state => state.env.title)
const curSummaryType = useAppSelector(state => state.env.tempData.curSummaryType) const curSummaryType = useAppSelector(state => state.env.tempData.curSummaryType)
@@ -76,19 +77,19 @@ const MoreBtn = (props: Props) => {
let s, fileName let s, fileName
if (!downloadType || downloadType === 'text') { if (!downloadType || downloadType === 'text') {
s = '' s = `${title??'无标题'}\n${url??'无链接'}\n\n`
for (const item of data.body) { for (const item of data.body) {
s += item.content + '\n' s += item.content + '\n'
} }
fileName = 'download.txt' fileName = 'download.txt'
} else if (downloadType === 'textWithTime') { } else if (downloadType === 'textWithTime') {
s = '' s = `${title??'无标题'}\n${url??'无链接'}\n\n`
for (const item of data.body) { for (const item of data.body) {
s += formatTime(item.from) + ' ' + item.content + '\n' s += formatTime(item.from) + ' ' + item.content + '\n'
} }
fileName = 'download.txt' fileName = 'download.txt'
} else if (downloadType === 'article') { } else if (downloadType === 'article') {
s = '' s = `${title??'无标题'}\n${url??'无链接'}\n\n`
for (const item of data.body) { for (const item of data.body) {
s += item.content + ', ' s += item.content + ', '
} }
@@ -138,9 +139,10 @@ const MoreBtn = (props: Props) => {
s = JSON.stringify(data) s = JSON.stringify(data)
fileName = 'download.json' fileName = 'download.json'
} else if (downloadType === 'summarize') { } else if (downloadType === 'summarize') {
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
const [success, content] = getSummarize(title, segments, curSummaryType) const [success, content] = getSummarize(title, segments, curSummaryType)
if (!success) return if (!success) return
s = content s += content
fileName = '总结.txt' fileName = '总结.txt'
} else { } else {
return return
@@ -153,7 +155,7 @@ const MoreBtn = (props: Props) => {
}).catch(console.error) }).catch(console.error)
} }
setMoreVisible(false) setMoreVisible(false)
}, [curSummaryType, data, downloadType, segments, title]) }, [curSummaryType, data, downloadType, segments, title, url])
const downloadAudioCallback = useCallback(() => { const downloadAudioCallback = useCallback(() => {
window.parent.postMessage({ window.parent.postMessage({

View File

@@ -102,6 +102,7 @@ const refreshVideoInfo = async () => {
//send setVideoInfo //send setVideoInfo
iframe.contentWindow.postMessage({ iframe.contentWindow.postMessage({
type: 'setVideoInfo', type: 'setVideoInfo',
url: location.origin + location.pathname,
title, title,
aid, aid,
pages, pages,

View File

@@ -12,6 +12,7 @@ import {
setSegments, setSegments,
setTitle, setTitle,
setTotalHeight, setTotalHeight,
setUrl,
} from '../redux/envReducer' } from '../redux/envReducer'
import {EventBusContext} from '../Router' import {EventBusContext} from '../Router'
import { import {
@@ -55,6 +56,7 @@ const useSubtitleService = () => {
if (data.type === 'setVideoInfo') { if (data.type === 'setVideoInfo') {
dispatch(setInfos(data.infos)) dispatch(setInfos(data.infos))
dispatch(setUrl(data.url))
dispatch(setTitle(data.title)) dispatch(setTitle(data.title))
console.debug('video title: ', data.title) console.debug('video title: ', data.title)
} }
@@ -86,7 +88,6 @@ const useSubtitleService = () => {
if (data.data.totalHeight) { if (data.data.totalHeight) {
dispatch(setTotalHeight(Math.min(Math.max(data.data.totalHeight, TOTAL_HEIGHT_MIN), TOTAL_HEIGHT_MAX))) dispatch(setTotalHeight(Math.min(Math.max(data.data.totalHeight, TOTAL_HEIGHT_MIN), TOTAL_HEIGHT_MAX)))
} }
console.debug('setSettings', data.data)
} }
} }

View File

@@ -30,6 +30,7 @@ interface EnvState {
data?: Transcript data?: Transcript
uploadedTranscript?: Transcript uploadedTranscript?: Transcript
segments?: Segment[] segments?: Segment[]
url?: string
title?: string title?: string
taskIds?: string[] taskIds?: string[]
@@ -260,6 +261,9 @@ export const slice = createSlice({
setCurrentTime: (state, action: PayloadAction<number | undefined>) => { setCurrentTime: (state, action: PayloadAction<number | undefined>) => {
state.currentTime = action.payload state.currentTime = action.payload
}, },
setUrl: (state, action: PayloadAction<string | undefined>) => {
state.url = action.payload
},
setTitle: (state, action: PayloadAction<string | undefined>) => { setTitle: (state, action: PayloadAction<string | undefined>) => {
state.title = action.payload state.title = action.payload
}, },
@@ -288,6 +292,7 @@ export const slice = createSlice({
}) })
export const { export const {
setUrl,
setAskFold, setAskFold,
setAskQuestion, setAskQuestion,
setAskStatus, setAskStatus,