Switch to using a yaml config

This commit is contained in:
SeanOMik 2023-07-29 00:08:47 -04:00
parent ec103e4385
commit 0b7c6a9693
Signed by: SeanOMik
GPG Key ID: 568F326C7EB33ACB
7 changed files with 41 additions and 24 deletions

9
.gitignore vendored
View File

@ -1,7 +1,6 @@
**/target
**/.vscode
target
.vscode
# Debug related directories that we don't want included
**/torrents*
**/output
**/config.toml
dev
config.yaml

29
Cargo.lock generated
View File

@ -503,7 +503,7 @@ dependencies = [
"atomic",
"pear",
"serde",
"toml",
"serde_yaml",
"uncased",
"version_check",
]
@ -923,6 +923,12 @@ version = "0.2.126"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
[[package]]
name = "linked-hash-map"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
[[package]]
name = "lock_api"
version = "0.3.4"
@ -1786,6 +1792,18 @@ dependencies = [
"syn",
]
[[package]]
name = "serde_yaml"
version = "0.8.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578a7433b776b56a35785ed5ce9a7e777ac0598aac5a6dd1b4b18a307c7fc71b"
dependencies = [
"indexmap",
"ryu",
"serde",
"yaml-rust",
]
[[package]]
name = "sha-1"
version = "0.10.0"
@ -2651,6 +2669,15 @@ dependencies = [
"winapi-build",
]
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]
[[package]]
name = "yansi"
version = "0.5.1"

View File

@ -23,7 +23,7 @@ abstracttorrent = { path = "abstracttorrent" }
serde_with = "1.14.0"
serde = { version = "1.0", features = ["derive"] }
figment = { version = "0.10", features = ["toml", "env"] }
figment = { version = "0.10", features = ["yaml", "env"] }
wild = "2.0.4"
argmap = "1.1.2"
async-recursion = "1.0.0"

View File

@ -3,7 +3,7 @@ use tracing::metadata::LevelFilter;
use std::path::Path;
use std::env;
use std::collections::HashMap;
use figment::{Figment, providers::{Format, Toml, Env}};
use figment::{Figment, providers::{Format, Yaml, Env}};
use figment::value::Value as FigmentValue;
use crate::torznab::TorznabClient;
@ -45,12 +45,7 @@ pub struct Config {
/// The category of added cross-seed torrents.
torrent_category: Option<String>,
/// Used for deserializing the indexers into a Vec<Indexer>.
#[serde(rename = "indexers")]
indexers_map: HashMap<String, FigmentValue>,
/// The indexers to search.
#[serde(skip)]
pub indexers: Vec<Indexer>,
/// Config section for qbittorrent client
@ -163,18 +158,10 @@ impl Config {
let figment = Figment::new()
.join(CliProvider::new())
.join(Env::prefixed("CROSS_SEED_"))
.join(Toml::file(format!("{}", path)));
.join(Yaml::file(format!("{}", path)));
let mut config: Config = figment.extract().unwrap();
// Parse the indexers map into a vector.
for (name, value) in &mut config.indexers_map {
let mut indexer: Indexer = value.deserialize().unwrap();
indexer.name = name.to_owned();
config.indexers.push(indexer);
}
config
}

View File

@ -8,11 +8,11 @@ use crate::torznab::{TorznabClient, GenericSearchParameters, SearchFunction};
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Indexer {
#[serde(skip_deserializing)]
/// Name of the indexer
pub name: String,
/// Whether the indexer is enabled or not for searching
pub enabled: Option<bool>,
#[serde(default = "crate::util::bool_true")]
pub enabled: bool,
/// URL to query for searches
pub url: String,
/// API key to pass to prowlarr/jackett

View File

@ -3,6 +3,7 @@ mod torznab;
mod torrent_client;
mod indexer;
mod cross_seed;
mod util;
use config::Config;

3
src/util.rs Normal file
View File

@ -0,0 +1,3 @@
pub fn bool_true() -> bool {
true
}