selene-core 0.8.2

selene-core is the backend for Selene, a local-first music player
Documentation
use infer::audio::{is_aiff, is_ape, is_flac, is_mp3, is_ogg, is_wav};
use serde::{Deserialize, Serialize};

/// All recognized audio containers
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Ord, Eq, Serialize, Deserialize)]
pub enum ContainerFormat {
    Flac,
    Mpa,
    Ogg,
    Wav,
    Aiff,
    Ape,
}

impl ContainerFormat {
    /// Gets container type by reading magic bytes
    ///
    /// Returns none if the container type is unsupported or unrecognized, or cannot be read
    #[must_use] 
    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)
    }

    /// Returns the name as of the container that ffmpeg uses for encoding (the "`format_name`")
    #[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",
        }
    }
}