about summary refs log tree commit diff
path: root/scripts/immich-api-tool
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xscripts/immich-api-tool (renamed from bundles/immich/files/immich-api-tool)23
1 files changed, 16 insertions, 7 deletions
diff --git a/bundles/immich/files/immich-api-tool b/scripts/immich-api-tool
index d0a1a41..14212a9 100755
--- a/bundles/immich/files/immich-api-tool
+++ b/scripts/immich-api-tool
@@ -1,11 +1,12 @@
 #!/bin/sh
+# shellcheck disable=SC3043 # local is basically supported
 set -eu
 
 API_URL=https://photos.gzr.im/api
 API_KEY=zaJUJGHpFqY9OA6kAhuauTj9tC1YVfA8umtZc6ls8U
 
 request() {
-  ENDPOINT=${1:?}
+  local ENDPOINT="${1:?}"
   shift 1
 
   curl -sSfL "${API_URL}${ENDPOINT}" \
@@ -28,22 +29,30 @@ searchFavorites() {
 # requires '{"assetIds":["list","of","ids",...]}' on stdin
 # downloads to PWD
 downloadArchive() {
+  local OUTPUT="${1:?}"
+
   request '/download/archive' \
     -H 'Accept: application/octet-stream' \
     -d @- \
-    -o "archive.zip" \
+    -o "$OUTPUT" \
     --no-silent
 }
 
+searchAlbum() {
+  local ID="${1:?}"
+
+  request "/albums/$ID"
+}
+
 main() {
   validateAccessToken || exit 1
 
-  # download favorites as archive
-  searchFavorites |
-    jq '[.assets.items[].id] | {assetIds:.}' -rc |
-    downloadArchive
+  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
+main $@
 exit 0