diff --git a/registry/lib/plugins/video/download/wasm-output/ffmpeg.ts b/registry/lib/plugins/video/download/wasm-output/ffmpeg.ts index 1eec43c85f..5f991c0ba1 100644 --- a/registry/lib/plugins/video/download/wasm-output/ffmpeg.ts +++ b/registry/lib/plugins/video/download/wasm-output/ffmpeg.ts @@ -7,8 +7,6 @@ Modified 2023 WakelessSloth56 /* eslint-disable @typescript-eslint/naming-convention */ -export const VERSION = '0.12.4' - const messageId = (() => { let messageID = 0 return () => messageID++ @@ -46,7 +44,8 @@ export class FFmpeg { this.#rejects[id](data) break default: - throw new Error('Unknown FFmpeg message') + // https://github.com/the1812/Bilibili-Evolved/pull/4521#discussion_r1402041877 + break } delete this.#resolves[id] delete this.#rejects[id] diff --git a/registry/lib/plugins/video/download/wasm-output/handler.ts b/registry/lib/plugins/video/download/wasm-output/handler.ts index 8e9473a6f1..eec527846e 100644 --- a/registry/lib/plugins/video/download/wasm-output/handler.ts +++ b/registry/lib/plugins/video/download/wasm-output/handler.ts @@ -1,32 +1,25 @@ -import { CdnTypes } from '@/core/cdn-types' import { DownloadPackage } from '@/core/download' import { meta } from '@/core/meta' import { Toast } from '@/core/toast' -import { FFmpeg, VERSION } from './ffmpeg' -import { httpget, toBlobUrl, toastProgress } from './utils' +import { FFmpeg } from './ffmpeg' +import { httpGet, toBlobUrl, toastProgress } from './utils' const ffmpeg = new FFmpeg() -function cdnUrl(p: string, file: string) { - return `https://${ - meta.compilationInfo.allCdns[CdnTypes.jsDelivr].host - }/npm/@ffmpeg/${p}@${VERSION}/dist/umd/${file}` -} - async function load(toast: Toast) { await ffmpeg.load({ workerLoadURL: await toBlobUrl( - cdnUrl('ffmpeg', '814.ffmpeg.js'), + meta.compilationInfo.altCdn.library.ffmpeg.worker, 'text/javascript', toastProgress(toast, '正在加载 FFmpeg Worker'), ), coreURL: await toBlobUrl( - cdnUrl('core', 'ffmpeg-core.js'), + meta.compilationInfo.altCdn.library.ffmpeg.core, 'text/javascript', toastProgress(toast, '正在加载 FFmpeg Core'), ), wasmURL: await toBlobUrl( - cdnUrl('core', 'ffmpeg-core.wasm'), + meta.compilationInfo.altCdn.library.ffmpeg.wasm, 'application/wasm', toastProgress(toast, '正在加载 FFmpeg WASM'), ), @@ -37,8 +30,8 @@ export async function run(name: string, videoUrl: string, audioUrl: string, toas await load(toast) } - ffmpeg.writeFile('video', await httpget(videoUrl, toastProgress(toast, '正在下载视频流'))) - ffmpeg.writeFile('audio', await httpget(audioUrl, toastProgress(toast, '正在下载音频流'))) + ffmpeg.writeFile('video', await httpGet(videoUrl, toastProgress(toast, '正在下载视频流'))) + ffmpeg.writeFile('audio', await httpGet(audioUrl, toastProgress(toast, '正在下载音频流'))) toast.message = '混流中……' diff --git a/registry/lib/plugins/video/download/wasm-output/utils.ts b/registry/lib/plugins/video/download/wasm-output/utils.ts index c957fb493b..ae4552e96a 100644 --- a/registry/lib/plugins/video/download/wasm-output/utils.ts +++ b/registry/lib/plugins/video/download/wasm-output/utils.ts @@ -11,14 +11,18 @@ export function toastProgress(toast: Toast, message: string): OnProgress { } } -export async function httpget(url: string, onprogress: OnProgress) { +export async function httpGet(url: string, onprogress: OnProgress) { const response = await fetch(url) if (!response.ok) { throw new Error(`${response.status} ${response.statusText}`) } const reader = response.body.getReader() - const length = parseInt(response.headers.get('Content-Length') || '0') + + // https://github.com/the1812/Bilibili-Evolved/pull/4521#discussion_r1402127375 + const length = response.headers.get('Content-Encoding') + ? -1 + : parseInt(response.headers.get('Content-Length')) let received = 0 const chunks = [] @@ -44,7 +48,7 @@ export async function httpget(url: string, onprogress: OnProgress) { } export async function toBlobUrl(url: string, mimeType: string, onprogress: OnProgress) { - const buffer = await httpget(url, onprogress) + const buffer = await httpGet(url, onprogress) const blob = new Blob([buffer], { type: mimeType }) return URL.createObjectURL(blob) } diff --git a/webpack/cdn/github.ts b/webpack/cdn/github.ts index 66def909dc..05872c69fe 100644 --- a/webpack/cdn/github.ts +++ b/webpack/cdn/github.ts @@ -1,3 +1,4 @@ +import { jsDelivr } from './jsdelivr' import { CdnConfig } from './types' const owner = 'the1812' @@ -15,6 +16,8 @@ export const github: CdnConfig = { sortable: `https://${host}/SortableJS/Sortable/1.14.0/Sortable.min.js`, mdi: `https://${owner}.github.io/Bilibili-Evolved/static/mdi/mdi.css`, streamsaver: `https://${host}/jimmywarting/StreamSaver.js/2.0.6/StreamSaver.js`, + // https://github.com/the1812/Bilibili-Evolved/pull/4521#discussion_r1402084486 + ffmpeg: jsDelivr.library.ffmpeg, }, smallLogo: `https://${host}/${owner}/Bilibili-Evolved/preview/images/logo-small.png`, logo: `https://${host}/${owner}/Bilibili-Evolved/preview/images/logo.png`, diff --git a/webpack/cdn/jsdelivr.ts b/webpack/cdn/jsdelivr.ts index ec2474681d..3765b97745 100644 --- a/webpack/cdn/jsdelivr.ts +++ b/webpack/cdn/jsdelivr.ts @@ -15,6 +15,11 @@ export const jsDelivr: CdnConfig = { sortable: `https://${host}/npm/sortablejs@1.14.0/Sortable.min.js`, mdi: `https://${host}/gh/${owner}/Bilibili-Evolved@master/docs/static/mdi/mdi.css`, streamsaver: `https://${host}/npm/streamsaver@2.0.6/StreamSaver.min.js`, + ffmpeg: { + worker: `https://${host}/npm/@ffmpeg/ffmpeg@0.12.4/dist/umd/814.ffmpeg.js`, + core: `https://${host}/npm/@ffmpeg/core@0.12.4/dist/umd/ffmpeg-core.js`, + wasm: `https://${host}/npm/@ffmpeg/core@0.12.4/dist/umd/ffmpeg-core.wasm`, + }, }, smallLogo: `https://${host}/gh/${owner}/Bilibili-Evolved@preview/images/logo-small.png`, logo: `https://${host}/gh/${owner}/Bilibili-Evolved@preview/images/logo.png`, diff --git a/webpack/cdn/types.ts b/webpack/cdn/types.ts index b23fc639f7..841d97d4df 100644 --- a/webpack/cdn/types.ts +++ b/webpack/cdn/types.ts @@ -11,6 +11,11 @@ export interface CdnConfig { sortable: string mdi: string streamsaver: string + ffmpeg: { + worker: string + core: string + wasm: string + } } smallLogo: string logo: string