Skip to content

Commit

Permalink
Add downloadDanmaku speed option (fix #4824)
Browse files Browse the repository at this point in the history
  • Loading branch information
the1812 committed Oct 14, 2024
1 parent 866ef53 commit f0d5f17
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions registry/lib/components/video/danmaku/download/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Toast } from '@/core/toast'
import { videoAndBangumiUrls } from '@/core/utils/urls'
import { DownloadVideoAssets } from '../../download/types'
import { DanmakuDownloadType } from './utils'
import { downloadDanmakuOptions } from './options'

export const component = defineComponentMetadata({
name: 'downloadDanmaku',
Expand All @@ -17,6 +18,7 @@ export const component = defineComponentMetadata({
entry: none,
reload: none,
unload: none,
options: downloadDanmakuOptions,
plugin: {
displayName: '下载视频 - 下载弹幕支持',
setup: ({ addData }) => {
Expand Down
10 changes: 10 additions & 0 deletions registry/lib/components/video/danmaku/download/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineOptionsMetadata, OptionsOfMetadata } from '@/components/define'

export const downloadDanmakuOptions = defineOptionsMetadata({
speed: {
defaultValue: 'auto' as 'auto' | number,
hidden: true,
},
})

export type DownloadDanmakuOptions = OptionsOfMetadata<typeof downloadDanmakuOptions>
10 changes: 9 additions & 1 deletion registry/lib/components/video/danmaku/download/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { DanmakuConverterConfig, DanmakuConverter } from '../converter/danmaku-c
import { DanmakuType } from '../converter/danmaku-type'
import { XmlDanmaku } from '../converter/xml-danmaku'
import { playerAgent } from '@/components/video/player-agent'
import { getComponentSettings } from '@/core/settings'
import { DownloadDanmakuOptions } from './options'

export class JsonDanmaku {
// static SegmentSize = 6 * 60
Expand Down Expand Up @@ -71,6 +73,8 @@ export class JsonDanmaku {
}
export type DanmakuDownloadType = 'json' | 'xml' | 'ass'
export const getUserDanmakuConfig = async () => {
const downloadDanmakuOptions =
getComponentSettings<DownloadDanmakuOptions>('downloadDanmaku').options
const title = getFriendlyTitle()
const defaultConfig: Omit<DanmakuConverterConfig, 'title'> = {
font: '微软雅黑',
Expand Down Expand Up @@ -135,7 +139,11 @@ export const getUserDanmakuConfig = async () => {

// 弹幕持续时长
config.duration = (() => {
const scrollDuration = 18 - 3 * playerAgent.getPlayerConfig('dmSetting.speedplus', 0)
const speed =
downloadDanmakuOptions.speed === 'auto'
? playerAgent.getPlayerConfig('dmSetting.speedplus', 0)
: downloadDanmakuOptions.speed
const scrollDuration = 18 - 3 * speed
return (danmaku: { type: number }) => {
switch (danmaku.type) {
case 4:
Expand Down

0 comments on commit f0d5f17

Please sign in to comment.