🎨 Handle split apks

This commit is contained in:
Nikhil Badyal
2025-04-19 18:51:54 +05:30
parent 0f22fcd029
commit c1f6fc33f6
+22
View File
@@ -1,5 +1,6 @@
"""Apkeep Downloader Class."""
import zipfile
from subprocess import PIPE, Popen
from time import perf_counter
from typing import Any, Self
@@ -25,11 +26,18 @@ class Apkeep(Downloader):
file_name = f"{package_name}.apk"
file_path = self.config.temp_folder / file_name
folder_path = self.config.temp_folder / package_name
zip_path = self.config.temp_folder / f"{package_name}.zip"
# If already downloaded, return it
if file_path.exists():
logger.debug(f"{file_name} already downloaded.")
return file_name
if zip_path.exists():
logger.debug(f"{zip_path.name} already zipped and exists.")
return zip_path.name
# Build apkeep command
cmd = [
"apkeep",
"-a",
@@ -40,6 +48,8 @@ class Apkeep(Downloader):
email,
"-t",
token,
"-o",
"split_apk=true",
self.config.temp_folder_name,
]
logger.debug(f"Running command: {cmd}")
@@ -57,7 +67,19 @@ class Apkeep(Downloader):
msg = f"Command failed with exit code {process.returncode} for app {package_name}"
raise DownloadError(msg)
logger.info(f"Downloading completed for app {package_name} in {perf_counter() - start:.2f} seconds.")
if file_path.exists():
return file_name
if folder_path.exists() and folder_path.is_dir():
# Zip the folder
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
for file in folder_path.rglob("*"):
arcname = file.relative_to(self.config.temp_folder)
zipf.write(file, arcname)
logger.debug(f"Zipped {folder_path} to {zip_path}")
return zip_path.name
msg = "APK file or folder not found after apkeep execution."
raise DownloadError(msg)
def latest_version(self: Self, app: APP, **kwargs: Any) -> tuple[str, str]:
"""Download latest version from Google Play via Apkeep."""