You've already forked bilibili-subtitle
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0a6bda667e | ||
![]() |
5a0a123af9 | ||
![]() |
b481b8a55a | ||
![]() |
3cede8650d |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "bilibili-subtitle",
|
"name": "bilibili-subtitle",
|
||||||
"version": "1.11.4",
|
"version": "1.11.6",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "哔哩哔哩字幕列表",
|
"description": "哔哩哔哩字幕列表",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
"ahooks": "^3.7.1",
|
"ahooks": "^3.7.1",
|
||||||
"classnames": "^2.3.2",
|
"classnames": "^2.3.2",
|
||||||
"daisyui": "^2.42.1",
|
"daisyui": "^2.42.1",
|
||||||
|
"dayjs": "^1.11.13",
|
||||||
"js-search": "^2.0.0",
|
"js-search": "^2.0.0",
|
||||||
"less": "^4.1.3",
|
"less": "^4.1.3",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
|
13
pnpm-lock.yaml
generated
13
pnpm-lock.yaml
generated
@@ -41,6 +41,9 @@ importers:
|
|||||||
daisyui:
|
daisyui:
|
||||||
specifier: ^2.42.1
|
specifier: ^2.42.1
|
||||||
version: 2.42.1(autoprefixer@10.4.13(postcss@8.4.19))(postcss@8.4.19)
|
version: 2.42.1(autoprefixer@10.4.13(postcss@8.4.19))(postcss@8.4.19)
|
||||||
|
dayjs:
|
||||||
|
specifier: ^1.11.13
|
||||||
|
version: 1.11.13
|
||||||
js-search:
|
js-search:
|
||||||
specifier: ^2.0.0
|
specifier: ^2.0.0
|
||||||
version: 2.0.0
|
version: 2.0.0
|
||||||
@@ -856,8 +859,8 @@ packages:
|
|||||||
autoprefixer: ^10.0.2
|
autoprefixer: ^10.0.2
|
||||||
postcss: ^8.1.6
|
postcss: ^8.1.6
|
||||||
|
|
||||||
dayjs@1.11.5:
|
dayjs@1.11.13:
|
||||||
resolution: {integrity: sha512-CAdX5Q3YW3Gclyo5Vpqkgpj8fSdLQcRuzfX6mC6Phy0nfJ0eGYOeS7m4mt2plDWLAtA4TqTakvbboHvUxfe4iA==}
|
resolution: {integrity: sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==}
|
||||||
|
|
||||||
debug@2.6.9:
|
debug@2.6.9:
|
||||||
resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==}
|
resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==}
|
||||||
@@ -3114,7 +3117,7 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@types/js-cookie': 2.2.7
|
'@types/js-cookie': 2.2.7
|
||||||
ahooks-v3-count: 1.0.0
|
ahooks-v3-count: 1.0.0
|
||||||
dayjs: 1.11.5
|
dayjs: 1.11.13
|
||||||
intersection-observer: 0.12.2
|
intersection-observer: 0.12.2
|
||||||
js-cookie: 2.2.1
|
js-cookie: 2.2.1
|
||||||
lodash: 4.17.21
|
lodash: 4.17.21
|
||||||
@@ -3126,7 +3129,7 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@types/js-cookie': 2.2.7
|
'@types/js-cookie': 2.2.7
|
||||||
ahooks-v3-count: 1.0.0
|
ahooks-v3-count: 1.0.0
|
||||||
dayjs: 1.11.5
|
dayjs: 1.11.13
|
||||||
intersection-observer: 0.12.2
|
intersection-observer: 0.12.2
|
||||||
js-cookie: 2.2.1
|
js-cookie: 2.2.1
|
||||||
lodash: 4.17.21
|
lodash: 4.17.21
|
||||||
@@ -3385,7 +3388,7 @@ snapshots:
|
|||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- ts-node
|
- ts-node
|
||||||
|
|
||||||
dayjs@1.11.5: {}
|
dayjs@1.11.13: {}
|
||||||
|
|
||||||
debug@2.6.9:
|
debug@2.6.9:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
43
src/components/DebateChat.tsx
Normal file
43
src/components/DebateChat.tsx
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { useAppSelector } from '@/hooks/redux';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
const DebateChat: React.FC<DebateProps> = ({ messages }) => {
|
||||||
|
const fontSize = useAppSelector(state => state.env.envData.fontSize)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col h-full">
|
||||||
|
<div className="flex-1 overflow-y-auto p-4">
|
||||||
|
{messages.map((message, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className={`flex mb-4 ${
|
||||||
|
message.side === 'pro' ? 'justify-start' : 'justify-end'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={`max-w-[85%] rounded-2xl p-3 shadow-md relative ${
|
||||||
|
message.side === 'pro'
|
||||||
|
? 'bg-blue-100 text-blue-800 ml-2'
|
||||||
|
: 'bg-green-100 text-green-800 mr-2'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<p className={`${fontSize === 'large' ? 'text-sm' : 'text-xs'} font-bold mb-1`}>
|
||||||
|
{message.side === 'pro' ? '正方' : '反方'}
|
||||||
|
</p>
|
||||||
|
<p className={fontSize === 'large' ? 'text-sm' : 'text-xs'}>{message.content}</p>
|
||||||
|
<div
|
||||||
|
className={`absolute w-4 h-4 ${
|
||||||
|
message.side === 'pro'
|
||||||
|
? 'bg-blue-100 -left-2 top-2 rounded-bl-full'
|
||||||
|
: 'bg-green-100 -right-2 top-2 rounded-br-full'
|
||||||
|
}`}
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DebateChat;
|
@@ -19,6 +19,8 @@ import {downloadText, openUrl} from '@kky002/kky-util'
|
|||||||
import toast from 'react-hot-toast'
|
import toast from 'react-hot-toast'
|
||||||
import {getSummarize} from '../utils/bizUtil'
|
import {getSummarize} from '../utils/bizUtil'
|
||||||
import { useMessage } from '@/hooks/message'
|
import { useMessage } from '@/hooks/message'
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
placement: Placement
|
placement: Placement
|
||||||
}
|
}
|
||||||
@@ -68,6 +70,8 @@ const MoreBtn = (props: Props) => {
|
|||||||
const segments = useAppSelector(state => state.env.segments)
|
const segments = useAppSelector(state => state.env.segments)
|
||||||
const url = useAppSelector(state => state.env.url)
|
const url = useAppSelector(state => state.env.url)
|
||||||
const title = useAppSelector(state => state.env.title)
|
const title = useAppSelector(state => state.env.title)
|
||||||
|
const ctime = useAppSelector(state => state.env.ctime) //时间戳,单位s
|
||||||
|
const author = useAppSelector(state => state.env.author)
|
||||||
const curSummaryType = useAppSelector(state => state.env.tempData.curSummaryType)
|
const curSummaryType = useAppSelector(state => state.env.tempData.curSummaryType)
|
||||||
|
|
||||||
const {sendInject} = useMessage()
|
const {sendInject} = useMessage()
|
||||||
@@ -79,20 +83,21 @@ const MoreBtn = (props: Props) => {
|
|||||||
|
|
||||||
let fileName = title
|
let fileName = title
|
||||||
let s, suffix
|
let s, suffix
|
||||||
|
let time = ctime ? dayjs(ctime * 1000).format('YYYY-MM-DD HH:mm:ss') : '' // 2024-05-01 12:00:00
|
||||||
if (!downloadType || downloadType === 'text') {
|
if (!downloadType || downloadType === 'text') {
|
||||||
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
|
s = `${title??'无标题'}\n${url??'无链接'}\n${author??'无作者'} ${time}\n\n`
|
||||||
for (const item of data.body) {
|
for (const item of data.body) {
|
||||||
s += item.content + '\n'
|
s += item.content + '\n'
|
||||||
}
|
}
|
||||||
suffix = 'txt'
|
suffix = 'txt'
|
||||||
} else if (downloadType === 'textWithTime') {
|
} else if (downloadType === 'textWithTime') {
|
||||||
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
|
s = `${title??'无标题'}\n${url??'无链接'}\n${author??'无作者'} ${time}\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'
|
||||||
}
|
}
|
||||||
suffix = 'txt'
|
suffix = 'txt'
|
||||||
} else if (downloadType === 'article') {
|
} else if (downloadType === 'article') {
|
||||||
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
|
s = `${title??'无标题'}\n${url??'无链接'}\n${author??'无作者'} ${time}\n\n`
|
||||||
for (const item of data.body) {
|
for (const item of data.body) {
|
||||||
s += item.content + ', '
|
s += item.content + ', '
|
||||||
}
|
}
|
||||||
@@ -142,7 +147,7 @@ const MoreBtn = (props: Props) => {
|
|||||||
s = JSON.stringify(data)
|
s = JSON.stringify(data)
|
||||||
suffix = 'json'
|
suffix = 'json'
|
||||||
} else if (downloadType === 'summarize') {
|
} else if (downloadType === 'summarize') {
|
||||||
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
|
s = `${title??'无标题'}\n${url??'无链接'}\n${author??'无作者'} ${time}\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
|
||||||
|
@@ -2,7 +2,7 @@ import React, {MutableRefObject, useCallback, useEffect, useMemo, useRef} from '
|
|||||||
import {useAppDispatch, useAppSelector} from '../hooks/redux'
|
import {useAppDispatch, useAppSelector} from '../hooks/redux'
|
||||||
import {setFloatKeyPointsSegIdx, setSegmentFold, setTempData} from '../redux/envReducer'
|
import {setFloatKeyPointsSegIdx, setSegmentFold, setTempData} from '../redux/envReducer'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
import {FaClipboardList} from 'react-icons/fa'
|
import {FaClipboardList, FaComments} from 'react-icons/fa'
|
||||||
import {PAGE_MAIN, PAGE_SETTINGS, SUMMARIZE_THRESHOLD, SUMMARIZE_TYPES} from '../consts/const'
|
import {PAGE_MAIN, PAGE_SETTINGS, SUMMARIZE_THRESHOLD, SUMMARIZE_TYPES} from '../consts/const'
|
||||||
import useTranslate from '../hooks/useTranslate'
|
import useTranslate from '../hooks/useTranslate'
|
||||||
import {BsDashSquare, BsPlusSquare, CgFileDocument, FaQuestion, GrOverview, RiFileCopy2Line} from 'react-icons/all'
|
import {BsDashSquare, BsPlusSquare, CgFileDocument, FaQuestion, GrOverview, RiFileCopy2Line} from 'react-icons/all'
|
||||||
@@ -12,6 +12,7 @@ import {useInViewport} from 'ahooks'
|
|||||||
import SegmentItem from './SegmentItem'
|
import SegmentItem from './SegmentItem'
|
||||||
import {stopPopFunc} from '../utils/util'
|
import {stopPopFunc} from '../utils/util'
|
||||||
import useSubtitle from '../hooks/useSubtitle'
|
import useSubtitle from '../hooks/useSubtitle'
|
||||||
|
import DebateChat from './DebateChat'
|
||||||
|
|
||||||
const SummarizeItemOverview = (props: {
|
const SummarizeItemOverview = (props: {
|
||||||
segment: Segment
|
segment: Segment
|
||||||
@@ -113,6 +114,8 @@ const Summarize = (props: {
|
|||||||
<div className={classNames('font-normal', fontSize === 'large' ? 'text-sm' : 'text-xs')}>{question.a}</div>
|
<div className={classNames('font-normal', fontSize === 'large' ? 'text-sm' : 'text-xs')}>{question.a}</div>
|
||||||
</div>)}
|
</div>)}
|
||||||
</div>}
|
</div>}
|
||||||
|
{summary?.type === 'debate' && (summary.content != null) &&
|
||||||
|
<DebateChat messages={summary.content} />}
|
||||||
</div>
|
</div>
|
||||||
<div className='flex flex-col justify-center items-center'>
|
<div className='flex flex-col justify-center items-center'>
|
||||||
{segment.text.length < SUMMARIZE_THRESHOLD && <div className='desc-lighter text-xs'>文字过短,无法总结.</div>}
|
{segment.text.length < SUMMARIZE_THRESHOLD && <div className='desc-lighter text-xs'>文字过短,无法总结.</div>}
|
||||||
@@ -200,6 +203,12 @@ const SegmentCard = (props: {
|
|||||||
}))
|
}))
|
||||||
}, [dispatch])
|
}, [dispatch])
|
||||||
|
|
||||||
|
const onSelDebate = useCallback(() => {
|
||||||
|
dispatch(setTempData({
|
||||||
|
curSummaryType: 'debate'
|
||||||
|
}))
|
||||||
|
}, [dispatch])
|
||||||
|
|
||||||
return <div
|
return <div
|
||||||
className={classNames('border border-base-300 bg-base-200/25 rounded flex flex-col m-1.5 p-1.5 gap-1 shadow', showCurrent && 'shadow-primary')}>
|
className={classNames('border border-base-300 bg-base-200/25 rounded flex flex-col m-1.5 p-1.5 gap-1 shadow', showCurrent && 'shadow-primary')}>
|
||||||
<div className='relative flex justify-center min-h-[20px]'>
|
<div className='relative flex justify-center min-h-[20px]'>
|
||||||
@@ -215,6 +224,7 @@ const SegmentCard = (props: {
|
|||||||
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'overview' && 'tab-active')} onClick={onSelOverview}><GrOverview/>概览</a>
|
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'overview' && 'tab-active')} onClick={onSelOverview}><GrOverview/>概览</a>
|
||||||
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'keypoint' && 'tab-active')} onClick={onSelKeypoint}><FaClipboardList/>要点</a>
|
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'keypoint' && 'tab-active')} onClick={onSelKeypoint}><FaClipboardList/>要点</a>
|
||||||
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'question' && 'tab-active')} onClick={onSelQuestion}><FaQuestion/>问题</a>
|
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'question' && 'tab-active')} onClick={onSelQuestion}><FaQuestion/>问题</a>
|
||||||
|
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'debate' && 'tab-active')} onClick={onSelDebate}><FaComments/>辩论</a>
|
||||||
<a className="tab tab-lifted tab-xs tab-disabled cursor-default"></a>
|
<a className="tab tab-lifted tab-xs tab-disabled cursor-default"></a>
|
||||||
</div>}
|
</div>}
|
||||||
<div
|
<div
|
||||||
|
@@ -11,6 +11,7 @@ export const PROMPT_TYPE_TRANSLATE = 'translate'
|
|||||||
export const PROMPT_TYPE_SUMMARIZE_OVERVIEW = 'summarize_overview'
|
export const PROMPT_TYPE_SUMMARIZE_OVERVIEW = 'summarize_overview'
|
||||||
export const PROMPT_TYPE_SUMMARIZE_KEYPOINT = 'summarize_keypoint'
|
export const PROMPT_TYPE_SUMMARIZE_KEYPOINT = 'summarize_keypoint'
|
||||||
export const PROMPT_TYPE_SUMMARIZE_QUESTION = 'summarize_question'
|
export const PROMPT_TYPE_SUMMARIZE_QUESTION = 'summarize_question'
|
||||||
|
export const PROMPT_TYPE_SUMMARIZE_DEBATE = 'summarize_debate'
|
||||||
export const PROMPT_TYPE_SUMMARIZE_BRIEF = 'summarize_brief'
|
export const PROMPT_TYPE_SUMMARIZE_BRIEF = 'summarize_brief'
|
||||||
export const PROMPT_TYPE_ASK = 'ask'
|
export const PROMPT_TYPE_ASK = 'ask'
|
||||||
export const PROMPT_TYPES = [{
|
export const PROMPT_TYPES = [{
|
||||||
@@ -28,6 +29,9 @@ export const PROMPT_TYPES = [{
|
|||||||
}, {
|
}, {
|
||||||
name: '问题',
|
name: '问题',
|
||||||
type: PROMPT_TYPE_SUMMARIZE_QUESTION,
|
type: PROMPT_TYPE_SUMMARIZE_QUESTION,
|
||||||
|
}, {
|
||||||
|
name: '辩论',
|
||||||
|
type: PROMPT_TYPE_SUMMARIZE_DEBATE,
|
||||||
}, {
|
}, {
|
||||||
name: '提问',
|
name: '提问',
|
||||||
type: PROMPT_TYPE_ASK,
|
type: PROMPT_TYPE_ASK,
|
||||||
@@ -58,6 +62,12 @@ export const SUMMARIZE_TYPES = {
|
|||||||
downloadName: '💡常见问题💡',
|
downloadName: '💡常见问题💡',
|
||||||
promptType: PROMPT_TYPE_SUMMARIZE_QUESTION,
|
promptType: PROMPT_TYPE_SUMMARIZE_QUESTION,
|
||||||
},
|
},
|
||||||
|
debate: {
|
||||||
|
name: '辩论',
|
||||||
|
desc: '辩论',
|
||||||
|
downloadName: '💡辩论💡',
|
||||||
|
promptType: PROMPT_TYPE_SUMMARIZE_DEBATE,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PROMPT_DEFAULTS = {
|
export const PROMPT_DEFAULTS = {
|
||||||
@@ -175,6 +185,42 @@ Provide an example to illustrate the expected output:
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
`,
|
||||||
|
[PROMPT_TYPE_SUMMARIZE_DEBATE]: `You are a helpful assistant skilled at generating debates based on video subtitles.
|
||||||
|
|
||||||
|
## Context
|
||||||
|
|
||||||
|
The video's title: '''{{title}}'''.
|
||||||
|
The video's subtitles:
|
||||||
|
|
||||||
|
'''
|
||||||
|
{{segment}}
|
||||||
|
'''
|
||||||
|
|
||||||
|
## Command
|
||||||
|
|
||||||
|
Please play the roles of both the affirmative and negative sides to discuss the author's viewpoint.
|
||||||
|
The conversation should consist of 10 rounds(5 sentences from the affirmative side, 5 sentences from the negative side.).
|
||||||
|
The tone should be straightforward.
|
||||||
|
|
||||||
|
Answer in language '{{language}}'.
|
||||||
|
|
||||||
|
## Output format
|
||||||
|
|
||||||
|
Provide an example to illustrate the expected output:
|
||||||
|
|
||||||
|
\`\`\`json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"side": "pro",
|
||||||
|
"content": "xxx"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"side": "con",
|
||||||
|
"content": "xxx"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
\`\`\`
|
||||||
`,
|
`,
|
||||||
[PROMPT_TYPE_ASK]: `You are a helpful assistant who answers question related to video subtitles.
|
[PROMPT_TYPE_ASK]: `You are a helpful assistant who answers question related to video subtitles.
|
||||||
Answer in language '{{language}}'.
|
Answer in language '{{language}}'.
|
||||||
@@ -245,6 +291,9 @@ for (const model of MODELS) {
|
|||||||
export const LANGUAGES = [{
|
export const LANGUAGES = [{
|
||||||
code: 'en',
|
code: 'en',
|
||||||
name: 'English',
|
name: 'English',
|
||||||
|
}, {
|
||||||
|
code: 'ja',
|
||||||
|
name: '日本語',
|
||||||
}, {
|
}, {
|
||||||
code: 'ena',
|
code: 'ena',
|
||||||
name: 'American English',
|
name: 'American English',
|
||||||
@@ -278,6 +327,39 @@ export const LANGUAGES = [{
|
|||||||
}, {
|
}, {
|
||||||
code: 'Italian',
|
code: 'Italian',
|
||||||
name: 'Italiano',
|
name: 'Italiano',
|
||||||
|
}, {
|
||||||
|
code: 'ko',
|
||||||
|
name: '한국어',
|
||||||
|
}, {
|
||||||
|
code: 'hi',
|
||||||
|
name: 'हिन्दी',
|
||||||
|
}, {
|
||||||
|
code: 'tr',
|
||||||
|
name: 'Türkçe',
|
||||||
|
}, {
|
||||||
|
code: 'nl',
|
||||||
|
name: 'Nederlands',
|
||||||
|
}, {
|
||||||
|
code: 'pl',
|
||||||
|
name: 'Polski',
|
||||||
|
}, {
|
||||||
|
code: 'sv',
|
||||||
|
name: 'Svenska',
|
||||||
|
}, {
|
||||||
|
code: 'vi',
|
||||||
|
name: 'Tiếng Việt',
|
||||||
|
}, {
|
||||||
|
code: 'th',
|
||||||
|
name: 'ไทย',
|
||||||
|
}, {
|
||||||
|
code: 'id',
|
||||||
|
name: 'Bahasa Indonesia',
|
||||||
|
}, {
|
||||||
|
code: 'el',
|
||||||
|
name: 'Ελληνικά',
|
||||||
|
}, {
|
||||||
|
code: 'he',
|
||||||
|
name: 'עברית',
|
||||||
}]
|
}]
|
||||||
export const LANGUAGES_MAP: {[key: string]: typeof LANGUAGES[number]} = {}
|
export const LANGUAGES_MAP: {[key: string]: typeof LANGUAGES[number]} = {}
|
||||||
for (const language of LANGUAGES) {
|
for (const language of LANGUAGES) {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { setCurFetched, setCurInfo, setData, setInfos, setTitle, setUrl } from '@/redux/envReducer'
|
import { setAuthor, setCtime, setCurFetched, setCurInfo, setData, setInfos, setTitle, setUrl } from '@/redux/envReducer'
|
||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import { useAppDispatch } from './redux'
|
import { useAppDispatch } from './redux'
|
||||||
import useMessagingService from '@/messaging/layer2/useMessagingService'
|
import useMessagingService from '@/messaging/layer2/useMessagingService'
|
||||||
@@ -20,6 +20,8 @@ const useMessageService = () => {
|
|||||||
dispatch(setInfos(params.infos))
|
dispatch(setInfos(params.infos))
|
||||||
dispatch(setUrl(params.url))
|
dispatch(setUrl(params.url))
|
||||||
dispatch(setTitle(params.title))
|
dispatch(setTitle(params.title))
|
||||||
|
dispatch(setCtime(params.ctime))
|
||||||
|
dispatch(setAuthor(params.author))
|
||||||
console.debug('video title: ', params.title)
|
console.debug('video title: ', params.title)
|
||||||
},
|
},
|
||||||
}), [dispatch])
|
}), [dispatch])
|
||||||
|
@@ -120,6 +120,8 @@ const debug = (...args: any[]) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let aid: number | null = null
|
let aid: number | null = null
|
||||||
|
let ctime: number | null = null
|
||||||
|
let author: string | undefined
|
||||||
let title = ''
|
let title = ''
|
||||||
let pages: any[] = []
|
let pages: any[] = []
|
||||||
let pagesMap: Record<string, any> = {}
|
let pagesMap: Record<string, any> = {}
|
||||||
@@ -162,6 +164,8 @@ const debug = (...args: any[]) => {
|
|||||||
aid = parseInt(aidOrBvid.slice(2))
|
aid = parseInt(aidOrBvid.slice(2))
|
||||||
pages = await fetch(`https://api.bilibili.com/x/player/pagelist?aid=${aid}`, { credentials: 'include' }).then(res => res.json()).then(res => res.data)
|
pages = await fetch(`https://api.bilibili.com/x/player/pagelist?aid=${aid}`, { credentials: 'include' }).then(res => res.json()).then(res => res.data)
|
||||||
cid = pages[0].cid
|
cid = pages[0].cid
|
||||||
|
ctime = pages[0].ctime
|
||||||
|
author = pages[0].owner?.name
|
||||||
title = pages[0].part
|
title = pages[0].part
|
||||||
await fetch(`https://api.bilibili.com/x/player/v2?aid=${aid}&cid=${cid}`, { credentials: 'include' }).then(res => res.json()).then(res => {
|
await fetch(`https://api.bilibili.com/x/player/v2?aid=${aid}&cid=${cid}`, { credentials: 'include' }).then(res => res.json()).then(res => {
|
||||||
subtitles = res.data.subtitle.subtitles
|
subtitles = res.data.subtitle.subtitles
|
||||||
@@ -171,6 +175,8 @@ const debug = (...args: any[]) => {
|
|||||||
title = res.data.title
|
title = res.data.title
|
||||||
aid = res.data.aid
|
aid = res.data.aid
|
||||||
cid = res.data.cid
|
cid = res.data.cid
|
||||||
|
ctime = res.data.ctime
|
||||||
|
author = res.data.owner?.name
|
||||||
pages = res.data.pages
|
pages = res.data.pages
|
||||||
})
|
})
|
||||||
await fetch(`https://api.bilibili.com/x/player/v2?aid=${aid}&cid=${cid}`, { credentials: 'include' }).then(res => res.json()).then(res => {
|
await fetch(`https://api.bilibili.com/x/player/v2?aid=${aid}&cid=${cid}`, { credentials: 'include' }).then(res => res.json()).then(res => {
|
||||||
@@ -191,6 +197,8 @@ const debug = (...args: any[]) => {
|
|||||||
url: location.origin + location.pathname,
|
url: location.origin + location.pathname,
|
||||||
title,
|
title,
|
||||||
aid,
|
aid,
|
||||||
|
ctime,
|
||||||
|
author,
|
||||||
pages,
|
pages,
|
||||||
infos: subtitles,
|
infos: subtitles,
|
||||||
})
|
})
|
||||||
|
2
src/message-typings.d.ts
vendored
2
src/message-typings.d.ts
vendored
@@ -80,7 +80,7 @@ interface ExtensionCloseSidePanelMessage extends ExtensionMessage {
|
|||||||
method: 'SET_INFOS';
|
method: 'SET_INFOS';
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AppSetVideoInfoMessage extends AppMessage<{ url: string, title: string, aid: number | null, pages: any, infos: any }> {
|
interface AppSetVideoInfoMessage extends AppMessage<{ url: string, title: string, aid: number | null, ctime: number | null, author?: string, pages: any, infos: any }> {
|
||||||
method: 'SET_VIDEO_INFO';
|
method: 'SET_VIDEO_INFO';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,7 +32,8 @@ interface EnvState {
|
|||||||
segments?: Segment[]
|
segments?: Segment[]
|
||||||
url?: string
|
url?: string
|
||||||
title?: string
|
title?: string
|
||||||
|
ctime?: number | null
|
||||||
|
author?: string
|
||||||
taskIds?: string[]
|
taskIds?: string[]
|
||||||
transResults: { [key: number]: TransResult }
|
transResults: { [key: number]: TransResult }
|
||||||
lastTransTime?: number
|
lastTransTime?: number
|
||||||
@@ -271,6 +272,12 @@ export const slice = createSlice({
|
|||||||
setTitle: (state, action: PayloadAction<string | undefined>) => {
|
setTitle: (state, action: PayloadAction<string | undefined>) => {
|
||||||
state.title = action.payload
|
state.title = action.payload
|
||||||
},
|
},
|
||||||
|
setCtime: (state, action: PayloadAction<number | null | undefined>) => {
|
||||||
|
state.ctime = action.payload
|
||||||
|
},
|
||||||
|
setAuthor: (state, action: PayloadAction<string | undefined>) => {
|
||||||
|
state.author = action.payload
|
||||||
|
},
|
||||||
setInfos: (state, action: PayloadAction<any[]>) => {
|
setInfos: (state, action: PayloadAction<any[]>) => {
|
||||||
state.infos = action.payload
|
state.infos = action.payload
|
||||||
},
|
},
|
||||||
@@ -342,6 +349,8 @@ export const {
|
|||||||
addAskInfo,
|
addAskInfo,
|
||||||
delAskInfo,
|
delAskInfo,
|
||||||
mergeAskInfo,
|
mergeAskInfo,
|
||||||
|
setCtime,
|
||||||
|
setAuthor,
|
||||||
} = slice.actions
|
} = slice.actions
|
||||||
|
|
||||||
export default slice.reducer
|
export default slice.reducer
|
||||||
|
11
src/typings.d.ts
vendored
11
src/typings.d.ts
vendored
@@ -151,4 +151,13 @@ interface BriefSummary extends Summary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SummaryStatus = 'init' | 'pending' | 'done'
|
type SummaryStatus = 'init' | 'pending' | 'done'
|
||||||
type SummaryType = 'overview' | 'keypoint' | 'brief' | 'question'
|
type SummaryType = 'overview' | 'keypoint' | 'brief' | 'question' | 'debate'
|
||||||
|
|
||||||
|
interface DebateMessage {
|
||||||
|
side: 'pro' | 'con';
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DebateProps {
|
||||||
|
messages: DebateMessage[];
|
||||||
|
}
|
||||||
|
@@ -81,6 +81,9 @@ export const isSummaryEmpty = (summary: Summary) => {
|
|||||||
} else if (summary.type === 'question') {
|
} else if (summary.type === 'question') {
|
||||||
const content: any[] = summary.content??[]
|
const content: any[] = summary.content??[]
|
||||||
return content.length === 0
|
return content.length === 0
|
||||||
|
} else if (summary.type === 'debate') {
|
||||||
|
const content: Array<{ side: string, content: string }> = summary.content ?? []
|
||||||
|
return content.length === 0
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -107,7 +110,12 @@ export const getSummaryStr = (summary: Summary) => {
|
|||||||
s += content.map(item => {
|
s += content.map(item => {
|
||||||
return item.q + '\n' + item.a + '\n'
|
return item.q + '\n' + item.a + '\n'
|
||||||
}).join('\n')
|
}).join('\n')
|
||||||
}
|
} else if (summary.type === 'debate') {
|
||||||
|
const content: Array<{ side: string, content: string }> = summary.content ?? []
|
||||||
|
s += content.map(item => {
|
||||||
|
return (item.side === 'pro'?'正方:':'反方:') + item.content + '\n'
|
||||||
|
}).join('\n')
|
||||||
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user