π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Detect motion photos and panoramas during local processing
Neeraj Guptaf1ca51bb5893
diff --git a/mobile/apps/photos/lib/db/files_db.dart b/mobile/apps/photos/lib/db/files_db.dartindex b0c615e2dd..f002b56fd4 100644--- a/mobile/apps/photos/lib/db/files_db.dart+++ b/mobile/apps/photos/lib/db/files_db.dart@@ -1199,6 +1199,8 @@ class FilesDB with SqlDbBase {jsonEncode({widthKey: file.hasDimensions ? file.width : null,heightKey: file.hasDimensions ? file.height : null,+ mediaTypeKey: null,+ motionVideoIndexKey: null,}),file.localID,file.modificationTime,@@ -1216,6 +1218,8 @@ class FilesDB with SqlDbBase {Location? location,int? fileSize,({int width, int height})? dimensions,+ int? mediaType,+ int? motionVideoIndex,}) async {final db = await instance.sqliteAsyncDB;final result = await db.execute(@@ -1236,11 +1240,14 @@ class FilesDB with SqlDbBase {location?.latitude,location?.longitude,fileSize,- jsonEncode(- dimensions == null- ? {}- : {widthKey: dimensions.width, heightKey: dimensions.height},- ),+ jsonEncode({+ if (dimensions != null) ...{+ widthKey: dimensions.width,+ heightKey: dimensions.height,+ },+ mediaTypeKey: ?mediaType,+ motionVideoIndexKey: ?motionVideoIndex,+ }),processingVersion,localID,modificationTime,diff --git a/mobile/apps/photos/lib/module/metadata/local_file.dart b/mobile/apps/photos/lib/module/metadata/local_file.dartindex 599bd6dc13..88657b961b 100644--- a/mobile/apps/photos/lib/module/metadata/local_file.dart+++ b/mobile/apps/photos/lib/module/metadata/local_file.dart@@ -35,6 +35,19 @@ void applyDisplayDimensions(EnteFile file, int width, int height) {});}+void applyMediaTypeMetadata(+ EnteFile file,+ bool isPanorama,+ int motionVideoIndex,+) {+ file.pubMmdEncodedJson = jsonEncode({+ ...jsonDecode(file.pubMmdEncodedJson ?? '{}') as Map<String, dynamic>,+ mediaTypeKey:+ ((file.pubMagicMetadata?.mediaType ?? 0) & ~1) | (isPanorama ? 1 : 0),+ motionVideoIndexKey: motionVideoIndex,+ });+}+void applyCreationTimeMetadata(EnteFile file, ParsedExifDateTime? exifTime) {final hasExifTime = exifTime != null;if (exifTime != null) {diff --git a/mobile/apps/photos/lib/services/sync/offline_import_metadata_service.dart b/mobile/apps/photos/lib/services/sync/offline_import_metadata_service.dartindex 1df052b111..9d3b6a17fc 100644--- a/mobile/apps/photos/lib/services/sync/offline_import_metadata_service.dart+++ b/mobile/apps/photos/lib/services/sync/offline_import_metadata_service.dart@@ -18,7 +18,7 @@ import "package:photos/service_locator.dart";import "package:photos/services/process_activity.dart";class OfflineImportMetadataService {- static const kProcessingVersion = 2;+ static const kProcessingVersion = 3;static const kDefaultBatchSize = 25;final _logger = Logger("OfflineImportMetadataService");@@ -121,6 +121,13 @@ class OfflineImportMetadataService {);applyCreationTimeMetadata(file, metadata?.creationDateTime);+ if (metadata != null) {+ applyMediaTypeMetadata(+ file,+ metadata.isPanorama,+ metadata.motionVideoStart?.toInt() ?? 0,+ );+ }final updated = await _db.updateOfflineImportMetadataForLocalID(file.localID!,@@ -129,6 +136,8 @@ class OfflineImportMetadataService {creationTime: file.creationTime,location: file.location,fileSize: fileSize,+ mediaType: metadata == null ? null : file.pubMagicMetadata!.mediaType,+ motionVideoIndex: metadata == null ? null : file.pubMagicMetadata!.mvi,dimensions: file.hasDimensions? (width: file.width, height: file.height): null,diff --git a/mobile/apps/photos/test/db/offline_metadata_test.dart b/mobile/apps/photos/test/db/offline_metadata_test.dartindex a60df84bdc..738a87c5c7 100644--- a/mobile/apps/photos/test/db/offline_metadata_test.dart+++ b/mobile/apps/photos/test/db/offline_metadata_test.dart@@ -26,7 +26,7 @@ void main() {});test(- "persists dimensions, refreshes edits and rejects stale results only for local rows",+ "persists media metadata, refreshes edits and rejects stale results only for local rows",() async {final db = await files.sqliteAsyncDB;for (final (uploadedID, collectionID) in [(-1, 1), (-1, 2), (99, 3)]) {@@ -49,6 +49,8 @@ void main() {processingVersion: 2,modificationTime: 100,dimensions: (width: 3000, height: 4000),+ mediaType: 1,+ motionVideoIndex: 1234,),isTrue,);@@ -61,6 +63,8 @@ void main() {..pubMmdEncodedJson = row[FilesDB.columnPubMMdEncodedJson] as String;expect((file.width, file.height), (3000, 4000));expect(file.pubMagicMetadata!.caption, "Keep me");+ expect(file.pubMagicMetadata!.mediaType, 1);+ expect(file.pubMagicMetadata!.mvi, 1234);expect(row[FilesDB.columnMetadataVersion], 2);}expect(@@ -80,6 +84,8 @@ void main() {processingVersion: 2,modificationTime: 100,dimensions: (width: 3000, height: 4000),+ mediaType: 1,+ motionVideoIndex: 1234,),isFalse,);diff --git a/mobile/apps/photos/test/module/metadata/photo_test.dart b/mobile/apps/photos/test/module/metadata/photo_test.dartindex b8a419ecd0..2b39e5c374 100644--- a/mobile/apps/photos/test/module/metadata/photo_test.dart+++ b/mobile/apps/photos/test/module/metadata/photo_test.dart@@ -6,6 +6,18 @@ import "package:photos/module/metadata/photo.dart";import "package:photos/src/rust/api/metadata_api.dart";void main() {+ test("media detection preserves other bits and clears stale detections", () {+ final file = EnteFile()+ ..pubMmdEncodedJson = '{"mediaType":2,"caption":"Keep me"}';+ applyMediaTypeMetadata(file, true, 1234);+ expect(file.pubMagicMetadata!.mediaType, 3);+ expect(file.pubMagicMetadata!.mvi, 1234);+ applyMediaTypeMetadata(file, false, 0);+ expect(file.pubMagicMetadata!.mediaType, 2);+ expect(file.pubMagicMetadata!.mvi, 0);+ expect(file.pubMagicMetadata!.caption, "Keep me");+ });+test("local discovery supplies oriented mosaic dimensions", () {final file = fileFromAsset("Camera",@@ -41,6 +53,8 @@ void main() {test("uses the parsed instant without applying the offset twice", () {const metadata = PhotoMetadata(dimensions: null,+ isPanorama: false,+ motionVideoStart: null,location: null,captureDateTime: CaptureDateTime(dateTime: "2024-01-01T12:00:00.123456",@@ -57,6 +71,8 @@ void main() {test("resolves an offset-free time locally without inventing an offset", () {const metadata = PhotoMetadata(dimensions: null,+ isPanorama: false,+ motionVideoStart: null,location: null,captureDateTime: CaptureDateTime(dateTime: "2024-01-01T12:00:00",diff --git a/rust/bindings/frb/photos/src/api/metadata_api.rs b/rust/bindings/frb/photos/src/api/metadata_api.rsindex 63b44e02c3..cc1b961e96 100644--- a/rust/bindings/frb/photos/src/api/metadata_api.rs+++ b/rust/bindings/frb/photos/src/api/metadata_api.rs@@ -5,6 +5,8 @@ pub struct PhotoMetadata {pub dimensions: Option<Dimensions>,pub capture_date_time: Option<CaptureDateTime>,pub location: Option<LocationCoordinate>,+ pub motion_video_start: Option<u64>,+ pub is_panorama: bool,}#[derive(Clone, Debug)]@@ -24,6 +26,8 @@ pub fn read_photo_metadata(file_path: String) -> Result<PhotoMetadata, String> {let metadata =ente_photos::metadata::read_photo_metadata(file_path).map_err(|error| error.to_string())?;Ok(PhotoMetadata {+ motion_video_start: metadata.motion_video.map(|video| video.start),+ is_panorama: metadata.is_panorama,dimensions: metadata.dimensions.map(|dimensions| Dimensions {width: dimensions.width,height: dimensions.height,diff --git a/rust/crates/photos/src/metadata.rs b/rust/crates/photos/src/metadata.rsindex 60f0db01f3..6bd4c7500d 100644--- a/rust/crates/photos/src/metadata.rs+++ b/rust/crates/photos/src/metadata.rs@@ -1,18 +1,24 @@use std::{fs::File, path::Path};-use ente_exif::{CaptureDateTime, DateTimePrecision, Dimensions, Error, Limits, Location, Mode};+use ente_exif::{+ CaptureDateTime, DateTimePrecision, Dimensions, Error, Limits, Location, Mode, VideoRange,+};#[derive(Debug)]pub struct PhotoMetadata {pub dimensions: Option<Dimensions>,pub capture_date_time: Option<CaptureDateTime>,pub location: Option<Location>,+ pub motion_video: Option<VideoRange>,+ pub is_panorama: bool,}pub fn read_photo_metadata(path: impl AsRef<Path>) -> Result<PhotoMetadata, Error> {let metadata = ente_exif::read(&mut File::open(path)?, Mode::Summary, Limits::default())?;Ok(PhotoMetadata {dimensions: metadata.display_dimensions(),+ motion_video: metadata.motion_video,+ is_panorama: metadata.is_panorama(),capture_date_time: metadata.capture_date_time_with(|date| {date.precision == DateTimePrecision::Second&& date.timestamp_micros != Some(0)diff --git a/rust/crates/photos/tests/metadata_test.rs b/rust/crates/photos/tests/metadata_test.rsindex 629343491d..6ebf3e18cf 100644--- a/rust/crates/photos/tests/metadata_test.rs+++ b/rust/crates/photos/tests/metadata_test.rs@@ -73,7 +73,30 @@ fn skips_partial_and_sentinel_capture_dates_and_continues_to_fallbacks() {);}+#[test]+fn reads_panorama_and_motion_video() {+ let plain = read("");+ assert!(!plain.is_panorama);+ assert_eq!(plain.motion_video, None);+ let video = b"\0\0\0\x10ftypisom\0\0\0\0\0\0\0\x08moov\0\0\0\x08mdat";+ let metadata = read_with_tail(+ r#"xmlns:GPano="http://ns.google.com/photos/1.0/panorama/"+ GPano:ProjectionType="equirectangular"+ xmlns:GCamera="http://ns.google.com/photos/1.0/camera/"+ GCamera:MicroVideoOffset="32""#,+ video,+ );+ assert!(metadata.is_panorama);+ let range = metadata.motion_video.unwrap();+ assert!(range.start > 0);+ assert_eq!(range.end - range.start, video.len() as u64);+}+fn read(properties: &str) -> PhotoMetadata {+ read_with_tail(properties, &[])+}++fn read_with_tail(properties: &str, tail: &[u8]) -> PhotoMetadata {let xmp = format!("http://ns.adobe.com/xap/1.0/\0<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"><rdf:Description xmlns:exif=\"http://ns.adobe.com/exif/1.0/\" xmlns:tiff=\"http://ns.adobe.com/tiff/1.0/\" xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\" {properties}/></rdf:RDF>");@@ -86,5 +109,6 @@ fn read(properties: &str) -> PhotoMetadata {0xff, 0xc0, 0, 11, 8, 0, 48, 0, 64, 1, 1, 0x11, 0, 0xff, 0xd9,]).unwrap();+ file.write_all(tail).unwrap();read_photo_metadata(file.path()).unwrap()}