filter movies by resolution
This commit is contained in:
parent
0ec9a41bff
commit
984aff3242
5 changed files with 62 additions and 23 deletions
34
src/gog.rs
34
src/gog.rs
|
@ -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()
|
||||
|
|
29
src/main.rs
29
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 <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();
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue