MengYX
5 years ago
7 changed files with 40 additions and 33 deletions
@ -1,17 +1,23 @@ |
|||
const musicMetadata = require("music-metadata-browser"); |
|||
import {GetCoverURL, GetFileInfo, AudioMimeType} from "./util"; |
|||
import {GetCoverURL, GetFileInfo, AudioMimeType, DetectAudioExt, GetArrayBuffer} from "./util"; |
|||
|
|||
export async function Decrypt(file, raw_filename, raw_ext) { |
|||
export async function Decrypt(file, raw_filename, raw_ext, detect = true) { |
|||
let ext = raw_ext; |
|||
if (detect) { |
|||
const buffer = new Uint8Array(await GetArrayBuffer(file)); |
|||
ext = DetectAudioExt(buffer, raw_ext); |
|||
if (ext !== raw_ext) file = new Blob([buffer], {type: AudioMimeType[ext]}) |
|||
} |
|||
const tag = await musicMetadata.parseBlob(file); |
|||
const info = GetFileInfo(tag.common.artist, tag.common.title, raw_filename); |
|||
return { |
|||
status: true, |
|||
title: info.title, |
|||
artist: info.artist, |
|||
ext: raw_ext, |
|||
ext: ext, |
|||
album: tag.common.album, |
|||
picture: GetCoverURL(tag), |
|||
file: URL.createObjectURL(file), |
|||
mime: AudioMimeType[raw_ext] |
|||
mime: AudioMimeType[ext] |
|||
} |
|||
} |
|||
|
Loading…
Reference in new issue