mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
feat: limit to 2GB, use HEAD to get size
This commit is contained in:
parent
406b2f6318
commit
588c9a421b
@ -7,7 +7,7 @@ import { title as pluginTitle } from '.'
|
||||
import type { Options } from '../../../../components/video/download'
|
||||
import { DownloadVideoAction } from '../../../../components/video/download/types'
|
||||
import { FFmpeg } from './ffmpeg'
|
||||
import { getCacheOrFetch, httpGet, toastProgress, toBlobUrl } from './utils'
|
||||
import { getCacheOrFetch, getContentLength, httpGet, toastProgress, toBlobUrl } from './utils'
|
||||
|
||||
const ffmpeg = new FFmpeg()
|
||||
|
||||
@ -139,8 +139,14 @@ export async function run(action: DownloadVideoAction, muxWithMetadata: boolean)
|
||||
throw new Error('仅支持 DASH 格式视频和音频')
|
||||
}
|
||||
|
||||
if (video.size + audio.size > 4294967295) {
|
||||
throw new Error(`仅支持合并 4GB 内的音视频(${formatFileSize(video.size + audio.size)})`)
|
||||
const [videoSize, audioSize] = await Promise.all([
|
||||
getContentLength(video.url),
|
||||
getContentLength(audio.url),
|
||||
])
|
||||
const size = Math.max(videoSize, video.size) + Math.max(audioSize, audio.size)
|
||||
// 2000 * 1024 * 1024
|
||||
if (size > 2097152000) {
|
||||
throw new Error(`仅支持合并 2GB 内的音视频(${formatFileSize(size)})`)
|
||||
}
|
||||
|
||||
await single(
|
||||
|
||||
@ -19,7 +19,7 @@ export const plugin: PluginMetadata = {
|
||||
outputs.push({
|
||||
name: 'wasm',
|
||||
displayName: 'WASM',
|
||||
description: `${desc}。运行过程中请勿关闭页面,初次使用或清除缓存后需要加载约 30 MB 的 WASM 文件。由于浏览器限制,仅支持合并 4GB 以内的音视频。`,
|
||||
description: `${desc}。运行过程中请勿关闭页面,初次使用或清除缓存后需要加载约 30 MB 的 WASM 文件。由于浏览器限制,仅支持合并 2GB 以内的音视频。`,
|
||||
runAction: async (action, instance) => {
|
||||
try {
|
||||
await run(action, instance.muxWithMetadata)
|
||||
|
||||
@ -21,6 +21,13 @@ export function toastProgress(toast: Toast) {
|
||||
}
|
||||
}
|
||||
|
||||
function parseContentLength(response: Response) {
|
||||
// https://github.com/the1812/Bilibili-Evolved/pull/4521#discussion_r1402127375
|
||||
return response.headers.get('Content-Encoding')
|
||||
? -1
|
||||
: parseInt(response.headers.get('Content-Length'))
|
||||
}
|
||||
|
||||
export async function httpGet(url: string, onprogress: OnProgress) {
|
||||
const response = await fetch(url)
|
||||
if (!response.ok) {
|
||||
@ -29,10 +36,7 @@ export async function httpGet(url: string, onprogress: OnProgress) {
|
||||
|
||||
const reader = response.body.getReader()
|
||||
|
||||
// https://github.com/the1812/Bilibili-Evolved/pull/4521#discussion_r1402127375
|
||||
const length = response.headers.get('Content-Encoding')
|
||||
? -1
|
||||
: parseInt(response.headers.get('Content-Length'))
|
||||
const length = parseContentLength(response)
|
||||
|
||||
let received = 0
|
||||
const chunks = []
|
||||
@ -57,6 +61,15 @@ export async function httpGet(url: string, onprogress: OnProgress) {
|
||||
return chunksAll
|
||||
}
|
||||
|
||||
export async function getContentLength(url: string) {
|
||||
try {
|
||||
const response = await fetch(url, { method: 'HEAD' })
|
||||
return response.ok ? parseContentLength(response) : -1
|
||||
} catch (_) {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCacheOrFetch(
|
||||
key: string,
|
||||
library: RuntimeLibraryDefinition,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user