Skip to content

armgit / ente

Public Imported from GitHub
0

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

Club into a live photo only if within 5 mins

Manav Rathic0f628ce2da3
diff --git a/web/apps/photos/src/services/upload/uploadManager.ts b/web/apps/photos/src/services/upload/uploadManager.ts
index dfa51d242f..23e7d7a97e 100644
--- a/web/apps/photos/src/services/upload/uploadManager.ts
+++ b/web/apps/photos/src/services/upload/uploadManager.ts
@@ -35,6 +35,7 @@ import {
type ParsedMetadataJSON,
} from "./takeout";
import UploadService, {
+ uploadItemCreationDate,
uploadItemFileName,
uploadItemSize,
uploader,
@@ -427,7 +428,10 @@ class UploadManager {
}
if (mediaItems.length) {
- const clusteredMediaItems = await clusterLivePhotos(mediaItems);
+ const clusteredMediaItems = await clusterLivePhotos(
+ mediaItems,
+ this.parsedMetadataJSONMap,
+ );
this.abortIfCancelled();
@@ -838,6 +842,7 @@ const markUploaded = async (electron: Electron, item: ClusteredUploadItem) => {
*/
const clusterLivePhotos = async (
items: UploadItemWithCollectionIDAndName[],
+ parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,
) => {
const result: ClusteredUploadItem[] = [];
items
@@ -865,7 +870,7 @@ const clusterLivePhotos = async (
collectionID: g.collectionID,
uploadItem: g.uploadItem,
};
- if (await areLivePhotoAssets(fa, ga)) {
+ if (await areLivePhotoAssets(fa, ga, parsedMetadataJSONMap)) {
const [image, video] =
fFileType == FileType.image ? [f, g] : [g, f];
result.push({
@@ -906,6 +911,7 @@ interface PotentialLivePhotoAsset {
const areLivePhotoAssets = async (
f: PotentialLivePhotoAsset,
g: PotentialLivePhotoAsset,
+ parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,
) => {
if (f.collectionID != g.collectionID) return false;
@@ -952,6 +958,27 @@ const areLivePhotoAssets = async (
return false;
}
+ // Finally, ensure that the creation times of the image and video are within
+ // some epsilon of each other. This is to avoid clubbing together unrelated
+ // items that coincidentally have the same name (this is not uncommon since,
+ // e.g. many cameras use a deterministic numbering scheme).
+
+ const fDate = await uploadItemCreationDate(
+ f.uploadItem,
+ f.fileType,
+ f.collectionID,
+ parsedMetadataJSONMap,
+ );
+ const gDate = await uploadItemCreationDate(
+ g.uploadItem,
+ g.fileType,
+ g.collectionID,
+ parsedMetadataJSONMap,
+ );
+ if (!fDate || !gDate) return false;
+ const secondDelta = Math.abs(fDate - gDate) / 1e6;
+ if (secondDelta > 5 * 60 /* 5 mins */) return false;
+
return true;
};
diff --git a/web/apps/photos/src/services/upload/uploadService.ts b/web/apps/photos/src/services/upload/uploadService.ts
index 2a60e7242f..e8e907c3f1 100644
--- a/web/apps/photos/src/services/upload/uploadService.ts
+++ b/web/apps/photos/src/services/upload/uploadService.ts
@@ -868,12 +868,11 @@ const tryExtractVideoMetadata = async (uploadItem: UploadItem) => {
*/
export const uploadItemCreationDate = async (
uploadItem: UploadItem,
- fileTypeInfo: FileTypeInfo,
+ fileType: FileType,
collectionID: number,
parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,
) => {
const fileName = uploadItemFileName(uploadItem);
- const { fileType } = fileTypeInfo;
const parsedMetadataJSON = matchTakeoutMetadata(
fileName,
@@ -893,7 +892,7 @@ export const uploadItemCreationDate = async (
throw new Error(`Unexpected file type ${fileType} for ${uploadItem}`);
}
- return parsedMetadata.creationDate;
+ return parsedMetadata.creationDate?.timestamp;
};
/**