Write out images in per-album json.
This commit is contained in:
parent
cced612139
commit
df3d29ce7c
@ -36,3 +36,7 @@
|
|||||||
transform: rotate(360deg);
|
transform: rotate(360deg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.figure {
|
||||||
|
width: 285px;
|
||||||
|
}
|
||||||
|
|||||||
22
react-debug/src/App.js
vendored
22
react-debug/src/App.js
vendored
@ -1,5 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
import './App.css';
|
||||||
|
|
||||||
class Album extends React.Component {
|
class Album extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -25,18 +27,16 @@ class Album extends React.Component {
|
|||||||
} else if (album !== null) {
|
} else if (album !== null) {
|
||||||
console.log(album);
|
console.log(album);
|
||||||
return album.map((a) => {
|
return album.map((a) => {
|
||||||
let img = <img src="https://via.placeholder.com/256x128" className="mr-3" alt="unset"/>;
|
// TODO(wathiede): use coverPhotoMediaItemId and fetch from a
|
||||||
if (a.coverPhotoBaseUrl !== undefined) {
|
// locally cached image.
|
||||||
img = <img src={ a.coverPhotoBaseUrl + "=w256" } className="mr-3" alt={ a.title }/>;
|
return <figure key={ a.id } className="figure">
|
||||||
}
|
<img src={ a.baseUrl + "=w256-h256-c" } className="mr-3" alt={ a.filename }/>
|
||||||
|
<figcaption className="figure-caption">
|
||||||
let figure = <figure key={ a.id } className="figure">
|
<a key={ a.id } href={ a.productUrl }>
|
||||||
{img}
|
<p className="text-truncate">{ a.filename}</p>
|
||||||
<figcaption className="figure-caption">{ a.title || "No title" } - { a.mediaItemsCount || 0 } photos </figcaption>
|
|
||||||
</figure>;
|
|
||||||
return <a key={ a.id } href={ a.productUrl }>
|
|
||||||
{ figure }
|
|
||||||
</a>
|
</a>
|
||||||
|
</figcaption>
|
||||||
|
</figure>
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return <h2>Loading...</h2>;
|
return <h2>Loading...</h2>;
|
||||||
|
|||||||
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>> {
|
fn print_media_items(media_items: Vec<MediaItem>) {
|
||||||
let mut total = 0;
|
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(
|
let media_items = SearchIter::new(
|
||||||
&client,
|
&client,
|
||||||
SearchMediaItemsRequest {
|
SearchMediaItemsRequest {
|
||||||
@ -133,18 +146,10 @@ fn search_media_items(client: &photos::Client, album_id: String) -> Result<(), B
|
|||||||
page_size: Some(100),
|
page_size: Some(100),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
);
|
)
|
||||||
for mi in media_items {
|
.filter_map(|mi| mi.ok())
|
||||||
let mi = mi?;
|
.collect();
|
||||||
total += 1;
|
Ok(media_items)
|
||||||
println!(
|
|
||||||
"{} {}",
|
|
||||||
mi.id.unwrap_or("NO ID".to_string()),
|
|
||||||
mi.filename.unwrap_or("NO FILENAME".to_string())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
println!("({}) items total", total);
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sync_albums(
|
fn sync_albums(
|
||||||
@ -159,11 +164,12 @@ fn sync_albums(
|
|||||||
info!("making album directory {}", album_dir.to_string_lossy());
|
info!("making album directory {}", album_dir.to_string_lossy());
|
||||||
fs::create_dir_all(&album_dir)?;
|
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");
|
let path = album_dir.join("album.json");
|
||||||
info!("saving {}", path.to_string_lossy());
|
info!("saving {}", path.to_string_lossy());
|
||||||
fs::write(path, j)?;
|
fs::write(path, j)?;
|
||||||
search_media_items(client, a.id.as_ref().expect("unset album id").to_string());
|
|
||||||
}
|
}
|
||||||
// Serialize it to a JSON string.
|
// Serialize it to a JSON string.
|
||||||
let j = serde_json::to_string(&albums)?;
|
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)?);
|
print_albums(list_albums(&client, title_filter)?);
|
||||||
Ok(())
|
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 {
|
Command::Sync {
|
||||||
title_filter,
|
title_filter,
|
||||||
output,
|
output,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user