Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an option to download a xapk and made apk the default downloaded type #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ Options:
-e, --email <google_email>
Google account email address (required if download source is Google Play)
-t, --aas-token <google_aas_token>
Google aas token (required if download source is Google Play)
Google aas token (required if download source is Google Play)
--accept-tos
Accept Google Play Terms of Service
-s, --sleep-duration <sleep_duration>
Sleep duration (in ms) before download requests [default: 0]
-r, --parallel <parallel>
The number of parallel APK fetches to run at a time [default: 4]
-x, --xapk
Download a xapk file instead of an apk file. This only applies to APKPure and not all apps have a xapk available.
-h, --help
Print help
-V, --version
Expand Down
23 changes: 14 additions & 9 deletions src/apkpure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@ pub async fn download_apps(
parallel: usize,
sleep_duration: u64,
outpath: &Path,
xapk_bundle: bool
) {
let mp = Rc::new(MultiProgress::new());
let http_client = Rc::new(reqwest::Client::new());
let headers = http_headers();
let re = Rc::new(Regex::new(crate::consts::APKPURE_DOWNLOAD_URL_REGEX).unwrap());

futures_util::stream::iter(
apps.into_iter().map(|app| {
let (app_id, app_version) = app;
let http_client = Rc::clone(&http_client);
let re = Rc::clone(&re);
let headers = headers.clone();
let mp = Rc::clone(&mp);
let mp_log = Rc::clone(&mp);
Expand All @@ -63,13 +62,19 @@ pub async fn download_apps(
.get(versions_url)
.headers(headers)
.send().await.unwrap();
if let Some(app_version) = app_version {
let regex_string = format!("[[:^digit:]]{}:(?s:.)+?{}", regex::escape(&app_version), crate::consts::APKPURE_DOWNLOAD_URL_REGEX);
let re = Regex::new(&regex_string).unwrap();
download_from_response(versions_response, Box::new(Box::new(re)), app_string, outpath, mp).await;
} else {
download_from_response(versions_response, Box::new(re), app_string, outpath, mp).await;
}

let download_url_regex = match xapk_bundle {
true => format!("(XAPKJ)..{}", crate::consts::APKPURE_DOWNLOAD_URL_REGEX),
false => format!("[^X](APKJ)..{}", crate::consts::APKPURE_DOWNLOAD_URL_REGEX)
};

let regex_string = if let Some(app_version) = app_version {
format!("[[:^digit:]]{}:(?s:.)+?{}", regex::escape(&app_version) , download_url_regex) }
else {
format!("[[:^digit:]]:(?s:.)+?{}" , download_url_regex)};

let re = Regex::new(&regex_string).unwrap();
download_from_response(versions_response, Box::new(Box::new(re)), app_string, outpath, mp).await;
}
})
).buffer_unordered(parallel).collect::<Vec<()>>().await;
Expand Down
9 changes: 8 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn app() -> Command {
)
.arg(
Arg::new("google_aas_token")
.help("Google aas token (required if download source is Google Play)")
.help("Google aas token (required if download source is Google Play)")
.short('t')
.long("aas-token")
.action(ArgAction::Set)
Expand Down Expand Up @@ -156,4 +156,11 @@ pub fn app() -> Command {
.index(1)
.required_unless_present("google_oauth_token"),
)
.arg(
Arg::new("xapk")
.help("Download a xapk file instead of an apk file. This only applies to APKPure and not all apps have a xapk available.")
.short('x')
.long("xapk")
.action(ArgAction::SetTrue)
)
}
2 changes: 1 addition & 1 deletion src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub const APKPURE_VERSIONS_URL_FORMAT: &str = "https://api.pureapk.com/m/v3/cms/app_version?hl=en-US&package_name=";
pub const APKPURE_DOWNLOAD_URL_REGEX: &str = r"(X?APKJ)..(https?://(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*))";
pub const APKPURE_DOWNLOAD_URL_REGEX: &str = r"(https?://(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*))";
pub const FDROID_REPO: &str = "https://f-droid.org/repo";
pub const FDROID_INDEX_FINGERPRINT: &[u8] = &[67, 35, 141, 81, 44, 30, 94, 178, 214, 86, 159, 74, 58, 251, 245, 82, 52, 24, 184, 46, 10, 62, 209, 85, 39, 112, 171, 185, 169, 201, 204, 171];
pub const FDROID_SIGNATURE_BLOCK_FILE_REGEX: &str = r"^META-INF/.*\.(DSA|EC|RSA)$";
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ async fn main() {

match download_source {
DownloadSource::APKPure => {
apkpure::download_apps(list, parallel, sleep_duration, &outpath.unwrap()).await;
if let Some(true) = matches.get_one::<bool>("xapk") {
apkpure::download_apps(list, parallel, sleep_duration, &outpath.unwrap(), true).await;
} else {
apkpure::download_apps(list, parallel, sleep_duration, &outpath.unwrap(), false).await;
}
}
DownloadSource::GooglePlay => {
let mut email = matches.get_one::<String>("google_email").map(|v| v.to_string());
Expand Down