Skip to content

Commit

Permalink
feat: saveVideoMetadata - ffmetadata fields mode option
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Sep 30, 2024
1 parent c973a25 commit 5626e33
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
2 changes: 2 additions & 0 deletions registry/lib/components/video/metadata/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Toast } from '@/core/toast'
import { videoUrls } from '@/core/utils/urls'
import { DownloadVideoAssets } from '../download/types'
import { generateByType, MetadataType } from './metadata'
import { options } from './options'

export const title = '保存视频元数据'
export const name = 'saveVideoMetadata'
Expand All @@ -28,6 +29,7 @@ export const component = defineComponentMetadata({
tags: [componentsTags.video],
entry: none,
urlInclude: videoUrls,
options,
widget: {
condition: hasVideo,
component: () => import('./SaveMetadata.vue').then(m => m.default),
Expand Down
46 changes: 28 additions & 18 deletions registry/lib/components/video/metadata/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { VideoInfo, VideoPageInfo } from '@/components/video/video-info'
import { VideoQuality } from '@/components/video/video-quality'
import { bilibiliApi, getJsonWithCredentials } from '@/core/ajax'
import { meta } from '@/core/meta'
import { getComponentSettings } from '@/core/settings'
import { Toast } from '@/core/toast'
import { title as pluginTitle } from '.'
import { name as componentName, title as pluginTitle } from '.'
import { FieldsMode, Options } from './options'

export type MetadataType = 'ffmetadata' | 'ogm'

Expand Down Expand Up @@ -62,6 +64,10 @@ async function generateFFMetadata(aid: string = unsafeWindow.aid, cid: string =
const data = await fetchMetadata(aid, cid)
const info = data.basic

const {
options: { fieldsMode },
} = getComponentSettings<Options>(componentName)

const lines = [
';FFMETADATA1',
`;generated by Bilibili-Evolved v${meta.compilationInfo.version}`,
Expand All @@ -70,25 +76,29 @@ async function generateFFMetadata(aid: string = unsafeWindow.aid, cid: string =
ff('title', `${info.title} - ${data.page.title}`, false),
ff('description', info.description, false),
ff('artist', info.up.name, false),
// Custom fields
ff('title', info.title),
ff('description', info.description),
ff('publish_date', new Date(info.pubdate * 1000).toLocaleString()),
ff('aid', info.aid),
ff('bvid', info.bvid),
ff('cid', data.page.cid),
ff('category_id', info.tagId),
ff('category_name', info.tagName),
ff('page_title', data.page.title),
ff('page', data.page.pageNumber),
ff('pages', info.pages.length),
ff('up_name', info.up.name),
ff('up_uid', info.up.uid),
]

if (data.quality) {
lines.push(ff('quality', data.quality.value))
lines.push(ff('quality_label', data.quality.name))
if (fieldsMode === FieldsMode.ALL) {
// Custom fields
lines.push(
ff('title', info.title),
ff('description', info.description),
ff('publish_date', new Date(info.pubdate * 1000).toLocaleString()),
ff('aid', info.aid),
ff('bvid', info.bvid),
ff('cid', data.page.cid),
ff('category_id', info.tagId),
ff('category_name', info.tagName),
ff('page_title', data.page.title),
ff('page', data.page.pageNumber),
ff('pages', info.pages.length),
ff('up_name', info.up.name),
ff('up_uid', info.up.uid),
)
if (data.quality) {
lines.push(ff('quality', data.quality.value))
lines.push(ff('quality_label', data.quality.name))
}
}

if (data.viewPoints.length > 0) {
Expand Down
16 changes: 16 additions & 0 deletions registry/lib/components/video/metadata/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineOptionsMetadata, OptionsOfMetadata } from '@/components/define'

export enum FieldsMode {
ALL = '全部',
Standard = '仅标准字段',
}

export const options = defineOptionsMetadata({
fieldsMode: {
defaultValue: FieldsMode.ALL,
displayName: 'FFMETADATA 字段',
dropdownEnum: FieldsMode,
},
})

export type Options = OptionsOfMetadata<typeof options>

0 comments on commit 5626e33

Please sign in to comment.