Write out images in per-album json.
This commit is contained in:
43
src/main.rs
43
src/main.rs
@@ -123,8 +123,21 @@ impl<'a> Iterator for SearchIter<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn search_media_items(client: &photos::Client, album_id: String) -> Result<(), Box<dyn Error>> {
|
||||
let mut total = 0;
|
||||
fn print_media_items(media_items: Vec<MediaItem>) {
|
||||
for mi in &media_items {
|
||||
println!(
|
||||
"{} {}",
|
||||
mi.id.as_ref().unwrap_or(&"NO ID".to_string()),
|
||||
mi.filename.as_ref().unwrap_or(&"NO FILENAME".to_string())
|
||||
);
|
||||
}
|
||||
println!("({}) items total", media_items.len());
|
||||
}
|
||||
|
||||
fn search_media_items(
|
||||
client: &photos::Client,
|
||||
album_id: String,
|
||||
) -> Result<Vec<MediaItem>, Box<dyn Error>> {
|
||||
let media_items = SearchIter::new(
|
||||
&client,
|
||||
SearchMediaItemsRequest {
|
||||
@@ -133,18 +146,10 @@ fn search_media_items(client: &photos::Client, album_id: String) -> Result<(), B
|
||||
page_size: Some(100),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
for mi in media_items {
|
||||
let mi = mi?;
|
||||
total += 1;
|
||||
println!(
|
||||
"{} {}",
|
||||
mi.id.unwrap_or("NO ID".to_string()),
|
||||
mi.filename.unwrap_or("NO FILENAME".to_string())
|
||||
);
|
||||
}
|
||||
println!("({}) items total", total);
|
||||
Ok(())
|
||||
)
|
||||
.filter_map(|mi| mi.ok())
|
||||
.collect();
|
||||
Ok(media_items)
|
||||
}
|
||||
|
||||
fn sync_albums(
|
||||
@@ -159,11 +164,12 @@ fn sync_albums(
|
||||
info!("making album directory {}", album_dir.to_string_lossy());
|
||||
fs::create_dir_all(&album_dir)?;
|
||||
}
|
||||
let j = serde_json::to_string(&albums)?;
|
||||
|
||||
let album = search_media_items(client, a.id.as_ref().expect("unset album id").to_string())?;
|
||||
let j = serde_json::to_string(&album)?;
|
||||
let path = album_dir.join("album.json");
|
||||
info!("saving {}", path.to_string_lossy());
|
||||
fs::write(path, j)?;
|
||||
search_media_items(client, a.id.as_ref().expect("unset album id").to_string());
|
||||
}
|
||||
// Serialize it to a JSON string.
|
||||
let j = serde_json::to_string(&albums)?;
|
||||
@@ -223,7 +229,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
print_albums(list_albums(&client, title_filter)?);
|
||||
Ok(())
|
||||
}
|
||||
Command::SearchMediaItems { album_id } => search_media_items(&client, album_id),
|
||||
Command::SearchMediaItems { album_id } => {
|
||||
print_media_items(search_media_items(&client, album_id)?);
|
||||
Ok(())
|
||||
}
|
||||
Command::Sync {
|
||||
title_filter,
|
||||
output,
|
||||
|
||||
Reference in New Issue
Block a user