Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Share embedded location enrichment

Neeraj Gupta88b17c1d4538
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.dart
index 5763ecee91..ed48a1ae03 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
@@ -7,12 +7,12 @@ import "package:photos/core/event_bus.dart";
import "package:photos/db/files_db.dart";
import "package:photos/events/files_updated_event.dart";
import "package:photos/events/local_photos_updated_event.dart";
-import "package:photos/models/file/extensions/file_props.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/location/location.dart";
import "package:photos/module/upload/model/media_upload_data.dart";
import "package:photos/module/upload/upload_metadata.dart";
import "package:photos/service_locator.dart";
+import "package:photos/utils/embedded_media_location.dart";
import "package:photos/utils/exif_util.dart";
import "package:photos/utils/file_util.dart";
@@ -166,18 +166,6 @@ class OfflineImportMetadataService {
}
}
- if (!file.hasLocation && file.isVideo && Platform.isAndroid) {
- final props = await getVideoPropsAsync(originFile);
- if (props?.location != null) {
- file.location = props!.location;
- }
- }
-
- if (Platform.isAndroid && exifData != null) {
- final exifLocation = locationFromExif(exifData);
- if (Location.isValidLocation(exifLocation)) {
- file.location = exifLocation;
- }
- }
+ await updateLocationFromEmbeddedMetadata(file, originFile, exifData);
}
}
diff --git a/mobile/apps/photos/lib/utils/embedded_media_location.dart b/mobile/apps/photos/lib/utils/embedded_media_location.dart
new file mode 100644
index 0000000000..31d2c8813f
--- /dev/null
+++ b/mobile/apps/photos/lib/utils/embedded_media_location.dart
@@ -0,0 +1,30 @@
+import "dart:io";
+
+import "package:exif_reader/exif_reader.dart";
+import "package:photos/models/file/extensions/file_props.dart";
+import "package:photos/models/file/file.dart";
+import "package:photos/models/location/location.dart";
+import "package:photos/utils/exif_util.dart";
+
+/// Adds Android location metadata to [file], preferring valid EXIF data.
+Future<void> updateLocationFromEmbeddedMetadata(
+ EnteFile file,
+ File sourceFile,
+ Map<String, IfdTag>? exifData,
+) async {
+ if (!Platform.isAndroid) {
+ return;
+ }
+ if (!file.hasLocation && file.isVideo) {
+ final videoLocation = (await getVideoPropsAsync(sourceFile))?.location;
+ if (videoLocation != null) {
+ file.location = videoLocation;
+ }
+ }
+ if (exifData != null) {
+ final exifLocation = locationFromExif(exifData);
+ if (Location.isValidLocation(exifLocation)) {
+ file.location = exifLocation;
+ }
+ }
+}
diff --git a/mobile/apps/photos/lib/utils/file_uploader_util.dart b/mobile/apps/photos/lib/utils/file_uploader_util.dart
index 6fcc7553cc..10450ae393 100644
--- a/mobile/apps/photos/lib/utils/file_uploader_util.dart
+++ b/mobile/apps/photos/lib/utils/file_uploader_util.dart
@@ -26,6 +26,7 @@ import 'package:photos/module/upload/model/media_upload_data.dart';
import "package:photos/services/sync/local_sync_service.dart";
import "package:photos/src/rust/api/motion_photo_api.dart";
import "package:photos/utils/apple_photos_errors.dart";
+import "package:photos/utils/embedded_media_location.dart";
import "package:photos/utils/exif_util.dart";
import 'package:photos/utils/file_util.dart';
import 'package:photos/utils/thumbnail_util.dart';
@@ -323,19 +324,7 @@ Future<void> _decorateEnteFileData(
longitude: latLong.longitude,
);
}
- if (!file.hasLocation && file.isVideo && Platform.isAndroid) {
- final FFProbeProps? props = await getVideoPropsAsync(sourceFile);
- if (props != null && props.location != null) {
- file.location = props.location;
- }
- }
- if (Platform.isAndroid && exifData != null) {
- //Fix for missing location data in lower android versions.
- final Location? exifLocation = locationFromExif(exifData);
- if (Location.isValidLocation(exifLocation)) {
- file.location = exifLocation;
- }
- }
+ await updateLocationFromEmbeddedMetadata(file, sourceFile, exifData);
if (Platform.isIOS) {
final originalTitle = await asset.titleAsync;
if (originalTitle.isNotEmpty) {