diff --git a/registry/lib/components/utils/view-cover/index.ts b/registry/lib/components/utils/view-cover/index.ts index b56af3d7c..4c5fef9af 100644 --- a/registry/lib/components/utils/view-cover/index.ts +++ b/registry/lib/components/utils/view-cover/index.ts @@ -1,5 +1,5 @@ import { defineComponentMetadata } from '@/components/define' -import { getBlobByAid } from '@/components/video/video-cover' +import { getVideoCoverUrlByAid, getBlobByAid } from '@/components/video/video-cover' import { PackageEntry } from '@/core/download' import { videoAndBangumiUrls } from '@/core/utils/urls' import { Toast } from '@/core/toast' @@ -55,6 +55,26 @@ export const component = defineComponentMetadata({ toast.message = `获取完成. 成功 ${success.length} 个, 失败 ${fail.length} 个.` return success.map(it => it.value) }, + getUrls: async ( + infos, + instance: { + type: CoverDownloadType + enabled: boolean + }, + ) => { + const { type, enabled } = instance + if (!enabled) { + return [] + } + return Promise.all( + infos.map(async info => { + return { + name: `${info.input.title}.${type}`, + url: await getVideoCoverUrlByAid(info.input.aid), + } + }), + ) + }, component: () => import('./Plugin.vue').then(m => m.default), }) }) diff --git a/registry/lib/components/video/download/DownloadVideo.vue b/registry/lib/components/video/download/DownloadVideo.vue index 1e66bc16a..6a1a637cd 100644 --- a/registry/lib/components/video/download/DownloadVideo.vue +++ b/registry/lib/components/video/download/DownloadVideo.vue @@ -330,19 +330,15 @@ export default Vue.extend({ }) } const action = new DownloadVideoAction(videoInfos) - const extraAssets = ( - await Promise.all( - assets.map(a => - a.getAssets( - videoInfos, - this.$refs.assetsOptions.find((c: any) => c.$attrs.name === a.name), - ), - ), - ) - ).flat() - action.extraAssets.push(...extraAssets) - await action.downloadExtraAssets() + assets.forEach(a => { + const assetsType = a?.getUrls ? action.extraOnlineAssets : action.extraAssets + assetsType.push({ + asset: a, + instance: this.$refs.assetsOptions.find((c: any) => c.$attrs.name === a.name), + }) + }) await output.runAction(action, instance) + await action.downloadExtraAssets() } catch (error) { logError(error) } finally { diff --git a/registry/lib/components/video/download/types.ts b/registry/lib/components/video/download/types.ts index 9f68a33ae..676c7a5d8 100644 --- a/registry/lib/components/video/download/types.ts +++ b/registry/lib/components/video/download/types.ts @@ -77,11 +77,19 @@ export interface DownloadVideoApi extends WithName { /** 表示下载时额外附带的产物, 如弹幕 / 字幕等 */ export interface DownloadVideoAssets extends VueInstanceInput, WithName { getAssets: (infos: DownloadVideoInfo[], instance: AssetsParameter) => Promise + /** 获取可直接下载的链接 */ + getUrls?: ( + infos: DownloadVideoInfo[], + instance: AssetsParameter, + ) => Promise<{ name: string; url: string }[]> } /** 表示视频的下载信息以及携带的额外产物 */ -export class DownloadVideoAction { +export class DownloadVideoAction { readonly inputs: DownloadVideoInputItem[] = [] - extraAssets: PackageEntry[] = [] + /** 可调用处理的asset和对应的参数 */ + extraAssets: { asset: DownloadVideoAssets; instance: AssetsParameter }[] = [] + /** 可直接下载的asset和对应的参数 */ + extraOnlineAssets: { asset: DownloadVideoAssets; instance: AssetsParameter }[] = [] constructor(public infos: DownloadVideoInfo[]) { this.inputs = infos.map(it => it.input) @@ -92,7 +100,15 @@ export class DownloadVideoAction { async downloadExtraAssets() { console.log('[downloadExtraAssets]', this.extraAssets) const filename = `${getFriendlyTitle(false)}.zip` - await new DownloadPackage(this.extraAssets).emit(filename) + const { infos } = this + const extraAssetsBlob = ( + await Promise.all( + [...this.extraAssets, ...this.extraOnlineAssets].map(({ asset, instance }) => + asset.getAssets(infos, instance), + ), + ) + ).flat() + await new DownloadPackage(extraAssetsBlob).emit(filename) } } /** 下载视频的最终输出处理 */ diff --git a/registry/lib/plugins/video/download/aria2-output/RpcConfig.vue b/registry/lib/plugins/video/download/aria2-output/RpcConfig.vue index 067638faa..52e9e2f01 100644 --- a/registry/lib/plugins/video/download/aria2-output/RpcConfig.vue +++ b/registry/lib/plugins/video/download/aria2-output/RpcConfig.vue @@ -1,5 +1,9 @@