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.
This commit is contained in:
Kumi 2024-04-12 12:10:57 +02:00
parent 2fb338917c
commit ba08266351
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -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")