diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/immich-api-tool | 58 |
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 |