From 0b7c6a96933ac1986758117cfb5a3bedbd17c968 Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Sat, 29 Jul 2023 00:08:47 -0400 Subject: [PATCH] Switch to using a yaml config --- .gitignore | 9 ++++----- Cargo.lock | 29 ++++++++++++++++++++++++++++- Cargo.toml | 2 +- src/config/config.rs | 17 ++--------------- src/indexer.rs | 4 ++-- src/main.rs | 1 + src/util.rs | 3 +++ 7 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 src/util.rs diff --git a/.gitignore b/.gitignore index 51f93e4..f5a1975 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ -**/target -**/.vscode +target +.vscode # Debug related directories that we don't want included -**/torrents* -**/output -**/config.toml \ No newline at end of file +dev +config.yaml \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index d4998bb..5f0fb6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 276b408..e3ed9ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/config/config.rs b/src/config/config.rs index 587b732..7d1144a 100644 --- a/src/config/config.rs +++ b/src/config/config.rs @@ -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, - /// Used for deserializing the indexers into a Vec. - #[serde(rename = "indexers")] - indexers_map: HashMap, - /// The indexers to search. - #[serde(skip)] pub indexers: Vec, /// 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 } diff --git a/src/indexer.rs b/src/indexer.rs index c681a98..e086254 100644 --- a/src/indexer.rs +++ b/src/indexer.rs @@ -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, + #[serde(default = "crate::util::bool_true")] + pub enabled: bool, /// URL to query for searches pub url: String, /// API key to pass to prowlarr/jackett diff --git a/src/main.rs b/src/main.rs index 6305dfd..74ccd7b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod torznab; mod torrent_client; mod indexer; mod cross_seed; +mod util; use config::Config; diff --git a/src/util.rs b/src/util.rs new file mode 100644 index 0000000..539354e --- /dev/null +++ b/src/util.rs @@ -0,0 +1,3 @@ +pub fn bool_true() -> bool { + true +} \ No newline at end of file