| Crates.io | icloud-album-rs |
| lib.rs | icloud-album-rs |
| version | 0.5.0 |
| created_at | 2025-05-04 00:25:46.311469+00 |
| updated_at | 2025-05-04 22:51:13.313938+00 |
| description | A Rust library for interacting with iCloud shared albums |
| homepage | |
| repository | https://github.com/harperreed/icloud-album-parser |
| max_upload_size | |
| id | 1659262 |
| size | 227,404 |
A Rust library for interacting with iCloud shared albums.
This library allows you to fetch metadata and photos from iCloud shared albums using a token. It provides a simple, async API to:
Add this to your Cargo.toml:
[dependencies]
icloud-album-rs = "0.4.0"
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
use icloud_album_rs::get_icloud_photos;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Your iCloud shared album token
let token = "your_shared_album_token";
// Fetch photos and metadata
let response = get_icloud_photos(token).await?;
// Print album info
println!("Album: {}", response.metadata.stream_name);
println!("Owner: {} {}",
response.metadata.user_first_name,
response.metadata.user_last_name
);
println!("Photos: {}", response.photos.len());
// Print information about each photo
for (i, photo) in response.photos.iter().enumerate() {
println!("Photo {}: {}", i + 1, photo.photo_guid);
// Print the URL for each derivative
for (key, derivative) in &photo.derivatives {
if let Some(url) = &derivative.url {
println!(" Derivative {}: {} ({}x{})",
key, url, derivative.width.unwrap_or(0), derivative.height.unwrap_or(0));
}
}
}
Ok(())
}
The library includes several examples in the examples/ directory:
fetch_album.rs: Basic example showing how to fetch and display album informationalbum_info.rs: More detailed album metadata display with pretty formattingdownload_photos.rs: Shows how to download photos from an album to your local machineAll examples require an iCloud shared album token. This is the string that appears after the URL when you share an album (e.g., https://share.icloud.com/photos/abc1234defg5678).
# Display detailed album information including all photos and their URLs
cargo run --example fetch_album -- "your_shared_album_token"
# Display formatted album information and a summary of the first 5 photos
cargo run --example album_info -- "your_shared_album_token"
# With logging enabled (for debugging)
RUST_LOG=debug cargo run --example album_info -- "your_shared_album_token"
# Download all photos from the album to the specified directory
cargo run --example download_photos -- "your_shared_album_token" "./download_dir"
The download example will:
The main response type is ICloudResponse which contains:
metadata: Information about the album (name, owner, etc.)photos: A vector of Image objectsEach Image contains:
photo_guid: A unique identifier for the photoderivatives: A map of derivative identifiers to Derivative objectsEach Derivative contains:
checksum: A unique identifier for the derivativefile_size: Size in bytes (can be string or number in API)width, height: Dimensions in pixels (can be string or number in API)url: The download URL for the derivativelog crateThe library includes a comprehensive test suite:
Run the basic unit tests with:
cargo test
Some tests are marked with #[ignore] to avoid runtime conflicts or external API calls.
To run all tests including those marked with #[ignore]:
./scripts/run_all_tests.sh
This script runs all tests, including those with separate tokio runtimes, in a CI-friendly way. It handles tests that require separate tokio runtimes by:
cargo testAlternatively, you can use the unified test runner directly:
cargo test --test run_all_tests
The unified test runner uses a sophisticated detection system to:
To run tests that don't require HTTP mocking:
cargo run --example static_tests
These tests verify the core functionality of the library using static JSON responses without making HTTP requests or using mockito.
To run all tests that use mockito:
cargo run --example mockito_standalone
This standalone launcher runs all the mockito tests in separate processes to avoid runtime conflicts. It includes:
You can also run individual test categories directly:
# Run API tests directly
cargo test --test api_test -- --ignored
# Run redirect tests directly
cargo test --test redirect_test -- --ignored
# Run integration tests directly
cargo test --test integration_test -- --ignored
To run tests against the actual iCloud API (requires internet connection):
cargo test --test real_world_test -- --ignored --nocapture
Note: This makes real API calls to Apple's servers.
The library uses the log crate for logging. You can enable and configure logging in your application:
// Initialize the env_logger (or any other logger implementation)
env_logger::init();
// Set log level via RUST_LOG environment variable
// Example: RUST_LOG=info,icloud_album_rs=debug cargo run
The library logs various events:
This is especially useful for diagnosing issues with the iCloud API and handling inconsistencies in responses.
The library includes several features to handle quirks in Apple's iCloud API:
MIT
Contributions are welcome! Please feel free to submit a Pull Request.