From 6aa2a5c7c9b8c50f1382ca0b7d3cf57d9972e2b5 Mon Sep 17 00:00:00 2001 From: Dom Whewell Date: Sat, 9 Nov 2024 17:14:38 +0000 Subject: [PATCH] Change to regex to get the extension --- bbot/modules/apkpure.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/bbot/modules/apkpure.py b/bbot/modules/apkpure.py index e7d22489c..c17d25e2c 100644 --- a/bbot/modules/apkpure.py +++ b/bbot/modules/apkpure.py @@ -1,3 +1,4 @@ +import re from pathlib import Path from bbot.modules.base import BaseModule @@ -49,11 +50,14 @@ async def download_apk(self, app_id): if response: attachment = response.headers.get("Content-Disposition", "") if "filename" in attachment: - extension = attachment.split('filename="')[-1].split(".")[-1].strip('"') - content = response.content - file_destination = self.output_dir / app_id / f"{app_id}.{extension}" - with open(file_destination, "wb") as f: - f.write(content) - self.info(f'Downloaded "{app_id}" from "{url}", saved to {file_destination}') - path = file_destination + match = re.search(r'filename="?([^"]+)"?', attachment) + if match: + filename = match.group(1) + extension = filename.split(".")[-1] + content = response.content + file_destination = self.output_dir / app_id / f"{app_id}.{extension}" + with open(file_destination, "wb") as f: + f.write(content) + self.info(f'Downloaded "{app_id}" from "{url}", saved to {file_destination}') + path = file_destination return path