From 984aff32427dbf2151241a5bce6e7e63d0e6315c Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Wed, 22 Mar 2017 16:11:28 +0100 Subject: [PATCH] filter movies by resolution --- CHANGELOG.md | 1 + README.md | 18 ++++++++++++++++-- src/gog.rs | 34 ++++++++++++++++++++++++++++++---- src/main.rs | 29 ++++++++++++----------------- src/models.rs | 3 +++ 5 files changed, 62 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 606fad1..88783e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## 0.2.2 (2017-03-22) +- ability to filter movies by resolution - ability to save movies seperately - default value for storage config (fixes #6) - ability to skip movie and game content diff --git a/README.md b/README.md index b674676..41bf72b 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,16 @@ A bare configuration with default values before first use: - *data*: A map, data url => hash - *extras*: A map, extra url => hash - *osFilters*: An array of operating systems. If it is not empty, game data is limited to the ones in the list. -Valid values are `linux`, `mac` and `windows` - *languageFilters*: An array of languages. If it is not empty, game data is limited to the ones in the list. +- *resolutionFilters*: An array of resolutions. If it is not empty, movie data is limited to the ones in the list. - *skipMovies*: Whether to skip movie content - *skipGames*: Whether to skip game content +Valid values for *osFilter*: +- `linux` +- `mac` +- `windows` + An incomplete list of languages on gog: - `english` - `český` @@ -63,6 +68,13 @@ An incomplete list of languages on gog: - `русский` - `中文` +An incomplete list of resolutions on gog: +- `DVD` +- `576p` +- `720p` +- `1080p` +- `4k` + You should have no need of changing `content`, `data` or `extras`, as these are used to determine whether specific content is up to date. @@ -71,7 +83,8 @@ used to determine whether specific content is up to date. If you want to see the information log while running set `RUST_LOG=info`. ``` -LAGS] [OPTIONS] +USAGE: + gog-sync [FLAGS] [OPTIONS] FLAGS: -h, --help Prints help information @@ -85,6 +98,7 @@ OPTIONS: -m, --movie-storage Sets the download folder for movies (defaults to the working directory). -o, --os Only sync files for this comma seperated list of operating systems. Valid values are 'linux', 'mac' and 'windows'. + -r, --resolution Only sync movies for this comma seperated list of resolutions. ``` --- diff --git a/src/gog.rs b/src/gog.rs index 6190fa7..f0baebe 100644 --- a/src/gog.rs +++ b/src/gog.rs @@ -125,6 +125,7 @@ impl<'a> Gog<'a> { storage_path_movies: &str, os_filters: &Vec, language_filters: &Vec, + resolution_filters: &Vec, skip_movies: bool, skip_games: bool) -> Result<(), GogError> { @@ -142,6 +143,7 @@ impl<'a> Gog<'a> { extras: HashMap::new(), os_filters: os_filters.clone(), language_filters: language_filters.clone(), + resolution_filters: resolution_filters.clone(), skip_movies: skip_movies, skip_games: skip_games, } @@ -156,7 +158,10 @@ impl<'a> Gog<'a> { None => u64::min_value(), }; - let content = match self.get_content(content_id, &os_filters, &language_filters) { + let content = match self.get_content(content_id, + &os_filters, + &language_filters, + &resolution_filters) { Ok(value) => value, Err(error) => { error!("{}: {}", &content_id, error); @@ -329,7 +334,8 @@ impl<'a> Gog<'a> { fn get_content(&mut self, content_id: u64, os_filters: &Vec, - language_filters: &Vec) + language_filters: &Vec, + resolution_filters: &Vec) -> Result { let content_uri = self.content_uri(content_id); debug!("looking for information at {}...", &content_uri); @@ -392,11 +398,31 @@ impl<'a> Gog<'a> { for real_download in real_downloads.as_array() { for download in real_download { if !download.is_object() || - !download.as_object().unwrap().contains_key("manualUrl") { - error!("Skipping an installer for {}", content.title); + !download.as_object().unwrap().contains_key("manualUrl") || + !download.as_object().unwrap().contains_key("name") { + error!("Skipping data for {}", content.title); continue; } + let name: &str = download["name"].as_str().unwrap(); + + + if content.is_movie && !resolution_filters.is_empty() { + let mut found_resolution = false; + for resolution_filter in resolution_filters { + let filter = format!("({})", resolution_filter); + if name.ends_with(&filter) { + found_resolution = true; + break; + } + } + + if !found_resolution { + info!("Skipping {}: not a suitable resolution.", name); + continue; + } + } + let data = Data { manual_url: String::from(download["manualUrl"] .as_str() diff --git a/src/main.rs b/src/main.rs index aafeff2..34488fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,21 +1,4 @@ //! Synchronizes a [GOG](https://www.gog.com/) library with a local folder. -//! -//! ``` -//! USAGE: -//! gog-sync [OPTIONS] -//! -//! FLAGS: -//! -h, --help Prints help information -//! -V, --version Prints version information -//! -//! OPTIONS: -//! -l, --language Only sync files for this comma seperated list of languages. -//! -o, --os Only sync files for this comma seperated list of operating systems. -//! Valid values are linux, mac and windows. -//! -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, italiano, magyar, polski, русский, 中文` extern crate chrono; extern crate clap; @@ -73,6 +56,12 @@ fn main() { .value_name("FILTER") .help("Only sync files for this comma seperated list of languages.") .takes_value(true)) + .arg(Arg::with_name("resolution") + .short("r") + .long("resolution") + .value_name("FILTER") + .help("Only sync movies for this comma seperated list of resolutions.") + .takes_value(true)) .arg(Arg::with_name("skip-movies") .short("f") .long("skip-movies") @@ -111,6 +100,11 @@ fn main() { None => config.language_filters, }; + let resolution_filters: Vec = match matches.value_of("resolution") { + Some(value) => value.split(',').map(String::from).collect(), + None => config.resolution_filters, + }; + let skip_movies = if matches.is_present("skip-movies") { true } else { @@ -130,6 +124,7 @@ fn main() { download_folder_movies, &os_filters, &language_filters, + &resolution_filters, skip_movies, skip_games) .unwrap(); diff --git a/src/models.rs b/src/models.rs index 2cb0366..2a07f0b 100644 --- a/src/models.rs +++ b/src/models.rs @@ -46,6 +46,8 @@ pub struct Config { pub os_filters: Vec, #[serde(default = "default_list")] pub language_filters: Vec, + #[serde(default = "default_list")] + pub resolution_filters: Vec, #[serde(default)] pub skip_movies: bool, #[serde(default)] @@ -70,6 +72,7 @@ impl Config { extras: HashMap::new(), os_filters: Vec::new(), language_filters: Vec::new(), + resolution_filters: Vec::new(), skip_movies: false, skip_games: false, }