diff --git a/src/main.rs b/src/main.rs index 6bf4598..20659bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,6 +122,7 @@ //! * Using Tor will make it a lot more likely that the download will fail. use std::collections::HashMap; +use std::env; use std::error::Error; use std::fs::{self, File}; use std::io::{self, Write, Read}; @@ -218,7 +219,35 @@ async fn main() { None => HashMap::new() }; - let oauth_token = matches.get_one::("google_oauth_token").map(|v| v.to_string()); + let mut email = matches.get_one::("google_email").map(|v| v.to_string()) + .or_else(|| env::var("APKEEP_GOOGLE_EMAIL").ok()); + let mut aas_token = matches.get_one::("google_aas_token").map(|v| v.to_string()) + .or_else(|| env::var("APKEEP_GOOGLE_AAS_TOKEN").ok()); + + let ini_file = matches.get_one::("ini").map(|ini_file| { + match fs::canonicalize(ini_file) { + Ok(ini_file) if Path::new(&ini_file).is_file() => { + ini_file + }, + _ => { + println!("{}\n\nSpecified ini is not a valid file", usage); + std::process::exit(1); + }, + } + }); + + if email.is_none() || aas_token.is_none() { + if let Ok(conf) = load_config(ini_file) { + if email.is_none() { + email = conf.get("google", "email"); + } + if aas_token.is_none() { + aas_token = conf.get("google", "aas_token"); + } + } + } + + let mut oauth_token = matches.get_one::("google_oauth_token").map(|v| v.to_string()); if oauth_token.is_some() { download_source = DownloadSource::GooglePlay; } @@ -303,7 +332,9 @@ async fn main() { apkpure::download_apps(list, parallel, sleep_duration, &outpath.unwrap()).await; } DownloadSource::GooglePlay => { - let mut email = matches.get_one::("google_email").map(|v| v.to_string()); + if aas_token.is_none() && oauth_token.is_none() { + oauth_token = env::var("APKEEP_GOOGLE_OAUTH_TOKEN").ok(); + } if email.is_some() && oauth_token.is_some() { google_play::request_aas_token( @@ -312,35 +343,11 @@ async fn main() { options, ).await; } else { - let mut aas_token = matches.get_one::("google_aas_token").map(|v| v.to_string()); let accept_tos = match matches.get_one::("list_versions") { Some(true) => true, _ => false, }; - let ini_file = matches.get_one::("ini").map(|ini_file| { - match fs::canonicalize(ini_file) { - Ok(ini_file) if Path::new(&ini_file).is_file() => { - ini_file - }, - _ => { - println!("{}\n\nSpecified ini is not a valid file", usage); - std::process::exit(1); - }, - } - }); - - if email.is_none() || aas_token.is_none() { - if let Ok(conf) = load_config(ini_file) { - if email.is_none() { - email = conf.get("google", "email"); - } - if aas_token.is_none() { - aas_token = conf.get("google", "aas_token"); - } - } - } - if email.is_none() { let mut prompt_email = String::new(); print!("Email: ");