From 94c656ad40a7aae570e5a5fb61ad32632acc6d46 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 23 Aug 2024 13:11:09 +0200 Subject: feat(treewide): Use a configuration file This allows use to avoid duplication of default values in the codebase and obviously also facilitates changing these without having to re-compile. --- src/constants.rs | 74 -------------------------------------------------------- 1 file changed, 74 deletions(-) (limited to 'src/constants.rs') diff --git a/src/constants.rs b/src/constants.rs index cb8388d..54cae89 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -8,78 +8,4 @@ // You should have received a copy of the License along with this program. // If not, see . -use std::{env::temp_dir, fs, path::PathBuf}; - -use anyhow::{Context, Result}; - pub const HELP_STR: &str = include_str!("./select/selection_file/help.str"); -pub const LOCAL_COMMENTS_LENGTH: usize = 1000; - -// NOTE: KEEP THIS IN SYNC WITH THE `mpv_playback_speed` in `cli.rs` <2024-08-20> -pub const DEFAULT_MPV_PLAYBACK_SPEED: f64 = 2.7; -pub const DEFAULT_SUBTITLE_LANGS: &str = ""; - -pub const CONCURRENT_DOWNLOADS: u32 = 5; -// We download to the temp dir to avoid taxing the disk -pub fn download_dir(create: bool) -> Result { - const DOWNLOAD_DIR: &str = "/tmp/yt"; - let dir = PathBuf::from(DOWNLOAD_DIR); - - if !dir.exists() && create { - fs::create_dir_all(&dir).context("Failed to create the download directory")? - } - - Ok(dir) -} - -const PREFIX: &str = "yt"; -fn get_runtime_path(name: &'static str) -> anyhow::Result { - let xdg_dirs = xdg::BaseDirectories::with_prefix(PREFIX)?; - xdg_dirs - .place_runtime_file(name) - .with_context(|| format!("Failed to place runtime file: '{}'", name)) -} -fn get_data_path(name: &'static str) -> anyhow::Result { - let xdg_dirs = xdg::BaseDirectories::with_prefix(PREFIX)?; - xdg_dirs - .place_data_file(name) - .with_context(|| format!("Failed to place data file: '{}'", name)) -} -fn get_config_path(name: &'static str) -> anyhow::Result { - let xdg_dirs = xdg::BaseDirectories::with_prefix(PREFIX)?; - xdg_dirs - .place_config_file(name) - .with_context(|| format!("Failed to place config file: '{}'", name)) -} - -pub fn mpv_config_path() -> anyhow::Result { - const MPV_CONFIG_PATH: &str = "mpv.conf"; - get_config_path(MPV_CONFIG_PATH) -} -pub fn mpv_input_path() -> anyhow::Result { - const MPV_INPUT_CONFIG_PATH: &str = "mpv.input.conf"; - get_config_path(MPV_INPUT_CONFIG_PATH) -} - -pub fn status_path() -> anyhow::Result { - const STATUS_PATH: &str = "running.info.json"; - get_runtime_path(STATUS_PATH) -} -pub fn last_select() -> anyhow::Result { - const LAST_SELECT: &str = "selected.yts"; - get_runtime_path(LAST_SELECT) -} - -pub fn database() -> anyhow::Result { - const DATABASE: &str = "videos.sqlite"; - get_data_path(DATABASE) -} -pub fn subscriptions() -> anyhow::Result { - const SUBSCRIPTIONS: &str = "subscriptions.json"; - get_data_path(SUBSCRIPTIONS) -} - -pub fn cache_path() -> PathBuf { - let temp_dir = temp_dir(); - temp_dir.join("ytc") -} -- cgit 1.4.1