Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Photos backend: Portrait, by Apple's own rule

Yashwanth Kamireddib629f03edc19
diff --git a/crates/quince-core/src/photos.rs b/crates/quince-core/src/photos.rs
index 97721f3..618ab86 100644
--- a/crates/quince-core/src/photos.rs
+++ b/crates/quince-core/src/photos.rs
@@ -84,6 +84,9 @@ pub struct Photo {
pub latitude: Option<f64>,
#[serde(default)]
pub longitude: Option<f64>,
+ /// How it was rendered (Apple's customRenderedValue): 8 is a Portrait, with depth.
+ #[serde(default)]
+ pub rendered: i64,
/// Photos' subtype: 1 and 3 mark screenshots and the like (`assetSubtypeV2`).
pub subtype: i64,
/// The asset's change tag, for writing back to it.
@@ -134,6 +137,8 @@ pub enum View {
Screenshots,
/// Wide photos made by sweeping: assetSubtypeV2 1.
Panoramas,
+ /// Portraits, with depth: customRenderedValue 8.
+ Portrait,
/// Newest added first.
Recents,
/// Hidden from every other view, as Photos' Hidden album.
@@ -145,7 +150,7 @@ pub enum View {
const COLUMNS: &str = "id, master, taken_at, added_at, kind, width, height, duration, filename, \
size, uti, favorite, hidden, deleted, deleted_at, subtype, change_tag, expunge_at, title, caption, rating, \
- keywords, latitude, longitude";
+ keywords, latitude, longitude, rendered";
fn row_to_photo(r: &rusqlite::Row<'_>) -> rusqlite::Result<Photo> {
Ok(Photo {
@@ -176,6 +181,7 @@ fn row_to_photo(r: &rusqlite::Row<'_>) -> rusqlite::Result<Photo> {
.unwrap_or_default(),
latitude: r.get(22)?,
longitude: r.get(23)?,
+ rendered: r.get(24)?,
})
}
@@ -188,9 +194,9 @@ impl Library {
"INSERT INTO photos (id, master, taken_at, added_at, kind, width, height, duration,
filename, size, uti, favorite, hidden, deleted, deleted_at,
subtype, change_tag, expunge_at, title, caption, rating,
- keywords, latitude, longitude)
+ keywords, latitude, longitude, rendered)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20, ?21,
- ?22, ?23, ?24)
+ ?22, ?23, ?24, ?25)
ON CONFLICT(id) DO UPDATE SET
master = excluded.master, taken_at = excluded.taken_at,
added_at = excluded.added_at, kind = excluded.kind, width = excluded.width,
@@ -202,7 +208,7 @@ impl Library {
expunge_at = excluded.expunge_at, title = excluded.title,
caption = excluded.caption, rating = excluded.rating,
keywords = excluded.keywords, latitude = excluded.latitude,
- longitude = excluded.longitude",
+ longitude = excluded.longitude, rendered = excluded.rendered",
)?;
for p in photos {
stmt.execute(params![
@@ -230,7 +236,8 @@ impl Library {
(!p.keywords.is_empty())
.then(|| serde_json::to_string(&p.keywords).unwrap_or_default()),
p.latitude,
- p.longitude
+ p.longitude,
+ p.rendered
])?;
}
}
@@ -336,6 +343,11 @@ impl Library {
"deleted = 0 AND hidden = 0 AND subtype = 1",
"taken_at DESC",
),
+ // Apple's DEPTH smart album, read on his library: customRenderedValue 8.
+ View::Portrait => (
+ "deleted = 0 AND hidden = 0 AND rendered = 8",
+ "taken_at DESC",
+ ),
View::Recents => (
"deleted = 0 AND hidden = 0",
"COALESCE(added_at, taken_at) DESC",
@@ -367,6 +379,7 @@ impl Library {
View::Videos,
View::Screenshots,
View::Panoramas,
+ View::Portrait,
View::Hidden,
View::Rated,
View::RecentlyDeleted,
@@ -681,6 +694,7 @@ mod tests {
keywords: Vec::new(),
latitude: None,
longitude: None,
+ rendered: 0,
}
}
@@ -803,5 +817,16 @@ mod tests {
};
assert_eq!(ids(View::Screenshots), ["shot"]);
assert_eq!(ids(View::Panoramas), ["wide"]);
+ let mut portrait = photo("depth", 400);
+ portrait.rendered = 8;
+ lib.put_photos(&[portrait]).unwrap();
+ assert_eq!(
+ lib.photos(View::Portrait)
+ .unwrap()
+ .into_iter()
+ .map(|p| p.id)
+ .collect::<Vec<_>>(),
+ ["depth"]
+ );
}
}
diff --git a/crates/quince-core/src/schema.rs b/crates/quince-core/src/schema.rs
index 60750e7..49333a9 100644
--- a/crates/quince-core/src/schema.rs
+++ b/crates/quince-core/src/schema.rs
@@ -481,4 +481,9 @@ pub const MIGRATIONS: &[&str] = &[
ALTER TABLE photo_albums ADD COLUMN parent TEXT;
UPDATE sync_state SET token = NULL WHERE service = 'photos';
"#,
+ // How each photo was rendered (a Portrait is 8); Photos read again so every photo has it.
+ r#"
+ ALTER TABLE photos ADD COLUMN rendered INTEGER NOT NULL DEFAULT 0;
+ UPDATE sync_state SET token = NULL WHERE service = 'photos';
+ "#,
];
diff --git a/crates/quince-icloud/src/photos.rs b/crates/quince-icloud/src/photos.rs
index 3a7102c..22109c7 100644
--- a/crates/quince-icloud/src/photos.rs
+++ b/crates/quince-icloud/src/photos.rs
@@ -201,6 +201,7 @@ pub fn photo_of(asset: &Value, master: &Value) -> Option<Photo> {
caption: decoded(asset, "extendedDescEnc"),
rating: field::int(asset, "rating").unwrap_or(0).clamp(0, 5),
keywords: keywords_of(asset),
+ rendered: field::int(asset, "customRenderedValue").unwrap_or(0),
latitude: location_of(asset).map(|l| l.0),
longitude: location_of(asset).map(|l| l.1),
expunge_at: (field::int(asset, "isDeleted") == Some(1))
@@ -232,6 +233,7 @@ fn with_asset(mut p: Photo, asset: &Value) -> Photo {
p.caption = decoded(asset, "extendedDescEnc");
p.rating = field::int(asset, "rating").unwrap_or(0).clamp(0, 5);
p.keywords = keywords_of(asset);
+ p.rendered = field::int(asset, "customRenderedValue").unwrap_or(p.rendered);
if let Some((lat, lon)) = location_of(asset) {
(p.latitude, p.longitude) = (Some(lat), Some(lon));
}
diff --git a/probe/examples/photos_audit.rs b/probe/examples/photos_audit.rs
index 2e53185..1828a06 100644
--- a/probe/examples/photos_audit.rs
+++ b/probe/examples/photos_audit.rs
@@ -94,6 +94,7 @@ async fn main() -> Result<()> {
walk("VIDEO").await?,
walk("SCREENSHOT").await?,
walk("PANORAMA").await?,
+ walk("DEPTH").await?,
];
let views = [
(View::Library, ids[0]),
@@ -101,6 +102,7 @@ async fn main() -> Result<()> {
(View::Videos, ids[2]),
(View::Screenshots, ids[3]),
(View::Panoramas, ids[4]),
+ (View::Portrait, ids[4]),
(View::Hidden, ids[5]),
(View::RecentlyDeleted, ids[6]),
];
@@ -112,6 +114,7 @@ async fn main() -> Result<()> {
View::Videos => Some(walked[1]),
View::Screenshots => Some(walked[2]),
View::Panoramas => Some(walked[3]),
+ View::Portrait => Some(walked[4]),
_ => apple(id),
};
let same = theirs == Some(ours);
diff --git a/probe/examples/photos_smart_albums.rs b/probe/examples/photos_smart_albums.rs
index 8041d3c..1471584 100644
--- a/probe/examples/photos_smart_albums.rs
+++ b/probe/examples/photos_smart_albums.rs
@@ -72,6 +72,19 @@ async fn main() -> Result<()> {
"{album}: {} assets; assetSubtypeV2 → {subtypes:?}",
all.len()
);
+ // With FIELDS set, each asset's own fields (not its renditions), to find what marks it.
+ if std::env::var("FIELDS").is_ok_and(|f| f.split(',').any(|x| x == album)) {
+ for asset in &all {
+ let keys: Vec<String> = asset["fields"]
+ .as_object()
+ .into_iter()
+ .flatten()
+ .filter(|(k, _)| !k.starts_with("res") && !k.ends_with("Enc"))
+ .map(|(k, v)| format!("{k}={}", v["value"]))
+ .collect();
+ println!(" {}", keys.join(" "));
+ }
+ }
}
Ok(())
}