Skip to content

Instantly share code, notes, and snippets.

@fay59
Last active November 8, 2025 10:57
Show Gist options
  • Select an option

  • Save fay59/8f719cd81967e0eb2234897491e051ec to your computer and use it in GitHub Desktop.

Select an option

Save fay59/8f719cd81967e0eb2234897491e051ec to your computer and use it in GitHub Desktop.
Download entire iCloud shared albums
#!/bin/bash
# requires jq
# arg 1: iCloud web album URL
# arg 2: folder to download into (optional)
function curl_post_json {
curl -sH "Content-Type: application/json" -X POST -d "@-" "$@"
}
BASE_API_URL="https://p23-sharedstreams.icloud.com/$(echo $1 | cut -d# -f2)/sharedstreams"
pushd $2 > /dev/null
STREAM=$(echo '{"streamCtag":null}' | curl_post_json "$BASE_API_URL/webstream")
CHECKSUMS=$(echo $STREAM | jq -r '.photos[] | [(.derivatives[] | {size: .fileSize | tonumber, value: .checksum})] | max_by(.size | tonumber).value')
echo $STREAM \
| jq -c "{photoGuids: [.photos[].photoGuid]}" \
| curl_post_json "$BASE_API_URL/webasseturls" \
| jq -r '.items[] | "https://" + .url_location + .url_path' \
| while read URL; do
for CHECKSUM in $CHECKSUMS; do
if echo $URL | grep $CHECKSUM > /dev/null; then
curl -sOJ $URL &
break
fi
done
done
popd > /dev/null
wait
@MattGrayYes
Copy link

I've made some modifications to the script to suit my use case

  • now uses the file name from the Content-Disposition header rather than the URL when checking filenames.
    • I had issues with it not seeing space symbols in filenames because the url had + characters instead
  • checks for files in the download folder that aren't part of the icloud shared album, and deletes them
    • only if they're a media file with a known extension
    • and only if you're running this while specifying an output directory

It's here: icloud_photo.sh

@Achiness4732
Copy link

Achiness4732 commented Sep 4, 2025

Never coded in java, but I guess the script curl_post_json is doing a json post on the serve using curl. I google-translated it into bash. Unfortunately, the curl post returned null from https://p23-sharedstreams.icloud.com/$(echo $1 | cut -d# -f2)/sharedstreams. Can someone help to point to a working stream server that still provides the webstream API. Thanks a lot. Just want to download a lot of pictures from kid's soccer game.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment