commit a2d9429f3317ac662f7a9a064156259e059d3285 Author: OMGeeky Date: Mon Sep 18 17:27:23 2023 +0200 Initial version diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8eb581d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +/Cargo.lock +/.idea diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..45505fd --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "backup_config" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = { version = "1.0", features = ["derive"] } +confique = { version = "0.2" , features= ["json5","toml"]} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..45ce3dd --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,115 @@ +use confique::Config; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Config)] +pub struct Conf { + /// The Database Connection URL + #[config(default = "sqlite://data.db?mode=rwc")] + pub db_url: String, + + #[config(nested)] + pub twitch: Twitch, + #[config(nested)] + pub google: Google, + + /// The path to the folder where the videos will be downloaded to. + #[config(default = "/var/tmp/twba/videos/")] + pub download_folder_path: String, + + /// How many videos should be downloaded at the same time. + /// + /// If this number is reached because the uploader can't keep up, the downloader will wait until + /// the number of downloads is below this number again. + /// + /// Set to 0 or leave empty to disable the limit. + pub maximum_downloaded_videos: Option, +} + +#[derive(Debug, Serialize, Deserialize, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Config)] +pub struct Google { + /// The path for the auth code file. + /// + /// This file will contain the response of the auth request. + /// + /// The file should be deleted after the auth response is used. + #[config(default = "tmp/twba/auth/code.txt")] + path_auth_code: String, + /// The path for the auth cache file for each user. '{user}' will be replaced with the user's login. + #[config(default = "tmp/twba/auth/{user}.txt")] + path_auth_cache: String, + + /// Decides if the auth should go to the localhost or the public IP/Server + #[config(default = false)] + local_auth_redirect: bool, + + /// The frequency for reading the auth file in seconds + #[config(default = 10)] + auth_file_read_frequency: u64, + /// The timeout for reading the auth file in seconds + #[config(default = 86400)] // 24 hours + auth_file_read_timeout: u64, + + /// The project ID for the Google Cloud project + #[config(default = "twitchbackup-1")] + pub project_id: String, +} + +#[derive(Debug, Serialize, Deserialize, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Config)] +pub struct BigQuery { + /// The path to the service account file for the BigQuery API + #[config(default = "auth/bigquery_service_account.json")] + pub service_account_path: String, + + /// The dataset ID for the BigQuery dataset + #[config(default = "backup_data")] + pub dataset_id: String, +} +#[derive(Debug, Serialize, Deserialize, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Config)] +pub struct Youtube { + /// The path to the client secret file for the youtube API + #[config(default = "auth/youtube_client_secret.json")] + pub client_secret_path: String, + /// The default tags to use for youtube videos. + /// + /// can be overridden per user + #[config(default = "[]")] + pub default_tags: Vec, + /// The default description template to use for youtube videos. + /// + /// can be overridden per user + /// + #[config(default = "test description for \"$$video_title$$\"")] + pub default_description_template: String, + /// The default for the targeted duration (in minutes) a youtube video should be. + /// + /// If the video is longer than the hard cap it will be split so + /// each part except for the last will have the length of the soft cap. + /// + /// can be overridden per user + #[config(default = 300)] + pub default_video_length_minutes_soft_cap: i64, + /// The default for the maximum duration (in minutes) a youtube video should be. + /// + /// If the video is longer than this, it will be split into multiple + /// videos (each besides the last the length of the soft cap). + /// + /// can be overridden per user + #[config(default = 359)] + pub default_video_length_minutes_hard_cap: i64, +} +#[derive(Debug, Serialize, Deserialize, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Config)] +pub struct Twitch { + /// The client ID for the Twitch API + pub client_id: String, + + /// The client secret for the Twitch API + pub client_secret: String, + + /// This is the Client-ID used for downloading videos. + #[config(default = "kimne78kx3ncx6brgo4mv6wki5h1ko")] + pub downloader_id: String, + + /// The number of threads to use for downloading videos. + #[config(default = 50)] + pub downloader_thread_count: u64, +} diff --git a/tests/test.rs b/tests/test.rs new file mode 100644 index 0000000..d345bcc --- /dev/null +++ b/tests/test.rs @@ -0,0 +1,22 @@ +#[cfg(test)] +mod test { + use backup_config::*; + use confique::Config; + + #[test] + fn test_config() { + let conf = Conf::builder() + .file("./test_data/simple.toml") + .file("./tests/test_data/simple.toml") + .load() + .unwrap(); + assert_eq!(conf.db_url, "sqlite://data.db?mode=rwc"); + } + + #[test] + fn print_template_toml() { + use confique::toml::{template, FormatOptions}; + let template_out = template::(FormatOptions::default()); + println!("template_out: \n```\n{}\n```", template_out); + } +} diff --git a/tests/test_data/simple.toml b/tests/test_data/simple.toml new file mode 100644 index 0000000..d2b052a --- /dev/null +++ b/tests/test_data/simple.toml @@ -0,0 +1,73 @@ +# The Database Connection URL +# +# Default value: "sqlite://data.db?mode=rwc" +#db_url = "sqlite://data.db?mode=rwc" + +# The path to the folder where the videos will be downloaded to. +# +# Default value: "/var/tmp/twba/videos/" +#download_folder_path = "/var/tmp/twba/videos/" + +# How many videos should be downloaded at the same time. +# +# If this number is reached because the uploader can't keep up, the downloader will wait until +# the number of downloads is below this number again. +# +# Set to 0 or leave empty to disable the limit. +#maximum_downloaded_videos = + +[twitch] +# The client ID for the Twitch API +# +# Required! This value must be specified. +client_id = "YOUR_CLIENT_ID_HERE" + +# The client secret for the Twitch API +# +# Required! This value must be specified. +client_secret = "YOUR_CLIENT_SECRET_HERE" + +# This is the Client-ID used for downloading videos. +# +# Default value: "kimne78kx3ncx6brgo4mv6wki5h1ko" +#downloader_id = "kimne78kx3ncx6brgo4mv6wki5h1ko" + +# The number of threads to use for downloading videos. +# +# Default value: 50 +#downloader_thread_count = 50 + +[google] +# The path for the auth code file. +# +# This file will contain the response of the auth request. +# +# The file should be deleted after the auth response is used. +# +# Default value: "tmp/twba/auth/code.txt" +#path_auth_code = "tmp/twba/auth/code.txt" + +# The path for the auth cache file for each user. '{user}' will be replaced with the user's login. +# +# Default value: "tmp/twba/auth/{user}.txt" +#path_auth_cache = "tmp/twba/auth/{user}.txt" + +# Decides if the auth should go to the localhost or the public IP/Server +# +# Default value: false +#local_auth_redirect = false + +# The frequency for reading the auth file in seconds +# +# Default value: 10 +#auth_file_read_frequency = 10 + +# The timeout for reading the auth file in seconds +# +# Default value: 86400 +#auth_file_read_timeout = 86400 + +# The project ID for the Google Cloud project +# +# Default value: "twitchbackup-1" +#project_id = "twitchbackup-1"