Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.
Rust apple-notesapple-reminderscloudkitcrdtdesktop-appicloudicloud-calendaricloud-driveicloud-notesicloud-photosiphonelinuxlinux-desktoplocal-firstoffline-firstprivacyrusttauritauri-appwindows
Photos folder: Live Photos come with their .MOV
Yashwanth Kamireddie06513be3786
diff --git a/crates/quince-core/src/photos.rs b/crates/quince-core/src/photos.rsindex 2de99fe..b8cc802 100644--- a/crates/quince-core/src/photos.rs+++ b/crates/quince-core/src/photos.rs@@ -98,6 +98,9 @@ pub struct Photo {/// How many photos its burst holds (filled when read; not stored).#[serde(default)]pub burst_count: i64,+ /// A Live Photo's moving part, its original `.MOV`, in bytes.+ #[serde(default)]+ pub live_size: Option<i64>,/// The asset's change tag, for writing back to it.pub change_tag: Option<String>,}@@ -159,7 +162,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, rendered, burst, burst_pick";+ keywords, latitude, longitude, rendered, burst, burst_pick, live_size";/// A burst shows as its chosen photo, as Photos shows it (Apple's library says as much: its/// `burstsExcludedFromPhotosCount` is every burst's photos less one each). A burst whose chosen@@ -201,6 +204,7 @@ fn row_to_photo(r: &rusqlite::Row<'_>) -> rusqlite::Result<Photo> {burst: r.get(25)?,burst_pick: r.get::<_, i64>(26)? != 0,burst_count: 0,+ live_size: r.get(27)?,})}@@ -213,9 +217,10 @@ 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, rendered, burst, burst_pick)+ keywords, latitude, longitude, rendered, burst, burst_pick,+ live_size)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, ?25, ?26, ?27)+ ?22, ?23, ?24, ?25, ?26, ?27, ?28)ON CONFLICT(id) DO UPDATE SETmaster = excluded.master, taken_at = excluded.taken_at,added_at = excluded.added_at, kind = excluded.kind, width = excluded.width,@@ -228,7 +233,8 @@ impl Library {caption = excluded.caption, rating = excluded.rating,keywords = excluded.keywords, latitude = excluded.latitude,longitude = excluded.longitude, rendered = excluded.rendered,- burst = excluded.burst, burst_pick = excluded.burst_pick",+ burst = excluded.burst, burst_pick = excluded.burst_pick,+ live_size = excluded.live_size",)?;for p in photos {stmt.execute(params![@@ -259,7 +265,8 @@ impl Library {p.longitude,p.rendered,p.burst,- i64::from(p.burst_pick)+ i64::from(p.burst_pick),+ p.live_size])?;}}@@ -762,6 +769,7 @@ mod tests {burst: None,burst_pick: false,burst_count: 0,+ live_size: None,}}diff --git a/crates/quince-core/src/schema.rs b/crates/quince-core/src/schema.rsindex b818a6b..de0d831 100644--- a/crates/quince-core/src/schema.rs+++ b/crates/quince-core/src/schema.rs@@ -515,4 +515,10 @@ pub const MIGRATIONS: &[&str] = &[CREATE INDEX photos_by_burst ON photos (burst) WHERE burst IS NOT NULL;UPDATE sync_state SET token = NULL WHERE service = 'photos';"#,+ // A Live Photo's moving part, its size: what the Photos folder lists it at. Photos read+ // again so every Live Photo has it.+ r#"+ ALTER TABLE photos ADD COLUMN live_size INTEGER;+ UPDATE sync_state SET token = NULL WHERE service = 'photos';+ "#,];diff --git a/crates/quince-icloud/src/photos.rs b/crates/quince-icloud/src/photos.rsindex 451e83e..8606ca7 100644--- a/crates/quince-icloud/src/photos.rs+++ b/crates/quince-icloud/src/photos.rs@@ -55,6 +55,8 @@ pub struct Links {pub full: Option<String>,/// A video's playable rendition, or a Live Photo's moving part.pub video: Option<String>,+ /// A Live Photo's moving part as it was shot: the original `.MOV`.+ pub live: Option<String>,}fn link(fields: &Value, key: &str, name: &str) -> Option<String> {@@ -83,6 +85,7 @@ pub fn links_of(master: &Value) -> Links {video: link(f, "resVidMedRes", "video.mp4").or_else(|| link(f, "resVidSmallRes", "video.mp4")).or_else(|| link(f, "resOriginalVidComplRes", "live.mov")),+ live: link(f, "resOriginalVidComplRes", "live.mov"),}}@@ -226,6 +229,9 @@ pub fn photo_of(asset: &Value, master: &Value) -> Option<Photo> {burst: burst_of(asset),burst_pick: burst_pick_of(asset),burst_count: 0,+ live_size: (kind == Kind::Live)+ .then(|| size("resOriginalVidComplFileSize"))+ .flatten(),latitude: location_of(asset).map(|l| l.0),longitude: location_of(asset).map(|l| l.1),expunge_at: (field::int(asset, "isDeleted") == Some(1))@@ -1006,6 +1012,24 @@ mod tests {);}+ /// A Live Photo knows its moving part: the original .MOV's link and size, for the Photos+ /// folder to list it beside the still. A still photo has neither.+ #[test]+ fn a_live_photo_knows_its_moving_part() {+ let mut m = master();+ m["fields"]["resOriginalVidComplRes"] =+ json!({"value": {"downloadURL": "https://cvws.example/live/${f}"}});+ m["fields"]["resOriginalVidComplFileSize"] = json!({"value": 3_500_000});+ let p = photo_of(&asset(json!({})), &m).unwrap();+ assert_eq!((p.kind, p.live_size), (Kind::Live, Some(3_500_000)));+ assert_eq!(+ links_of(&m).live.as_deref(),+ Some("https://cvws.example/live/live.mov")+ );+ let still = photo_of(&asset(json!({})), &master()).unwrap();+ assert_eq!((still.live_size, links_of(&master()).live), (None, None));+ }+/// A full pass replaces the library; a later asset-only change (deleted) is laid over the/// photo already known; an expunged asset goes.#[test]diff --git a/probe/examples/photos_live_size.rs b/probe/examples/photos_live_size.rsnew file mode 100644index 0000000..bf2971d--- /dev/null+++ b/probe/examples/photos_live_size.rs@@ -0,0 +1,46 @@+//! Live, read-only: a Live Photo's moving part downloads at exactly the size its master+//! advertises (`resOriginalVidComplFileSize`) — what the Photos folder lists the .MOV at — and+//! is a QuickTime file. Takes asset ids; prints only sizes and the file's first box.+use anyhow::{anyhow, Result};+use quince_icloud::photos::{links_of, CONTAINER, ZONE};++#[tokio::main]+async fn main() -> Result<()> {+ let dir = std::path::PathBuf::from(std::env::var("HOME")?).join(".local/share/quince-probe");+ let mut client = quince_auth::Client::new(&dir)?;+ if !client.resume().await? {+ return Err(anyhow!("no session"));+ }+ let ck = client+ .session()+ .service_url("ckdatabasews")+ .ok_or_else(|| anyhow!("no ck"))?;+ let (http, p) = (client.http().clone(), client.service_params());+ let zc = quince_icloud::cloudkit::ZoneClient::new(&http, &ck, CONTAINER, p);+ for (n, asset) in std::env::args().skip(1).enumerate() {+ let a = zc+ .lookup_record(ZONE, &asset)+ .await?+ .ok_or_else(|| anyhow!("no asset"))?;+ let master = a+ .pointer("/fields/masterRef/value/recordName")+ .and_then(|v| v.as_str())+ .ok_or_else(|| anyhow!("no master"))?;+ let m = zc+ .lookup_record(ZONE, master)+ .await?+ .ok_or_else(|| anyhow!("no master record"))?;+ let said = m+ .pointer("/fields/resOriginalVidComplFileSize/value")+ .and_then(serde_json::Value::as_i64);+ let live = links_of(&m).live.ok_or_else(|| anyhow!("no live link"))?;+ let bytes = http.get(&live).send().await?.bytes().await?;+ println!(+ "live photo {n}: advertised {said:?}, downloaded {}, box {:?}, equal: {}",+ bytes.len(),+ String::from_utf8_lossy(&bytes[4..12.min(bytes.len())]),+ said == i64::try_from(bytes.len()).ok()+ );+ }+ Ok(())+}diff --git a/src-tauri/src/mount_photos.rs b/src-tauri/src/mount_photos.rsindex e0effa4..b223678 100644--- a/src-tauri/src/mount_photos.rs+++ b/src-tauri/src/mount_photos.rs@@ -5,7 +5,9 @@//! Albums/Trips/Goa/IMG_0042.JPG//! Favorites/… Videos/…//!-//! Each file is the original, under its own name and dated when it was taken. Its bytes are+//! Each file is the original, under its own name and dated when it was taken; a Live Photo is+//! its still and, beside it under the same name, its moving part as shot (IMG_1234.MOV) — as+//! Image Capture brings them off an iPhone. Its bytes are//! read from the app's own photo cache (fetched once if they are not there), never copied a//! second time; thumbnails are the app's own, so a file manager browsing downloads nothing.//! Hidden and Recently Deleted are never shown.@@ -24,6 +26,8 @@ const ALBUMS: &str = "PH::albums";const FAVORITES: &str = "PH::favorites";const VIDEOS: &str = "PH::videos";const FILE: &str = "PHOTO::";+/// A Live Photo's moving part, beside its still.+const LIVE: &str = "LIVE::";const MONTHS: [&str; 12] = ["January",@@ -83,6 +87,29 @@ fn file(p: &Photo, parent: &str) -> DriveItem {}}+/// A photo's files in a folder: the photo, and for a Live Photo its `.MOV` too.+fn files(p: &Photo, parent: &str) -> Vec<DriveItem> {+ let still = file(p, parent);+ let live = (p.kind == quince_core::photos::Kind::Live)+ .then_some(p.live_size)+ .flatten()+ .map(|size| DriveItem {+ drivewsid: format!("{LIVE}{}", p.id),+ extension: Some("MOV".into()),+ size: Some(size),+ ..still.clone()+ });+ std::iter::once(still).chain(live).collect()+}++/// The photo a file in the folder is of, and whether it is a Live Photo's moving part.+fn photo_of(item: &DriveItem) -> Option<(&str, bool)> {+ item.drivewsid+ .strip_prefix(FILE)+ .map(|id| (id, false))+ .or_else(|| item.drivewsid.strip_prefix(LIVE).map(|id| (id, true)))+}+/// (year, month 1–12) a photo was taken in, in this computer's time zone.fn taken(p: &Photo) -> (i16, i8) {let zone = jiff::tz::TimeZone::system();@@ -115,11 +142,11 @@ fn children(app: &AppHandle, id: &str) -> Option<Vec<DriveItem>> {}FAVORITES => photos(View::Favorites).iter()- .map(|p| file(p, FAVORITES))+ .flat_map(|p| files(p, FAVORITES)).collect(),VIDEOS => photos(View::Videos).iter()- .map(|p| file(p, VIDEOS))+ .flat_map(|p| files(p, VIDEOS)).collect(),ALBUMS => albums_in(&library, None, ALBUMS),_ => {@@ -146,7 +173,7 @@ fn children(app: &AppHandle, id: &str) -> Option<Vec<DriveItem>> {photos(View::Library).iter().filter(|p| taken(p) == (y, m))- .map(|p| file(p, id))+ .flat_map(|p| files(p, id)).collect()} else {let album = id.strip_prefix("PH::album:")?;@@ -163,7 +190,7 @@ fn children(app: &AppHandle, id: &str) -> Option<Vec<DriveItem>> {.ok()?.iter().filter(|p| !p.hidden && !p.deleted)- .map(|p| file(p, id))+ .flat_map(|p| files(p, id)).collect()}}@@ -215,17 +242,19 @@ impl Remote for PhotosRemote {}fn file(&self, item: &DriveItem) -> Option<Fut<PathBuf>> {- let id = item.drivewsid.strip_prefix(FILE)?.to_string();+ let (id, live) = photo_of(item)?;+ let (id, size) = (+ id.to_string(),+ if live { Size::Live } else { Size::Original },+ );let app = self.0.clone();- Some(Box::pin(- async move { cached(&app, &id, Size::Original).await },- ))+ Some(Box::pin(async move { cached(&app, &id, size).await }))}fn is_local(&self, item: &DriveItem) -> bool {- item.drivewsid- .strip_prefix(FILE)- .is_some_and(|id| cache_path(&self.0, id, Size::Original).exists())+ photo_of(item).is_some_and(|(id, live)| {+ cache_path(&self.0, id, if live { Size::Live } else { Size::Original }).exists()+ })}fn thumbnails(&self, folder: &str) -> Fut<HashMap<String, Vec<u8>>> {@@ -238,7 +267,8 @@ impl Remote for PhotosRemote {.map_err(|e| e.to_string())?;let mut out = HashMap::new();for item in files.iter().filter(|i| i.kind == "FILE") {- let Some(id) = item.drivewsid.strip_prefix(FILE) else {+ // A Live Photo's .MOV is pictured by its still, as Photos shows it.+ let Some((id, _)) = photo_of(item) else {continue;};if let Ok(path) = cached(&app, id, Size::Thumb).await {@@ -251,3 +281,47 @@ impl Remote for PhotosRemote {})}}++#[cfg(test)]+mod tests {+ use super::*;++ /// A Live Photo is two files under one name — the still and its .MOV, at the moving part's+ /// own size — and each knows which picture it is.+ #[test]+ fn a_live_photo_is_its_still_and_its_mov() {+ let mut p: Photo = serde_json::from_value(serde_json::json!({+ "id": "A1", "master": "M1", "takenAt": 1_789_640_832, "kind": "live",+ "width": 4032, "height": 3024, "filename": "IMG_0001.HEIC", "size": 2_400_000,+ "favorite": false, "hidden": false, "deleted": false, "subtype": 0,+ "liveSize": 3_500_000+ }))+ .unwrap();+ let both = files(&p, "PH::m:2026-9");+ let named: Vec<_> = both+ .iter()+ .map(|f| (f.display_name(), f.size, photo_of(f)))+ .collect();+ assert_eq!(+ named,+ vec![+ (+ "IMG_0001.HEIC".to_string(),+ Some(2_400_000),+ Some(("A1", false))+ ),+ (+ "IMG_0001.MOV".to_string(),+ Some(3_500_000),+ Some(("A1", true))+ ),+ ]+ );+ p.kind = quince_core::photos::Kind::Image;+ assert_eq!(+ files(&p, "PH::m:2026-9").len(),+ 1,+ "a still photo is one file"+ );+ }+}diff --git a/src-tauri/src/photos.rs b/src-tauri/src/photos.rsindex f53e9be..4c0ee4f 100644--- a/src-tauri/src/photos.rs+++ b/src-tauri/src/photos.rs@@ -58,6 +58,8 @@ pub enum Size {/// The whole picture, displayable: for a photo zoomed in.Full,Video,+ /// A Live Photo's moving part as shot, the original `.MOV`.+ Live,}impl Size {@@ -68,6 +70,7 @@ impl Size {Size::Original => "original",Size::Full => "full",Size::Video => "video",+ Size::Live => "live",}}fn pick(self, l: &Links) -> Option<String> {@@ -77,6 +80,7 @@ impl Size {Size::Original => l.original.clone(),Size::Full => l.full.clone().or_else(|| l.medium.clone()),Size::Video => l.video.clone(),+ Size::Live => l.live.clone(),}}}