filter movies by resolution

This commit is contained in:
Sebastian Hugentobler 2017-03-22 16:11:28 +01:00
parent 0ec9a41bff
commit 984aff3242
5 changed files with 62 additions and 23 deletions

View File

@ -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

View File

@ -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 <FOLDER> Sets the download folder for movies (defaults to the working directory).
-o, --os <FILTER> Only sync files for this comma seperated list of operating systems.
Valid values are 'linux', 'mac' and 'windows'.
-r, --resolution <FILTER> Only sync movies for this comma seperated list of resolutions.
```
---

View File

@ -125,6 +125,7 @@ impl<'a> Gog<'a> {
storage_path_movies: &str,
os_filters: &Vec<String>,
language_filters: &Vec<String>,
resolution_filters: &Vec<String>,
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<String>,
language_filters: &Vec<String>)
language_filters: &Vec<String>,
resolution_filters: &Vec<String>)
-> Result<Content, GogError> {
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()

View File

@ -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 <FILTER> Only sync files for this comma seperated list of languages.
//! -o, --os <FILTER> Only sync files for this comma seperated list of operating systems.
//! Valid values are linux, mac and windows.
//! -s, --storage <FOLDER> 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<String> = 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();

View File

@ -46,6 +46,8 @@ pub struct Config {
pub os_filters: Vec<String>,
#[serde(default = "default_list")]
pub language_filters: Vec<String>,
#[serde(default = "default_list")]
pub resolution_filters: Vec<String>,
#[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,
}