blob: 8eedb18a791cb71a44f6e11b3d9647fb4c0de9d4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// 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::path::PathBuf;
use anyhow::{Context, Result};
fn get_runtime_path(name: &'static str) -> 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) -> 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) -> 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(super) fn create_path(path: PathBuf) -> Result<PathBuf> {
if !path.exists() {
if let Some(parent) = path.parent() {
std::fs::create_dir_all(&parent)
.with_context(|| format!("Failed to create the '{}' directory", path.display()))?
}
}
Ok(path)
}
pub const PREFIX: &str = "yt";
pub mod select {
pub fn playback_speed() -> f64 {
2.7
}
pub fn subtitle_langs() -> &'static str {
""
}
}
pub mod watch {
pub fn local_comments_length() -> usize {
1000
}
}
pub mod update {
pub fn max_backlog() -> u32 {
20
}
}
pub mod paths {
use std::{env::temp_dir, path::PathBuf};
use anyhow::Result;
use super::{create_path, get_config_path, get_data_path, get_runtime_path, PREFIX};
// We download to the temp dir to avoid taxing the disk
pub fn download_dir() -> Result<PathBuf> {
let temp_dir = temp_dir();
create_path(temp_dir.join(PREFIX))
}
pub fn mpv_config_path() -> Result<PathBuf> {
get_config_path("mpv.conf")
}
pub fn mpv_input_path() -> Result<PathBuf> {
get_config_path("mpv.input.conf")
}
pub fn database_path() -> Result<PathBuf> {
get_data_path("videos.sqlite")
}
pub fn config_path() -> Result<PathBuf> {
get_config_path("config.toml")
}
pub fn last_selection_path() -> Result<PathBuf> {
get_runtime_path("selected.yts")
}
}
pub mod download {
pub fn max_cache_size() -> &'static str {
"3 GiB"
}
}
|