selene-core 0.3.1

selene-core is the backend for Selene, a local-first music player
Documentation
use std::path::Path;

use crate::{
    codec::Codec, container::ContainerFormat, ffmpeg::Stream, media_container::MediaContainer,
    utils::pair_extension,
};

impl MediaContainer {
    #[must_use]
    pub fn path(&self) -> &Path {
        &self.path
    }

    #[must_use]
    pub fn container(&self) -> &ContainerFormat {
        &self.format
    }

    #[must_use]
    pub fn codec(&self) -> &Codec {
        &self.stream.codec
    }

    /// Returns the file extension this [`MediaContainer`] uses. Returns [`Option::None`] for invalid or unrecognized pairs
    #[must_use]
    pub fn extension(&self) -> Option<&str> {
        pair_extension(&self.format, &self.stream.codec)
    }

    /// Returns the [`ContainerFormat`] and [`Codec`] the program will transcode [`Self`] into
    ///
    /// Returns none if the pair is an unknown or unrecognized pair
    #[must_use]
    pub fn transcode_to(&self) -> Option<(ContainerFormat, Codec)> {
        let format = self.format;
        let codec = self.stream.codec;
        match format {
            ContainerFormat::Mp3 => Some((ContainerFormat::Mp3, Codec::Mp3)),
            ContainerFormat::Ogg => match codec {
                Codec::Flac | Codec::LibOpus | Codec::LibVorbis => Some((format, codec)),
                _ => None,
            },
            ContainerFormat::Flac | ContainerFormat::Wav => {
                Some((ContainerFormat::Flac, Codec::Flac))
            }
        }
    }

    #[must_use] 
    pub fn stream(&self) -> &Stream {
        &self.stream
    }
}