From c1779265af924906f7df7f5fe8fb6e387e56ebc2 Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Wed, 22 Mar 2017 14:40:54 +0100 Subject: [PATCH] ability to skip game or movie content --- src/gog.rs | 11 ++++++++++- src/main.rs | 30 +++++++++++++++++++++++++++--- src/models.rs | 6 ++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/gog.rs b/src/gog.rs index 06d520e..33d4b71 100644 --- a/src/gog.rs +++ b/src/gog.rs @@ -124,7 +124,9 @@ impl<'a> Gog<'a> { storage_path: &str, storage_path_movies: &str, os_filters: &Vec, - language_filters: &Vec) + language_filters: &Vec, + skip_movies: bool, + skip_games: bool) -> Result<(), GogError> { let configfiles = ConfigFiles::new(); let mut config: Config = match configfiles.load("config.json") { @@ -140,6 +142,8 @@ impl<'a> Gog<'a> { extras: HashMap::new(), os_filters: os_filters.clone(), language_filters: language_filters.clone(), + skip_movies: skip_movies, + skip_games: skip_games, } } }; @@ -160,6 +164,11 @@ impl<'a> Gog<'a> { } }; + if (game.is_movie && skip_movies) || (!game.is_movie && skip_games) { + info!("filtering {}", game.title); + continue; + } + let game_hash = models::get_hash(&game); if game_hash_saved == game_hash { diff --git a/src/main.rs b/src/main.rs index 9ae3ee8..fc9ca41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ //! -s, --storage Sets the download folder (defaults to the working directory). //! ``` //! -//! An incomplete list of languages on gog: `english, český, deutsch, español, français, magyar, polski, русский, 中文` +//! An incomplete list of languages on gog: `english, český, deutsch, español, français, italiano, magyar, polski, русский, 中文` extern crate chrono; extern crate clap; @@ -73,6 +73,16 @@ fn main() { .value_name("FILTER") .help("Only sync files for this comma seperated list of languages.") .takes_value(true)) + .arg(Arg::with_name("skip-movies") + .short("f") + .long("skip-movies") + .help("Skip movie content.") + .takes_value(false)) + .arg(Arg::with_name("skip-games") + .short("g") + .long("skip-games") + .help("Skip game content.") + .takes_value(false)) .get_matches(); let configfiles = ConfigFiles::new(); @@ -88,7 +98,7 @@ fn main() { let download_folder_movies: &str = match matches.value_of("movieStorage") { Some(value) => value, - None => config.movie_storage.as_str(), + None => download_folder, }; let os_filters: Vec = match matches.value_of("os") { @@ -101,12 +111,26 @@ fn main() { None => config.language_filters, }; + let skip_movies = if matches.is_present("skip-movies") { + true + } else { + config.skip_movies + }; + + let skip_games = if matches.is_present("skip-games") { + true + } else { + config.skip_games + }; + let mut http_client = Http::new(); let mut gog = Gog::new(&mut http_client); gog.login().unwrap(); gog.sync(download_folder, download_folder_movies, &os_filters, - &language_filters) + &language_filters, + skip_movies, + skip_games) .unwrap(); } diff --git a/src/models.rs b/src/models.rs index 6f41c92..2e3e43a 100644 --- a/src/models.rs +++ b/src/models.rs @@ -46,6 +46,10 @@ pub struct Config { pub os_filters: Vec, #[serde(default = "default_list")] pub language_filters: Vec, + #[serde(default)] + pub skip_movies: bool, + #[serde(default)] + pub skip_games: bool, } fn default_map() -> HashMap { @@ -66,6 +70,8 @@ impl Config { extras: HashMap::new(), os_filters: Vec::new(), language_filters: Vec::new(), + skip_movies: false, + skip_games: false, } } }