1use std::{
2 path::{Path, PathBuf},
3 sync::LazyLock,
4};
5
6use directories::{BaseDirs, UserDirs};
7
8use crate::media_container::{Codec, ContainerFormat};
9
10pub const PROGRAM_FS_NAME: &str = "selene";
11pub const PROGRAM_DISPLAY_NAME: &str = "Selene";
12
13#[cfg(feature = "lrclib")]
14pub mod lrclib;
15
16#[cfg(any(feature = "lastfm"))]
17pub mod scrobbling;
18
19pub mod config;
20pub mod database;
21pub mod errors;
22pub mod library;
23pub mod media_container;
24pub mod synced_lyrics;
25pub mod utils;
26
27pub mod symphonia_helpers;
28
29#[cfg(any(feature = "lrclib", feature = "lastfm"))]
30static REQWEST_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(|| {
31 reqwest::Client::builder()
32 .user_agent(format!(
33 "{PROGRAM_DISPLAY_NAME} v{ver} (https://codeberg.org/CrypticCreator/Selene)",
34 ver = env!("CARGO_PKG_VERSION")
35 ))
36 .build()
37 .unwrap()
38});
39
40static BASE_DIRS: LazyLock<Option<BaseDirs>> = LazyLock::new(BaseDirs::new);
41
42#[must_use]
48pub fn base_dirs() -> &'static BaseDirs {
49 BASE_DIRS.as_ref().unwrap()
50}
51
52#[must_use]
53pub fn config_dir() -> &'static Path {
54 &CONFIG_DIR
55}
56static CONFIG_DIR: LazyLock<PathBuf> =
57 LazyLock::new(|| base_dirs().config_dir().join(PROGRAM_FS_NAME));
58
59#[must_use]
60pub fn data_dir() -> &'static Path {
61 &DATA_DIR
62}
63static DATA_DIR: LazyLock<PathBuf> = LazyLock::new(|| base_dirs().data_dir().join(PROGRAM_FS_NAME));
64
65#[must_use]
66pub fn cache_dir() -> PathBuf {
67 base_dirs().cache_dir().join(PROGRAM_FS_NAME)
68}
69
70#[must_use]
71pub fn runtime_dir() -> PathBuf {
72 base_dirs().runtime_dir().unwrap().join(PROGRAM_FS_NAME)
73}
74
75pub fn music_dir() -> Option<&'static Path> {
76 MUSIC_DIR.as_deref()
77}
78static MUSIC_DIR: LazyLock<Option<PathBuf>> = LazyLock::new(|| {
79 UserDirs::new().and_then(|user_dirs| user_dirs.audio_dir().map(|p| p.join("Selene Library")))
80});
81
82pub const VALID_TRANSCODE_PAIRS: [(ContainerFormat, Codec); 2] = [
84 (ContainerFormat::Flac, Codec::Flac),
85 (ContainerFormat::Ogg, Codec::Vorbis),
86];
87
88pub const VALID_LIBRARY_FORMATS: [ContainerFormat; 3] = [
89 ContainerFormat::Flac,
90 ContainerFormat::Mpa,
91 ContainerFormat::Ogg,
92];
93pub const VALID_LIBRARY_CODECS: [Codec; 3] = [Codec::Flac, Codec::Vorbis, Codec::Mp3];