def extract_icon_io(apk: APK, max_dpi=640) -> str: """Extracts an apk image to the filesystem and creates a naive cache of images for optimization of incremental runs""" try: apk_name = apk.get_app_name() image_name = f"{apk_name}.png" image_path = Path( BASE_DIR, 'app_icon', ) image_path.mkdir(parents=True, exist_ok=True) image = apk.get_file(apk.get_app_icon(max_dpi=max_dpi)) pillow_image = Image.open(BytesIO(image)) pillow_image.verify() except Exception as e: log.error(f"IMAGE IS NOT VALID {apk.filename} \n {e.__cause__}") return apk.filename try: with open(Path(image_path, image_name), 'wb') as output: log.info('writing image to ' + str(image_path)) output.write(image) except Exception as e: log.warning(f'could not save image for {image_name}') log.error(e) return image_name
def get_meta_from_apk(apk: APK) -> ApkMetadata: return int(apk.version_code), Path( apk.filename), apk.get_app_name(), apk.version_name