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