mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Merge pull request #4542 from WakelessSloth56/preview-features
修复 #4521 中审查的问题
This commit is contained in:
commit
5972b58101
@ -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]
|
||||
|
||||
@ -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 = '混流中……'
|
||||
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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`,
|
||||
|
||||
@ -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`,
|
||||
|
||||
@ -11,6 +11,11 @@ export interface CdnConfig {
|
||||
sortable: string
|
||||
mdi: string
|
||||
streamsaver: string
|
||||
ffmpeg: {
|
||||
worker: string
|
||||
core: string
|
||||
wasm: string
|
||||
}
|
||||
}
|
||||
smallLogo: string
|
||||
logo: string
|
||||
|
||||
Loading…
Reference in New Issue
Block a user