about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2025-09-07 17:32:13 +0200
committerRobert Günzler <r@gnzler.io>2025-09-25 13:16:25 +0200
commit99e5cfd96016c2816affda1ceba50e2673ba42fc (patch)
treeb10a2bc2be79f8afe277718ef2b26f1a4a6c1fb8 /scripts
parent7f9285e827dab648e72e1fbcbf4cd4e6709fb591 (diff)
immich: move api tool to root
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/immich-api-tool58
1 files changed, 58 insertions, 0 deletions
diff --git a/scripts/immich-api-tool b/scripts/immich-api-tool
new file mode 100755
index 0000000..14212a9
--- /dev/null
+++ b/scripts/immich-api-tool
@@ -0,0 +1,58 @@
+#!/bin/sh
+# shellcheck disable=SC3043 # local is basically supported
+set -eu
+
+API_URL=https://photos.gzr.im/api
+API_KEY=zaJUJGHpFqY9OA6kAhuauTj9tC1YVfA8umtZc6ls8U
+
+request() {
+  local ENDPOINT="${1:?}"
+  shift 1
+
+  curl -sSfL "${API_URL}${ENDPOINT}" \
+    -H "x-api-key: $API_KEY" \
+    -H 'Content-Type: application/json' \
+    "$@"
+}
+
+validateAccessToken() {
+  request '/auth/validateToken' -X POST >/dev/null
+}
+
+# returns full json response
+searchFavorites() {
+  request '/search/metadata' \
+    -H 'Accept: application/json' \
+    -d '{"isFavorite": true}'
+}
+
+# requires '{"assetIds":["list","of","ids",...]}' on stdin
+# downloads to PWD
+downloadArchive() {
+  local OUTPUT="${1:?}"
+
+  request '/download/archive' \
+    -H 'Accept: application/octet-stream' \
+    -d @- \
+    -o "$OUTPUT" \
+    --no-silent
+}
+
+searchAlbum() {
+  local ID="${1:?}"
+
+  request "/albums/$ID"
+}
+
+main() {
+  validateAccessToken || exit 1
+
+  case "${1:?}" in
+  album-dl) searchAlbum "${2:?}" | jq '[.assets[].id]|{assetIds:.}' -rc | downloadArchive "${3:?}" ;;
+  album-ls) searchAlbum "${2:?}" | jq '.assets[].originalPath' -r ;;
+  esac
+}
+
+test -n "${DEBUG:-}" && set -x
+main $@
+exit 0