mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-27 17:52:16 +00:00
add workflow parsing for mp3 and opus formats (#3832)
This commit is contained in:
30
src/scripts/metadata/ogg.ts
Normal file
30
src/scripts/metadata/ogg.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
export async function getOggMetadata(file: File) {
|
||||
const reader = new FileReader()
|
||||
const read_process = new Promise(
|
||||
(r) => (reader.onload = (event) => r(event?.target?.result))
|
||||
)
|
||||
reader.readAsArrayBuffer(file)
|
||||
const arrayBuffer = (await read_process) as ArrayBuffer
|
||||
const signature = String.fromCharCode(...new Uint8Array(arrayBuffer, 0, 4))
|
||||
if (signature !== 'OggS') console.error('Invalid file signature.')
|
||||
let oggs = 0
|
||||
let header = ''
|
||||
while (header.length < arrayBuffer.byteLength) {
|
||||
const page = String.fromCharCode(
|
||||
...new Uint8Array(arrayBuffer, header.length, header.length + 4096)
|
||||
)
|
||||
if (page.match('OggS\u0000')) oggs++
|
||||
header += page
|
||||
if (oggs > 1) break
|
||||
}
|
||||
let workflow, prompt
|
||||
let prompt_s = header
|
||||
.match(/prompt=(\{.*?(\}.*?\u0000))/s)?.[1]
|
||||
?.match(/\{.*\}/)?.[0]
|
||||
if (prompt_s) prompt = JSON.parse(prompt_s)
|
||||
let workflow_s = header
|
||||
.match(/workflow=(\{.*?(\}.*?\u0000))/s)?.[1]
|
||||
?.match(/\{.*\}/)?.[0]
|
||||
if (workflow_s) workflow = JSON.parse(workflow_s)
|
||||
return { prompt, workflow }
|
||||
}
|
||||
Reference in New Issue
Block a user