Skip to content

Commit

Permalink
Support Google Play API v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Hainish committed Apr 3, 2024
1 parent 2bb9230 commit a69ec9c
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 108 deletions.
33 changes: 23 additions & 10 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn app() -> Command {
.long("app")
.action(ArgAction::Set)
.conflicts_with("csv")
.required_unless_present("csv"),
.required_unless_present_any(["csv", "google_oauth_token"]),
)
.arg(
Arg::new("csv")
Expand Down Expand Up @@ -105,19 +105,31 @@ pub fn app() -> Command {
.required(false),
)
.arg(
Arg::new("google_username")
.help("Google Username (required if download source is Google Play)")
.short('u')
.long("username")
Arg::new("google_oauth_token")
.help("Google oauth token, required to retrieve long-lived aas token")
.long("oauth-token")
.action(ArgAction::Set)
)
.arg(
Arg::new("google_password")
.help("Google App Password (required if download source is Google Play)")
.short('p')
.long("password")
Arg::new("google_email")
.help("Google account email address (required if download source is Google Play)")
.short('e')
.long("email")
.action(ArgAction::Set)
)
.arg(
Arg::new("google_aas_token")
.help("Google aas token (required if download source is Google Play)")
.short('t')
.long("aas-token")
.action(ArgAction::Set)
)
.arg(
Arg::new("google_accept_tos")
.help("Accept Google Play Terms of Service")
.long("accept-tos")
.action(ArgAction::SetTrue)
)
.arg(
Arg::new("sleep_duration")
.help("Sleep duration (in ms) before download requests")
Expand All @@ -141,6 +153,7 @@ pub fn app() -> Command {
Arg::new("OUTPATH")
.help("Path to store output files")
.action(ArgAction::Set)
.index(1),
.index(1)
.required_unless_present("google_oauth_token"),
)
}
66 changes: 56 additions & 10 deletions src/google_play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ pub async fn download_apps(
apps: Vec<(String, Option<String>)>,
parallel: usize,
sleep_duration: u64,
username: &str,
password: &str,
email: &str,
aas_token: &str,
outpath: &Path,
accept_tos: bool,
mut options: HashMap<&str, &str>,
) {
let locale = options.remove("locale").unwrap_or("en_US");
let timezone = options.remove("timezone").unwrap_or("UTC");
let device = options.remove("device").unwrap_or("hero2lte");
let device = options.remove("device").unwrap_or("px_7a");
let split_apk = match options.remove("split_apk") {
Some(val) if val == "1" || val.to_lowercase() == "true" => true,
_ => false,
Expand All @@ -30,14 +29,43 @@ pub async fn download_apps(
Some(val) if val == "1" || val.to_lowercase() == "true" => true,
_ => false,
};
let mut gpa = Gpapi::new(locale, timezone, device);
let mut gpa = Gpapi::new(device, email);

if let Err(err) = gpa.login(username, password).await {
if let Some(locale) = options.remove("locale") {
gpa.set_locale(locale);
}
if let Some(timezone) = options.remove("timezone") {
gpa.set_timezone(timezone);
}

gpa.set_aas_token(aas_token);
if let Err(err) = gpa.login().await {
match err.kind() {
GpapiErrorKind::SecurityCheck | GpapiErrorKind::EncryptLogin => println!("{}", err),
_ => println!("Could not log in to Google Play. Please check your credentials and try again later."),
GpapiErrorKind::TermsOfService => {
if accept_tos {
match gpa.accept_tos().await {
Ok(_) => {
if let Err(_) = gpa.login().await {
println!("Could not log in, even after accepting the Google Play Terms of Service");
std::process::exit(1);
}
println!("Google Play Terms of Service accepted.");
},
_ => {
println!("Could not accept Google Play Terms of Service");
std::process::exit(1);
},
}
} else {
println!("{}\nPlease read the ToS here: https://play.google.com/about/play-terms/index.html\nIf you accept, please pass the --accept-tos flag.", err);
std::process::exit(1);
}
},
_ => {
println!("Could not log in to Google Play. Please check your credentials and try again later. {}", err);
std::process::exit(1);
}
}
std::process::exit(1);
}

let mp = Rc::new(MultiProgress::new());
Expand Down Expand Up @@ -95,6 +123,24 @@ pub async fn download_apps(
).buffer_unordered(parallel).collect::<Vec<()>>().await;
}

pub async fn request_aas_token(
email: &str,
oauth_token: &str,
mut options: HashMap<&str, &str>,
) {
let device = options.remove("device").unwrap_or("px_7a");
let mut api = Gpapi::new(device, email);
match api.request_aas_token(oauth_token).await {
Ok(()) => {
let aas_token = api.get_aas_token().unwrap();
println!("AAS Token: {}", aas_token);
},
Err(_) => {
println!("Error: was not able to retrieve AAS token with the provided OAuth token. Please provide new OAuth token and try again.");
}
}
}

pub fn list_versions(apps: Vec<(String, Option<String>)>) {
for app in apps {
let (app_id, _) = app;
Expand Down
Loading

0 comments on commit a69ec9c

Please sign in to comment.