Skip to content

Commit

Permalink
feat: wasm plugin switch for whether to mux metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
lainio24 committed Jul 30, 2024
1 parent 0638dbd commit 3684f7d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
41 changes: 41 additions & 0 deletions registry/lib/plugins/video/download/wasm-output/Config.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<template>
<div v-if="shouldShow" class="download-video-config-item" style="flex-wrap: wrap">
<div class="download-video-config-title">写入元数据:</div>
<SwitchBox v-model="muxWithMetadata" @change="saveOptions" />
<div class="download-video-config-description" style="width: 100%">
仅支持元数据类型「ffmetadata」
</div>
</div>
</template>

<script lang="ts">
import { SwitchBox } from '@/ui'
import { isComponentEnabled, getComponentSettings } from '@/core/settings'
interface Options {
muxWithMetadata: boolean
}
const defaultOptions: Options = {
muxWithMetadata: false,
}
const { options: storedOptions } = getComponentSettings('downloadVideo')
const options: Options = { ...defaultOptions, ...storedOptions }
export default Vue.extend({
components: {
SwitchBox,
},
data() {
const shouldShow = isComponentEnabled('saveVideoMetadata')
return {
shouldShow,
muxWithMetadata: shouldShow && options.muxWithMetadata,
}
},
methods: {
saveOptions() {
options.muxWithMetadata = this.muxExtraAssets
Object.assign(storedOptions, options)
},
},
})
</script>
18 changes: 10 additions & 8 deletions registry/lib/plugins/video/download/wasm-output/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,25 @@ async function single(
)
}

export async function run(action: DownloadVideoAction) {
export async function run(action: DownloadVideoAction, muxWithMetadata: boolean) {
if (!ffmpeg.loaded) {
await loadFFmpeg()
}

const { infos: pages, extraAssets } = action

let ffmetadata: PackageEntry[]
const extraAssetsForBrowser = []
for (const { asset, instance } of extraAssets) {
if (!ffmetadata && asset.name === 'saveVideoMetadata' && instance.type === 'ffmetadata') {
ffmetadata = await asset.getAssets(pages, instance)
} else {
extraAssetsForBrowser.push({ asset, instance })
if (muxWithMetadata) {
const extraAssetsForBrowser = []
for (const { asset, instance } of extraAssets) {
if (!ffmetadata && asset.name === 'saveVideoMetadata' && instance.type === 'ffmetadata') {
ffmetadata = await asset.getAssets(pages, instance)
} else {
extraAssetsForBrowser.push({ asset, instance })
}
}
action.extraAssets = extraAssetsForBrowser
}
action.extraAssets = extraAssetsForBrowser

const { dashAudioExtension, dashFlacAudioExtension, dashVideoExtension } =
getComponentSettings<Options>('downloadVideo').options
Expand Down
7 changes: 4 additions & 3 deletions registry/lib/plugins/video/download/wasm-output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ export const plugin: PluginMetadata = {
outputs.push({
name: 'wasm',
displayName: 'WASM',
description: `${desc}运行过程中请勿关闭页面,初次使用或清除缓存后需要加载约 30 MB 的 WASM 文件`,
runAction: async action => {
description: `${desc}运行过程中请勿关闭页面,初次使用或清除缓存后需要加载约 30 MB 的 WASM 文件`,
runAction: async (action, instance) => {
try {
await run(action)
await run(action, instance.muxWithMetadata)
} catch (error) {
Toast.error(String(error), title)
}
},
component: () => import('./Config.vue').then(m => m.default),
})
})
},
Expand Down

0 comments on commit 3684f7d

Please sign in to comment.