summaryrefslogtreecommitdiff
path: root/immich.py
diff options
context:
space:
mode:
authorTim Keller <tjkeller.xyz>2025-05-09 21:58:54 -0500
committerTim Keller <tjkeller.xyz>2025-05-09 21:58:54 -0500
commit145de3311cb9f32ac0bc9842b0600fcad84fed16 (patch)
tree2822a41929eac3758d0ffe7a7d1b8cf49158a09e /immich.py
parentb487f62ba7cd7dbbcadb2b5704ec1c99f6578390 (diff)
downloadimmich-frame-145de3311cb9f32ac0bc9842b0600fcad84fed16.tar.xz
immich-frame-145de3311cb9f32ac0bc9842b0600fcad84fed16.zip
add support for downloading new images from immich api on a separate thread
Diffstat (limited to 'immich.py')
-rw-r--r--immich.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/immich.py b/immich.py
new file mode 100644
index 0000000..1f1ccb8
--- /dev/null
+++ b/immich.py
@@ -0,0 +1,33 @@
+import requests
+from io import BytesIO
+
+from texture import ImageTexture
+
+
+class ImmichConnector:
+ def __init__(self, server_url, api_key):
+ self.server_url = server_url.removesuffix("/")
+ self.api_key = api_key
+
+ def _request(self, endpoint):
+ return requests.get(f"{self.server_url}/api/{endpoint}", headers={ "x-api-key": self.api_key })
+
+ def load_album_assets(self, key):
+ response = self._request(f"albums/{key}")
+ if response.status_code != 200: return
+
+ data = response.json()
+ return data["assets"]
+
+ def load_image(self, pd, key, exif=None):
+ response = self._request(f"assets/{key}/thumbnail?size=fullsize")
+ if response.status_code != 200: return
+
+ image_data = BytesIO(response.content)
+ it = ImageTexture(image_data, exif)
+ pd.textures.append(it)
+ print(f"Loaded image {key}")
+
+ def idle(self, pd):
+ for asset in self.load_album_assets("bac029a5-972b-4519-bce0-a0d74add3969"):
+ self.load_image(pd, asset["id"], asset["exifInfo"])