From 99e5cfd96016c2816affda1ceba50e2673ba42fc Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Sun, 7 Sep 2025 17:32:13 +0200 Subject: immich: move api tool to root MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Robert Günzler --- scripts/immich-api-tool | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 scripts/immich-api-tool (limited to 'scripts/immich-api-tool') 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 -- cgit 1.4.1