selene-core 0.9.0-alpha.2

selene-core is the backend for Selene, a local-first music player
Documentation
#![forbid(unsafe_code)]

use lunar_lib::paths::init_directories;

pub const PROGRAM_FS_NAME: &str = "selene";
pub const PROGRAM_DISPLAY_NAME: &str = "Selene";

// #[cfg(feature = "lrclib")]
// pub mod lrclib;

pub mod config;

#[cfg(feature = "database-impls")]
pub mod database;

pub mod library;
pub mod lyrics;
pub mod media_container;
pub mod utils;

pub mod symphonia_helpers;

pub fn init_dirs() -> Result<(), &'static str> {
    init_directories(PROGRAM_FS_NAME)
}

pub use lunar_lib::id::Id;

pub trait SeleneIdExt<T> {
    /// Turns an ID into its `name:id` counterpart, eg. `track:<id>`
    #[cfg(feature = "database-impls")]
    fn to_selene_id(&self) -> String
    where
        T: lunar_lib::database::DatabaseEntry;

    /// Gets an ID from the hash of a string. This will not work for tracks, which require the hash of the source file
    fn from_string_hash(string: impl AsRef<str>) -> Self;
}

impl<T> SeleneIdExt<T> for Id<T> {
    #[cfg(feature = "database-impls")]
    fn to_selene_id(&self) -> String
    where
        T: lunar_lib::database::DatabaseEntry,
    {
        format!("{}:{}", T::TREE_NAME, self)
    }

    fn from_string_hash(string: impl AsRef<str>) -> Self {
        let hash = blake3::hash(string.as_ref().to_lowercase().as_bytes());
        Self::from(*hash.as_bytes())
    }
}