use std::{
path::{Path, PathBuf},
sync::LazyLock,
};
use directories::{BaseDirs, UserDirs};
use crate::media_container::{Codec, ContainerFormat};
pub const PROGRAM_FS_NAME: &str = "selene";
pub const PROGRAM_DISPLAY_NAME: &str = "Selene";
#[cfg(feature = "net-features")]
pub mod lrclib;
pub mod config;
pub mod database;
pub mod errors;
pub mod library;
pub mod media_container;
pub mod synced_lyrics;
pub mod utils;
pub mod symphonia_helpers;
#[cfg(feature = "net-features")]
static REQWEST_CLIENT: LazyLock<reqwest::blocking::Client> = LazyLock::new(|| {
reqwest::blocking::Client::builder()
.user_agent(format!(
"{PROGRAM_DISPLAY_NAME} v{ver} (https://codeberg.org/CrypticCreator/Selene)",
ver = env!("CARGO_PKG_VERSION")
))
.build()
.unwrap()
});
static BASE_DIRS: LazyLock<Option<BaseDirs>> = LazyLock::new(BaseDirs::new);
#[must_use]
pub fn base_dirs() -> &'static BaseDirs {
BASE_DIRS.as_ref().unwrap()
}
#[must_use]
pub fn config_dir() -> &'static Path {
&CONFIG_DIR
}
static CONFIG_DIR: LazyLock<PathBuf> =
LazyLock::new(|| base_dirs().config_dir().join(PROGRAM_FS_NAME));
#[must_use]
pub fn data_dir() -> &'static Path {
&DATA_DIR
}
static DATA_DIR: LazyLock<PathBuf> = LazyLock::new(|| base_dirs().data_dir().join(PROGRAM_FS_NAME));
#[must_use]
pub fn cache_dir() -> PathBuf {
base_dirs().cache_dir().join(PROGRAM_FS_NAME)
}
#[must_use]
pub fn runtime_dir() -> PathBuf {
base_dirs().runtime_dir().unwrap().join(PROGRAM_FS_NAME)
}
pub fn music_dir() -> Option<&'static Path> {
MUSIC_DIR.as_deref()
}
static MUSIC_DIR: LazyLock<Option<PathBuf>> = LazyLock::new(|| {
UserDirs::new().and_then(|user_dirs| user_dirs.audio_dir().map(|p| p.join("Selene Library")))
});
pub const VALID_TRANSCODE_PAIRS: [(ContainerFormat, Codec); 2] = [
(ContainerFormat::Flac, Codec::Flac),
(ContainerFormat::Ogg, Codec::Vorbis),
];
pub const VALID_LIBRARY_FORMATS: [ContainerFormat; 3] = [
ContainerFormat::Flac,
ContainerFormat::Mpa,
ContainerFormat::Ogg,
];
pub const VALID_LIBRARY_CODECS: [Codec; 3] = [Codec::Flac, Codec::Vorbis, Codec::Mp3];