From 7989b6e3b26f65456cc5d24cc1a3df4101e07e9a Mon Sep 17 00:00:00 2001 From: Yuze Fu Date: Fri, 22 Sep 2023 22:24:10 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=81=E8=AE=B8=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E8=A7=86=E9=A2=91=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6=E6=8B=93?= =?UTF-8?q?=E5=B1=95=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/video/download/apis/dash.ts | 21 +++++++++-- .../lib/components/video/download/index.ts | 35 ++++++++++++++----- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/registry/lib/components/video/download/apis/dash.ts b/registry/lib/components/video/download/apis/dash.ts index aa49c50c48..a6a0a027d7 100644 --- a/registry/lib/components/video/download/apis/dash.ts +++ b/registry/lib/components/video/download/apis/dash.ts @@ -11,9 +11,11 @@ import { DownloadVideoInputItem, } from '../types' import { bangumiApi, videoApi } from './url' +import { Options } from '..' +import { getComponentSettings } from '@/core/settings' /** dash 格式更明确的扩展名 */ -export const DashExtensions = { +export const DefaultDashExtensions = { video: '.mp4', audio: '.m4a', flacAudio: '.flac', @@ -27,7 +29,7 @@ export enum DashCodec { Av1 = 'AV1', } export interface Dash { - type: keyof typeof DashExtensions + type: keyof typeof DefaultDashExtensions bandWidth: number codecs: string codecId: number @@ -50,12 +52,25 @@ export interface DashFilters { video?: (dash: VideoDash) => boolean audio?: (dash: AudioDash) => boolean } +const getDashExtensions = (type: keyof typeof DefaultDashExtensions): string => { + const { options } = getComponentSettings('downloadVideo') + if (type === 'video') { + return options.dashVideoExtension + } + if (type === 'audio') { + return options.dashAudioExtension + } + if (type === 'flacAudio') { + return options.dashFlacAudioExtension + } + return DefaultDashExtensions[type] ?? DashFragmentExtension +} const dashToFragment = (dash: Dash): DownloadVideoFragment => ({ url: dash.downloadUrl, backupUrls: dash.backupUrls, length: dash.duration, size: Math.trunc((dash.bandWidth * dash.duration) / 8), - extension: DashExtensions[dash.type] ?? DashFragmentExtension, + extension: getDashExtensions(dash.type), }) export const dashToFragments = (info: { videoDashes: VideoDash[] diff --git a/registry/lib/components/video/download/index.ts b/registry/lib/components/video/download/index.ts index 1481ca288d..319110d184 100644 --- a/registry/lib/components/video/download/index.ts +++ b/registry/lib/components/video/download/index.ts @@ -1,6 +1,31 @@ -import { defineComponentMetadata } from '@/components/define' +import { + OptionsOfMetadata, + defineComponentMetadata, + defineOptionsMetadata, +} from '@/components/define' import { hasVideo } from '@/core/spin-query' +import { DefaultDashExtensions } from './apis/dash' +const options = defineOptionsMetadata({ + basicConfig: { + defaultValue: {}, + displayName: '基础配置', + hidden: true, + }, + dashVideoExtension: { + defaultValue: DefaultDashExtensions.video, + displayName: 'DASH 视频扩展名', + }, + dashAudioExtension: { + defaultValue: DefaultDashExtensions.audio, + displayName: 'DASH 普通音频扩展名', + }, + dashFlacAudioExtension: { + defaultValue: DefaultDashExtensions.flacAudio, + displayName: 'DASH FLAC 音频扩展名', + }, +}) +export type Options = OptionsOfMetadata export const component = defineComponentMetadata({ name: 'downloadVideo', displayName: '下载视频', @@ -12,12 +37,6 @@ export const component = defineComponentMetadata({ condition: () => hasVideo(), }, tags: [componentsTags.video], - options: { - basicConfig: { - defaultValue: {}, - displayName: '基础配置', - hidden: true, - }, - }, + options, // plugin, })