Switch to using a yaml config
This commit is contained in:
parent
ec103e4385
commit
0b7c6a9693
|
@ -1,7 +1,6 @@
|
||||||
**/target
|
target
|
||||||
**/.vscode
|
.vscode
|
||||||
|
|
||||||
# Debug related directories that we don't want included
|
# Debug related directories that we don't want included
|
||||||
**/torrents*
|
dev
|
||||||
**/output
|
config.yaml
|
||||||
**/config.toml
|
|
|
@ -503,7 +503,7 @@ dependencies = [
|
||||||
"atomic",
|
"atomic",
|
||||||
"pear",
|
"pear",
|
||||||
"serde",
|
"serde",
|
||||||
"toml",
|
"serde_yaml",
|
||||||
"uncased",
|
"uncased",
|
||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
@ -923,6 +923,12 @@ version = "0.2.126"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
|
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "linked-hash-map"
|
||||||
|
version = "0.5.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lock_api"
|
name = "lock_api"
|
||||||
version = "0.3.4"
|
version = "0.3.4"
|
||||||
|
@ -1786,6 +1792,18 @@ dependencies = [
|
||||||
"syn",
|
"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]]
|
[[package]]
|
||||||
name = "sha-1"
|
name = "sha-1"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
|
@ -2651,6 +2669,15 @@ dependencies = [
|
||||||
"winapi-build",
|
"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]]
|
[[package]]
|
||||||
name = "yansi"
|
name = "yansi"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
|
|
|
@ -23,7 +23,7 @@ abstracttorrent = { path = "abstracttorrent" }
|
||||||
|
|
||||||
serde_with = "1.14.0"
|
serde_with = "1.14.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
figment = { version = "0.10", features = ["toml", "env"] }
|
figment = { version = "0.10", features = ["yaml", "env"] }
|
||||||
wild = "2.0.4"
|
wild = "2.0.4"
|
||||||
argmap = "1.1.2"
|
argmap = "1.1.2"
|
||||||
async-recursion = "1.0.0"
|
async-recursion = "1.0.0"
|
||||||
|
|
|
@ -3,7 +3,7 @@ use tracing::metadata::LevelFilter;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::collections::HashMap;
|
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 figment::value::Value as FigmentValue;
|
||||||
|
|
||||||
use crate::torznab::TorznabClient;
|
use crate::torznab::TorznabClient;
|
||||||
|
@ -45,12 +45,7 @@ pub struct Config {
|
||||||
/// The category of added cross-seed torrents.
|
/// The category of added cross-seed torrents.
|
||||||
torrent_category: Option<String>,
|
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.
|
/// The indexers to search.
|
||||||
#[serde(skip)]
|
|
||||||
pub indexers: Vec<Indexer>,
|
pub indexers: Vec<Indexer>,
|
||||||
|
|
||||||
/// Config section for qbittorrent client
|
/// Config section for qbittorrent client
|
||||||
|
@ -163,18 +158,10 @@ impl Config {
|
||||||
let figment = Figment::new()
|
let figment = Figment::new()
|
||||||
.join(CliProvider::new())
|
.join(CliProvider::new())
|
||||||
.join(Env::prefixed("CROSS_SEED_"))
|
.join(Env::prefixed("CROSS_SEED_"))
|
||||||
.join(Toml::file(format!("{}", path)));
|
.join(Yaml::file(format!("{}", path)));
|
||||||
|
|
||||||
let mut config: Config = figment.extract().unwrap();
|
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
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,11 @@ use crate::torznab::{TorznabClient, GenericSearchParameters, SearchFunction};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
pub struct Indexer {
|
pub struct Indexer {
|
||||||
#[serde(skip_deserializing)]
|
|
||||||
/// Name of the indexer
|
/// Name of the indexer
|
||||||
pub name: String,
|
pub name: String,
|
||||||
/// Whether the indexer is enabled or not for searching
|
/// 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
|
/// URL to query for searches
|
||||||
pub url: String,
|
pub url: String,
|
||||||
/// API key to pass to prowlarr/jackett
|
/// API key to pass to prowlarr/jackett
|
||||||
|
|
|
@ -3,6 +3,7 @@ mod torznab;
|
||||||
mod torrent_client;
|
mod torrent_client;
|
||||||
mod indexer;
|
mod indexer;
|
||||||
mod cross_seed;
|
mod cross_seed;
|
||||||
|
mod util;
|
||||||
|
|
||||||
use config::Config;
|
use config::Config;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
pub fn bool_true() -> bool {
|
||||||
|
true
|
||||||
|
}
|
Loading…
Reference in New Issue