about summary refs log tree commit diff stats
path: root/src/constants.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-21 10:49:23 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-21 11:28:43 +0200
commit1debeb77f7986de1b659dcfdc442de6415e1d9f5 (patch)
tree4df3e7c3f6a2d1ec116e4088c5ace7f143a8b05f /src/constants.rs
downloadyt-1debeb77f7986de1b659dcfdc442de6415e1d9f5.tar.gz
yt-1debeb77f7986de1b659dcfdc442de6415e1d9f5.zip
chore: Initial Commit
This repository was migrated out of my nixos-config.
Diffstat (limited to '')
-rw-r--r--src/constants.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/constants.rs b/src/constants.rs
new file mode 100644
index 0000000..f4eef3d
--- /dev/null
+++ b/src/constants.rs
@@ -0,0 +1,79 @@
+// yt - A fully featured command line YouTube client
+//
+// Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// This file is part of Yt.
+//
+// You should have received a copy of the License along with this program.
+// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+
+use std::{env::temp_dir, path::PathBuf};
+
+use anyhow::Context;
+
+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 = "en";
+
+pub const CONCURRENT_DOWNLOADS: u32 = 5;
+// We download to the temp dir to avoid taxing the disk
+pub fn download_dir() -> PathBuf {
+    const DOWNLOAD_DIR: &str = "/tmp/yt";
+    PathBuf::from(DOWNLOAD_DIR)
+}
+
+const PREFIX: &str = "yt";
+fn get_runtime_path(name: &'static str) -> anyhow::Result<PathBuf> {
+    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<PathBuf> {
+    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<PathBuf> {
+    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<PathBuf> {
+    const MPV_CONFIG_PATH: &str = "mpv.conf";
+    get_config_path(MPV_CONFIG_PATH)
+}
+pub fn mpv_input_path() -> anyhow::Result<PathBuf> {
+    const MPV_INPUT_CONFIG_PATH: &str = "mpv.input.conf";
+    get_config_path(MPV_INPUT_CONFIG_PATH)
+}
+
+pub fn status_path() -> anyhow::Result<PathBuf> {
+    const STATUS_PATH: &str = "running.info.json";
+    get_runtime_path(STATUS_PATH)
+}
+pub fn last_select() -> anyhow::Result<PathBuf> {
+    const LAST_SELECT: &str = "selected.yts";
+    get_runtime_path(LAST_SELECT)
+}
+
+pub fn database() -> anyhow::Result<PathBuf> {
+    const DATABASE: &str = "videos.sqlite";
+    get_data_path(DATABASE)
+}
+pub fn subscriptions() -> anyhow::Result<PathBuf> {
+    const SUBSCRIPTIONS: &str = "subscriptions.json";
+    get_data_path(SUBSCRIPTIONS)
+}
+
+pub fn cache_path() -> PathBuf {
+    let temp_dir = temp_dir();
+    temp_dir.join("ytc")
+}