2021-05-23 15:06:21 +00:00
|
|
|
import {AudioMimeType, GetArrayBuffer, GetCoverFromFile, GetMetaFromFile, SniffAudioExt} from "@/decrypt/utils.ts";
|
2021-05-23 13:40:43 +00:00
|
|
|
|
2020-01-21 11:03:41 +00:00
|
|
|
|
2021-05-23 14:29:34 +00:00
|
|
|
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
|
|
|
|
|
|
|
export async function Decrypt(file: Blob, raw_filename: string, raw_ext: string, detect: boolean = true) {
|
2020-02-11 07:51:07 +00:00
|
|
|
let ext = raw_ext;
|
|
|
|
if (detect) {
|
|
|
|
const buffer = new Uint8Array(await GetArrayBuffer(file));
|
2021-05-23 13:40:43 +00:00
|
|
|
ext = SniffAudioExt(buffer, raw_ext);
|
2020-02-11 07:51:07 +00:00
|
|
|
if (ext !== raw_ext) file = new Blob([buffer], {type: AudioMimeType[ext]})
|
|
|
|
}
|
2021-05-23 14:29:34 +00:00
|
|
|
const tag = await metaParseBlob(file);
|
2021-05-23 15:06:21 +00:00
|
|
|
const {title, artist} = GetMetaFromFile(raw_filename, tag.common.title, tag.common.artist)
|
|
|
|
|
2020-01-21 11:03:41 +00:00
|
|
|
return {
|
|
|
|
status: true,
|
2021-05-23 15:06:21 +00:00
|
|
|
title,
|
|
|
|
artist,
|
|
|
|
ext,
|
2020-01-21 11:03:41 +00:00
|
|
|
album: tag.common.album,
|
2021-05-23 15:06:21 +00:00
|
|
|
picture: GetCoverFromFile(tag),
|
2020-02-06 08:18:40 +00:00
|
|
|
file: URL.createObjectURL(file),
|
2020-02-11 07:51:07 +00:00
|
|
|
mime: AudioMimeType[ext]
|
2020-01-21 11:03:41 +00:00
|
|
|
}
|
|
|
|
}
|