about summary refs log tree commit diff stats
path: root/pkgs/by-name/yt/yt/src/constants.rs
blob: 17e0f018d63919f19ee8aaf0538e3bb9a5fdd846 (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
use std::{env::temp_dir, path::PathBuf};

use anyhow::Context;

pub const HELP_STR: &str = include_str!("./select/selection_file/help.str");

pub const YT_DLP_FLAGS: [&str; 13] = [
    // Ignore errors arising of unavailable sponsor block API
    "--ignore-errors",
    "--format",
    "bestvideo[height<=?1080]+bestaudio/best",
    "--embed-chapters",
    "--progress",
    "--write-comments",
    "--extractor-args",
    "youtube:max_comments=150,all,100;comment_sort=top",
    "--write-info-json",
    "--sponsorblock-mark",
    "default",
    "--sponsorblock-remove",
    "sponsor",
];
pub const MPV_FLAGS: [&str; 4] = [
    "--speed=2.7",
    "--volume=75",
    "--keep-open=yes",
    "--msg-level=osd/libass=fatal",
];

pub const CONCURRENT: 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))
}

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")
}