2020-01-21 11:03:41 +00:00
|
|
|
const musicMetadata = require("music-metadata-browser");
|
2020-02-11 07:51:07 +00:00
|
|
|
import {GetCoverURL, GetFileInfo, AudioMimeType, DetectAudioExt, GetArrayBuffer} from "./util";
|
2020-01-21 11:03:41 +00:00
|
|
|
|
2020-02-11 07:51:07 +00:00
|
|
|
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]})
|
|
|
|
}
|
2020-02-06 08:18:40 +00:00
|
|
|
const tag = await musicMetadata.parseBlob(file);
|
2020-02-11 06:48:27 +00:00
|
|
|
const info = GetFileInfo(tag.common.artist, tag.common.title, raw_filename);
|
2020-01-21 11:03:41 +00:00
|
|
|
return {
|
|
|
|
status: true,
|
|
|
|
title: info.title,
|
|
|
|
artist: info.artist,
|
2020-02-11 07:51:07 +00:00
|
|
|
ext: ext,
|
2020-01-21 11:03:41 +00:00
|
|
|
album: tag.common.album,
|
2020-02-11 06:48:27 +00:00
|
|
|
picture: GetCoverURL(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
|
|
|
}
|
|
|
|
}
|