Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[组件-下载视频][插件-下载视频 - aria2 输出支持][组件-查看封面] 为aria2提供可下载封面的功能 #4798

Merged
merged 5 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions registry/lib/components/video/download/DownloadVideo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,14 @@ export default Vue.extend({
}
const action = new DownloadVideoAction(videoInfos)
assets.forEach(a => {
action.extraAssets.push({
const assetsType = a?.getUrls ? action.extraOnlineAssets : action.extraAssets
assetsType.push({
asset: a,
instance: this.$refs.assetsOptions.find((c: any) => c.$attrs.name === a.name),
})
})
/** 若视频输出的插件设置了proxyExtraAssets,则由插件在runAction中处理 */
if (!output?.proxyExtraAssets) {
await action.downloadExtraAssets()
}
await output.runAction(action, instance)
await action.downloadExtraAssets()
} catch (error) {
logError(error)
} finally {
Expand Down
10 changes: 6 additions & 4 deletions registry/lib/components/video/download/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ export interface DownloadVideoAssets<AssetsParameter = any> extends VueInstanceI
/** 表示视频的下载信息以及携带的额外产物 */
export class DownloadVideoAction<AssetsParameter = any> {
readonly inputs: DownloadVideoInputItem[] = []
/** 可下载的asset和对应的参数 */
/** 可调用处理的asset和对应的参数 */
extraAssets: { asset: DownloadVideoAssets; instance: AssetsParameter }[] = []
/** 可直接下载的asset和对应的参数 */
extraOnlineAssets: { asset: DownloadVideoAssets; instance: AssetsParameter }[] = []
the1812 marked this conversation as resolved.
Show resolved Hide resolved

constructor(public infos: DownloadVideoInfo[]) {
this.inputs = infos.map(it => it.input)
Expand All @@ -101,7 +103,9 @@ export class DownloadVideoAction<AssetsParameter = any> {
const { infos } = this
const extraAssetsBlob = (
await Promise.all(
this.extraAssets.map(({ asset, instance }) => asset.getAssets(infos, instance)),
[...this.extraAssets, ...this.extraOnlineAssets].map(({ asset, instance }) =>
asset.getAssets(infos, instance),
),
)
).flat()
await new DownloadPackage(extraAssetsBlob).emit(filename)
Expand All @@ -110,7 +114,5 @@ export class DownloadVideoAction<AssetsParameter = any> {
/** 下载视频的最终输出处理 */
export interface DownloadVideoOutput<OutputParameter = any> extends VueInstanceInput, WithName {
runAction: (action: DownloadVideoAction, instance: OutputParameter) => Promise<void>
/** 是否需要代理下载assets */
proxyExtraAssets?: boolean
description?: string
}
18 changes: 5 additions & 13 deletions registry/lib/plugins/video/download/aria2-output/aria2-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { getJson, monkey, postJson } from '@/core/ajax'
import { Toast } from '@/core/toast'
import { UserAgent } from '@/core/utils/constants'
import { logError } from '@/core/utils/log'
import {
DownloadVideoOutput,
DownloadVideoAction,
} from '../../../../components/video/download/types'
import { DownloadVideoOutput } from '../../../../components/video/download/types'
import { Aria2RpcProfile } from './rpc-profiles'

interface RpcParam {
Expand Down Expand Up @@ -130,15 +127,14 @@ export const aria2Rpc: DownloadVideoOutput = {
name: 'aria2Rpc',
displayName: 'aria2 RPC',
description: '使用 aria2 RPC 功能发送下载请求.',
proxyExtraAssets: true,
runAction: async (
action,
instance: Vue & {
selectedRpcProfile: Aria2RpcProfile
isPluginDownloadAssets?: boolean
},
) => {
const { infos, extraAssets } = action
const { infos, extraOnlineAssets } = action
const { selectedRpcProfile, isPluginDownloadAssets } = instance
const { secretKey, dir, other } = selectedRpcProfile
const referer = document.URL.replace(window.location.search, '')
Expand Down Expand Up @@ -175,24 +171,20 @@ export const aria2Rpc: DownloadVideoOutput = {
// handle assets
const assetsAriaParams = []
const extraAssetsForBrowerDownload = []
for (const { asset, instance: assetInstance } of extraAssets) {
for (const { asset, instance: assetInstance } of extraOnlineAssets) {
if (isPluginDownloadAssets && 'getUrls' in asset) {
// get asset from aria2
const results = await asset.getUrls(infos, assetInstance)
assetsAriaParams.push(...results.map(({ name, url }) => ariaParamsGenerator(url, name)))
} else {
// get asset from browser
// remain asset in `extraOnlineAssets`
extraAssetsForBrowerDownload.push({ asset, instance: assetInstance })
}
}
action.extraOnlineAssets = extraAssetsForBrowerDownload

const totalParams = [...videoParams, ...assetsAriaParams]
const results = await sendRpc(selectedRpcProfile, totalParams)
if (extraAssetsForBrowerDownload.length > 0) {
const actionForBrowserDownload = new DownloadVideoAction(infos)
actionForBrowserDownload.extraAssets = extraAssetsForBrowerDownload
await actionForBrowserDownload.downloadExtraAssets()
}
console.table(results)
if (results.length === 1) {
const result = results[0]
Expand Down
Loading