diff --git a/Cargo.lock b/Cargo.lock index a923b34..5db6adb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -484,9 +484,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.43" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50fd97c9dc2399518aa331917ac6f274280ec5eb34e555dd291899745c48ec6f" +checksum = "1fc0e74a703892159f5ae7d3aac52c8e6c392f5ae5f359c70b5881d60aaac318" dependencies = [ "clap_builder", "clap_derive", @@ -504,9 +504,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.43" +version = "4.5.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c35b5830294e1fa0462034af85cc95225a4cb07092c088c55bda3147cfcd8f65" +checksum = "b3e7f4214277f3c7aa526a59dd3fbe306a370daee1f8b7b8c987069cd8e888a8" dependencies = [ "anstream", "anstyle", @@ -516,9 +516,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.41" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" +checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -1581,9 +1581,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760" [[package]] name = "libc" -version = "0.2.174" +version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "libredox" @@ -2030,9 +2030,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.95" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +checksum = "d61789d7719defeb74ea5fe81f2fdfdbd28a803847077cecce2ff14e1472f6f1" dependencies = [ "unicode-ident", ] @@ -2093,7 +2093,7 @@ dependencies = [ "serde", "serde_json", "syn 2.0.104", - "thiserror 2.0.12", + "thiserror 2.0.14", "typify", "unicode-ident", ] @@ -2170,7 +2170,7 @@ checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" dependencies = [ "getrandom 0.2.16", "libredox", - "thiserror 2.0.12", + "thiserror 2.0.14", ] [[package]] @@ -2214,9 +2214,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.22" +version = "0.12.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbc931937e6ca3a06e3b6c0aa7841849b160a90351d6ab467a8b9b9959767531" +checksum = "d429f34c8092b2d42c7c93cec323bb4adeb7c67698f70839adec842ec10c7ceb" dependencies = [ "base64 0.22.1", "bytes", @@ -2748,11 +2748,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.12" +version = "2.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +checksum = "0b0949c3a6c842cbde3f1686d6eea5a010516deb7085f79db747562d4102f41e" dependencies = [ - "thiserror-impl 2.0.12", + "thiserror-impl 2.0.14", ] [[package]] @@ -2768,9 +2768,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.12" +version = "2.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +checksum = "cc5b44b4ab9c2fdd0e0512e6bece8388e214c0749f5862b114cc5b7a25daf227" dependencies = [ "proc-macro2", "quote", @@ -3059,7 +3059,7 @@ dependencies = [ "serde", "serde_json", "syn 2.0.104", - "thiserror 2.0.12", + "thiserror 2.0.14", "unicode-ident", ] @@ -3166,9 +3166,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.17.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cf4199d1e5d15ddd86a694e4d0dffa9c323ce759fea589f00fef9d81cc1931d" +checksum = "f33196643e165781c20a5ead5582283a7dacbb87855d867fbc2df3f81eddc1be" dependencies = [ "getrandom 0.3.3", "js-sys", diff --git a/README.md b/README.md index 9035733..cbdeb1d 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ video backup solution. This tool provides various utilities to manage your Immic - **List** all albums on your Immich server - **Delete** albums (all or empty ones only) - **Auto-create** albums from external libraries folder structure +- **List assets of an album** by album name ### Assets - **List** assets (all or offline only) @@ -105,6 +106,11 @@ Auto-create albums from folder structure: immich-tools albums auto-create --album-name-separator "/" ``` +List assets belonging to a specific album (by album name): +```bash +immich-tools albums list-assets --album "My Album" +``` + ### Assets List all assets: diff --git a/src/args.rs b/src/args.rs index 622180e..70bde87 100644 --- a/src/args.rs +++ b/src/args.rs @@ -95,6 +95,13 @@ pub(crate) enum AlbumsCommands { /// List all albums #[serde(rename = "list")] List {}, + /// List all assets that belong to a specific album + #[serde(rename = "list-assets")] + ListAssets { + /// Name of the album to list assets for + #[arg(long)] + album: String, + }, } #[derive(Serialize, Subcommand)] diff --git a/src/commands/list_album_assets.rs b/src/commands/list_album_assets.rs new file mode 100644 index 0000000..5071b25 --- /dev/null +++ b/src/commands/list_album_assets.rs @@ -0,0 +1,38 @@ +use crate::{ + actions::{ + action::Action, fetch_album_assets::FetchAlbumAssets, fetch_all_albums::FetchAllAlbums, + }, + context::Context, +}; +use color_eyre::eyre::{eyre, Result}; +use tabled::{settings::Style, Table, Tabled}; + +#[derive(Tabled)] +struct AssetRow { + #[tabled(rename = "Path")] + original_file_path: String, +} + +pub async fn list_album_assets(ctx: Context, album_name: &str) -> Result<()> { + let albums = FetchAllAlbums::new(()).execute(&ctx).await?; + + let album = albums + .into_iter() + .find(|a| a.name == album_name) + .ok_or_else(|| eyre!("Album not found: {}", album_name))?; + + let mut assets: Vec<_> = FetchAlbumAssets::new(album) + .execute(&ctx) + .await? + .into_iter() + .map(|asset| AssetRow { + original_file_path: asset.original_path.to_string_lossy().to_string(), + }) + .collect(); + + assets.sort_by_key(|row| row.original_file_path.clone()); + + println!("{}", Table::new(assets).with(Style::rounded())); + + Ok(()) +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 3924e81..ae72806 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,6 +1,7 @@ pub mod auto_create_albums; pub mod delete_albums; pub mod delete_assets; +pub mod list_album_assets; pub mod list_albums; pub mod list_assets; pub mod list_libraries; diff --git a/src/main.rs b/src/main.rs index 7226bc5..05596a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#![allow(renamed_and_removed_lints)] // https://github.com/oxidecomputer/progenitor/issues/1169 include!(concat!(env!("OUT_DIR"), "/client.rs")); #[cfg(test)] @@ -16,6 +17,7 @@ use color_eyre::Section; use commands::auto_create_albums::auto_create_albums; use commands::delete_albums::delete_albums; use commands::delete_assets::delete_assets; +use commands::list_album_assets::list_album_assets; use commands::list_albums::list_albums; use commands::list_assets::list_assets; use commands::list_libraries::list_libraries; @@ -86,6 +88,7 @@ async fn main() -> Result<()> { } => auto_create_albums(ctx, album_name_separator.to_string()).await, AlbumsCommands::Delete { empty } => delete_albums(ctx, *empty).await, AlbumsCommands::List {} => list_albums(ctx).await, + AlbumsCommands::ListAssets { album } => list_album_assets(ctx, album).await, }, Commands::Assets { assets_command } => match assets_command { AssetsCommands::Delete { offline } => delete_assets(ctx, *offline).await,