use infer::audio::{is_aiff, is_ape, is_flac, is_mp3, is_ogg, is_wav};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Ord, Eq, Serialize, Deserialize)]
pub enum ContainerFormat {
Flac,
Mpa,
Ogg,
Wav,
Aiff,
Ape,
}
impl ContainerFormat {
pub fn from_buf(buf: &[u8; 16]) -> Option<Self> {
let container = if is_flac(buf) {
ContainerFormat::Flac
} else if is_ogg(buf) {
ContainerFormat::Ogg
} else if is_mp3(buf) {
ContainerFormat::Mpa
} else if is_wav(buf) {
ContainerFormat::Wav
} else if is_aiff(buf) {
ContainerFormat::Aiff
} else if is_ape(buf) {
ContainerFormat::Ape
} else {
return None;
};
Some(container)
}
#[must_use]
pub fn format_name(&self) -> &str {
match self {
ContainerFormat::Aiff => "aiff",
ContainerFormat::Ape => "ape",
ContainerFormat::Flac => "flac",
ContainerFormat::Mpa => "mp3",
ContainerFormat::Ogg => "ogg",
ContainerFormat::Wav => "wav",
}
}
}