Add Detect Media Type by File
parent
10f09958c4
commit
c314a251c2
@ -1,17 +1,23 @@
|
|||||||
const musicMetadata = require("music-metadata-browser");
|
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 tag = await musicMetadata.parseBlob(file);
|
||||||
const info = GetFileInfo(tag.common.artist, tag.common.title, raw_filename);
|
const info = GetFileInfo(tag.common.artist, tag.common.title, raw_filename);
|
||||||
return {
|
return {
|
||||||
status: true,
|
status: true,
|
||||||
title: info.title,
|
title: info.title,
|
||||||
artist: info.artist,
|
artist: info.artist,
|
||||||
ext: raw_ext,
|
ext: ext,
|
||||||
album: tag.common.album,
|
album: tag.common.album,
|
||||||
picture: GetCoverURL(tag),
|
picture: GetCoverURL(tag),
|
||||||
file: URL.createObjectURL(file),
|
file: URL.createObjectURL(file),
|
||||||
mime: AudioMimeType[raw_ext]
|
mime: AudioMimeType[ext]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue