From ba08266351aaf87e1c523a6ba13a0db7fa4857dd Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 12 Apr 2024 12:10:57 +0200 Subject: [PATCH] feat(krpano): support directional image downloads Enhanced the KRPanoDownloader and KRPanoConverter classes to handle downloads and conversions for directional images specified by characters (e.g., 'f' for front, 'r' for right, etc.) in addition to the existing numeric tile-based system. This update adds a new regex pattern to match directional images and updates the URL schema logic to accommodate character-based tile descriptions, improving support for a wider range of image types in panoramic views. This change allows for more flexible and intuitive handling of different image naming conventions, making the module more adaptable to various krpano configurations. --- src/pix360_krpano/modules.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/pix360_krpano/modules.py b/src/pix360_krpano/modules.py index 2a78dc5..d828552 100644 --- a/src/pix360_krpano/modules.py +++ b/src/pix360_krpano/modules.py @@ -17,7 +17,8 @@ class KRPanoDownloader(DownloaderModule): self.logger = logging.getLogger("pix360") REGEX_FULL: List[Tuple[str, int, Dict[str, str]]] = [ - (r"\d+/\d+/\d+_\d+\.jpg", DownloaderModule.CERTAINTY_PROBABLE, {}), + (r"\d+/\d+/\d+_\d+\.jpg", DownloaderModule.CERTAINTY_PROBABLE, {}), + (r"[frblud]/\d+/\d+_\d+\.jpg", DownloaderModule.CERTAINTY_PROBABLE, {}), ] REGEX_SIMPLE: List[Tuple[str, int, Dict[str, str]]] = [ @@ -94,7 +95,11 @@ class KRPanoConverter: assert "_" in parts[-1] parts[-1] = "%i_%i.jpg" parts[-2] = "%i" - parts[-3] = parts[-3].rstrip("0123456789") + "%i" + + if not parts[-3].isnumeric(): + parts[-3] = parts[-3].rstrip("frblud") + "%s" + else: + parts[-3] = parts[-3].rstrip("0123456789") + "%i" return "/".join(parts) @@ -148,7 +153,12 @@ class KRPanoConverter: while True: try: - res = HTTPRequest(schema % (tile, maxzoom, y, x)).open() + if "%s" in schema.split("/")[-3]: + tile_char = "frblud"[tile] + else: + tile_char = tile + + res = HTTPRequest(schema % (tile_char, maxzoom, y, x)).open() assert res.getcode() == 200 content = res.read() fo = ContentFile(content, name=f"{tile}_{maxzoom}_{y}_{x}.jpg")