Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][web] Add support for search by camera model

Neeraj Guptaf88144d83eeb
diff --git a/mobile/apps/photos/lib/models/file/extensions/file_props.dart b/mobile/apps/photos/lib/models/file/extensions/file_props.dart
index 01ab6b7254..ce654b391c 100644
--- a/mobile/apps/photos/lib/models/file/extensions/file_props.dart
+++ b/mobile/apps/photos/lib/models/file/extensions/file_props.dart
@@ -49,6 +49,16 @@ extension FilePropsExtn on EnteFile {
String? get uploaderName => pubMagicMetadata?.uploaderName;
+ String? get cameraModel => pubMagicMetadata?.cameraModel;
+
+ String? get cameraLabel {
+ final model = cameraModel?.trim();
+ if (model == null || model.isEmpty) {
+ return null;
+ }
+ return model;
+ }
+
bool get skipIndex => !isUploaded || fileType == FileType.other;
bool canReUpload(int userID) =>
diff --git a/mobile/apps/photos/lib/models/metadata/file_magic.dart b/mobile/apps/photos/lib/models/metadata/file_magic.dart
index 53627aafbc..0dc988eb67 100644
--- a/mobile/apps/photos/lib/models/metadata/file_magic.dart
+++ b/mobile/apps/photos/lib/models/metadata/file_magic.dart
@@ -13,6 +13,7 @@ const streamVersionKey = 'sv';
const mediaTypeKey = 'mediaType';
const latKey = "lat";
const longKey = "long";
+const cameraModelKey = 'cameraModel';
const motionVideoIndexKey = "mvi";
const noThumbKey = "noThumb";
const dateTimeKey = 'dateTime';
@@ -48,6 +49,7 @@ class PubMagicMetadata {
int? h;
double? lat;
double? long;
+ String? cameraModel;
// Indicates streaming version of the file.
// If this is set, then the file is a streaming version of the original file.
@@ -83,6 +85,7 @@ class PubMagicMetadata {
this.h,
this.lat,
this.long,
+ this.cameraModel,
this.mvi,
this.noThumb,
this.mediaType,
@@ -108,6 +111,7 @@ class PubMagicMetadata {
h: safeParseInt(map[heightKey], heightKey),
lat: map[latKey],
long: map[longKey],
+ cameraModel: map[cameraModelKey],
mvi: map[motionVideoIndexKey],
noThumb: map[noThumbKey],
mediaType: map[mediaTypeKey],
diff --git a/mobile/apps/photos/lib/models/search/hierarchical/camera_filter.dart b/mobile/apps/photos/lib/models/search/hierarchical/camera_filter.dart
new file mode 100644
index 0000000000..8229aa6400
--- /dev/null
+++ b/mobile/apps/photos/lib/models/search/hierarchical/camera_filter.dart
@@ -0,0 +1,44 @@
+import "package:flutter/material.dart";
+import "package:photos/models/file/extensions/file_props.dart";
+import "package:photos/models/file/file.dart";
+import "package:photos/models/search/hierarchical/hierarchical_search_filter.dart";
+
+class CameraFilter extends HierarchicalSearchFilter {
+ final String cameraLabel;
+ final int occurrence;
+
+ CameraFilter({
+ required this.cameraLabel,
+ required this.occurrence,
+ super.filterTypeName = "cameraFilter",
+ super.matchedUploadedIDs,
+ });
+
+ @override
+ String name() {
+ return cameraLabel;
+ }
+
+ @override
+ int relevance() {
+ return occurrence;
+ }
+
+ @override
+ bool isMatch(EnteFile file) {
+ return file.cameraLabel == cameraLabel;
+ }
+
+ @override
+ bool isSameFilter(HierarchicalSearchFilter other) {
+ if (other is CameraFilter) {
+ return other.cameraLabel == cameraLabel;
+ }
+ return false;
+ }
+
+ @override
+ IconData? icon() {
+ return Icons.photo_camera_outlined;
+ }
+}
diff --git a/mobile/apps/photos/lib/models/search/hierarchical/hierarchical_search_filter.dart b/mobile/apps/photos/lib/models/search/hierarchical/hierarchical_search_filter.dart
index 7e99fe3424..084636df35 100644
--- a/mobile/apps/photos/lib/models/search/hierarchical/hierarchical_search_filter.dart
+++ b/mobile/apps/photos/lib/models/search/hierarchical/hierarchical_search_filter.dart
@@ -14,6 +14,7 @@ enum FilterTypeNames {
topLevelGenericFilter,
uploaderFilter,
onlyThemFilter,
+ cameraFilter,
}
abstract class HierarchicalSearchFilter {
diff --git a/mobile/apps/photos/lib/models/search/search_types.dart b/mobile/apps/photos/lib/models/search/search_types.dart
index 8cb830a6e3..d9d13d37a7 100644
--- a/mobile/apps/photos/lib/models/search/search_types.dart
+++ b/mobile/apps/photos/lib/models/search/search_types.dart
@@ -38,6 +38,7 @@ enum ResultType {
shared,
faces,
magic,
+ camera,
}
enum SectionType {
diff --git a/mobile/apps/photos/lib/services/search_service.dart b/mobile/apps/photos/lib/services/search_service.dart
index b8d7b9ba6e..c04ab85b75 100644
--- a/mobile/apps/photos/lib/services/search_service.dart
+++ b/mobile/apps/photos/lib/services/search_service.dart
@@ -30,6 +30,7 @@ import "package:photos/models/memories/smart_memory.dart";
import "package:photos/models/ml/face/person.dart";
import 'package:photos/models/search/album_search_result.dart';
import 'package:photos/models/search/generic_search_result.dart';
+import "package:photos/models/search/hierarchical/camera_filter.dart";
import "package:photos/models/search/hierarchical/contacts_filter.dart";
import "package:photos/models/search/hierarchical/face_filter.dart";
import "package:photos/models/search/hierarchical/file_type_filter.dart";
@@ -477,6 +478,7 @@ class SearchService {
final List<EnteFile> captionMatch = <EnteFile>[];
final List<EnteFile> displayNameMatch = <EnteFile>[];
final Map<String, List<EnteFile>> uploaderToFile = {};
+ final Map<String, List<EnteFile>> cameraToFiles = {};
for (EnteFile eachFile in allFiles) {
if (eachFile.caption != null && pattern.hasMatch(eachFile.caption!)) {
captionMatch.add(eachFile);
@@ -491,6 +493,10 @@ class SearchService {
}
uploaderToFile[eachFile.uploaderName!]!.add(eachFile);
}
+ final cameraLabel = eachFile.cameraLabel;
+ if (cameraLabel != null && pattern.hasMatch(cameraLabel)) {
+ cameraToFiles.putIfAbsent(cameraLabel, () => []).add(eachFile);
+ }
}
if (captionMatch.isNotEmpty) {
searchResults.add(
@@ -539,6 +545,22 @@ class SearchService {
);
}
}
+ if (cameraToFiles.isNotEmpty) {
+ for (final entry in cameraToFiles.entries) {
+ searchResults.add(
+ GenericSearchResult(
+ ResultType.camera,
+ entry.key,
+ entry.value,
+ hierarchicalSearchFilter: CameraFilter(
+ cameraLabel: entry.key,
+ occurrence: kMostRelevantFilter,
+ matchedUploadedIDs: filesToUploadedFileIDs(entry.value),
+ ),
+ ),
+ );
+ }
+ }
return searchResults;
}
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/search_result_widget.dart b/mobile/apps/photos/lib/ui/viewer/search/result/search_result_widget.dart
index 8362b4e604..35bf88106f 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/search_result_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/search_result_widget.dart
@@ -166,6 +166,8 @@ class SearchResultWidget extends StatelessWidget {
return "Person";
case ResultType.uploader:
return "Uploaded by";
+ case ResultType.camera:
+ return "Camera";
}
}
}
diff --git a/mobile/apps/photos/lib/utils/file_uploader.dart b/mobile/apps/photos/lib/utils/file_uploader.dart
index 5d91af9b82..65049324e7 100644
--- a/mobile/apps/photos/lib/utils/file_uploader.dart
+++ b/mobile/apps/photos/lib/utils/file_uploader.dart
@@ -1093,6 +1093,9 @@ class FileUploader {
pubMetadata[offsetTimeKey] = exifTime.offsetTime;
}
}
+ if ((mediaUploadData.cameraModel ?? '').isNotEmpty) {
+ pubMetadata[cameraModelKey] = mediaUploadData.cameraModel;
+ }
return pubMetadata;
}
diff --git a/mobile/apps/photos/lib/utils/file_uploader_util.dart b/mobile/apps/photos/lib/utils/file_uploader_util.dart
index ba1db4da72..2d6a724348 100644
--- a/mobile/apps/photos/lib/utils/file_uploader_util.dart
+++ b/mobile/apps/photos/lib/utils/file_uploader_util.dart
@@ -40,6 +40,7 @@ class MediaUploadData {
final FileHashData? hashData;
final int? height;
final int? width;
+ final String? cameraModel;
// For android motion photos, the startIndex is the index of the first frame
// For iOS, this value will be always null.
@@ -56,6 +57,7 @@ class MediaUploadData {
this.hashData, {
this.height,
this.width,
+ this.cameraModel,
this.motionPhotoStartIndex,
this.isPanorama,
this.exifData,
@@ -73,6 +75,17 @@ class FileHashData {
FileHashData(this.fileHash, {this.zipHash});
}
+String? _extractPrintableExifValue(IfdTag? tag) {
+ final printable = tag?.printable?.trim();
+ if (printable == null || printable.isEmpty) {
+ return null;
+ }
+ if (printable.toLowerCase() == 'null') {
+ return null;
+ }
+ return printable;
+}
+
Future<MediaUploadData> getUploadDataFromEnteFile(
EnteFile file, {
bool parseExif = false,
@@ -94,6 +107,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(
String? zipHash;
String fileHash;
Map<String, IfdTag>? exifData;
+ String? cameraModel;
// The timeouts are to safeguard against https://github.com/CaiJingLong/flutter_photo_manager/issues/467
final asset = await file.getAsset
@@ -131,6 +145,9 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(
}
if (parseExif) {
exifData = await tryExifFromFile(sourceFile);
+ if (exifData != null) {
+ cameraModel = _extractPrintableExifValue(exifData['Image Model']);
+ }
}
// h4ck to fetch location data if missing (thank you Android Q+) lazily only during uploads
await _decorateEnteFileData(file, asset, sourceFile, exifData);
@@ -193,6 +210,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(
FileHashData(fileHash, zipHash: zipHash),
height: h,
width: w,
+ cameraModel: cameraModel,
motionPhotoStartIndex: motionPhotoStartingIndex,
exifData: exifData,
);
@@ -363,6 +381,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAppCache(
File sourceFile;
Uint8List? thumbnailData;
Map<String, IfdTag>? exifData;
+ String? cameraModel;
const bool isDeleted = false;
final localPath = getSharedMediaFilePath(file);
sourceFile = File(localPath);
@@ -381,6 +400,9 @@ Future<MediaUploadData> _getMediaUploadDataFromAppCache(
if (file.fileType == FileType.image) {
dimensions = await getImageHeightAndWith(imagePath: localPath);
exifData = await tryExifFromFile(sourceFile);
+ if (exifData != null) {
+ cameraModel = _extractPrintableExifValue(exifData['Image Model']);
+ }
} else if (thumbnailData != null) {
// the thumbnail null check is to ensure that we are able to generate thum
// for video, we need to use the thumbnail data with any max width/height
@@ -399,6 +421,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAppCache(
FileHashData(fileHash),
height: dimensions?['height'],
width: dimensions?['width'],
+ cameraModel: cameraModel,
exifData: exifData,
);
} catch (e, s) {
diff --git a/mobile/apps/photos/lib/utils/hierarchical_search_util.dart b/mobile/apps/photos/lib/utils/hierarchical_search_util.dart
index 4ce5ba6236..96e0acf21e 100644
--- a/mobile/apps/photos/lib/utils/hierarchical_search_util.dart
+++ b/mobile/apps/photos/lib/utils/hierarchical_search_util.dart
@@ -11,6 +11,7 @@ import "package:photos/models/file/file_type.dart";
import "package:photos/models/location_tag/location_tag.dart";
import "package:photos/models/ml/face/person.dart";
import "package:photos/models/search/hierarchical/album_filter.dart";
+import "package:photos/models/search/hierarchical/camera_filter.dart";
import "package:photos/models/search/hierarchical/contacts_filter.dart";
import "package:photos/models/search/hierarchical/face_filter.dart";
import "package:photos/models/search/hierarchical/file_type_filter.dart";
@@ -158,6 +159,7 @@ Future<void> curateFilters(
);
final contactsFilters = _curateContactsFilter(files);
final uploaderFilters = _curateUploaderFilter(files);
+ final cameraFilters = _curateCameraFilters(files);
final faceFilters = await curateFaceFilters(files);
final magicFilters = await curateMagicFilters(files, context);
final onlyThemFilter = getOnlyThemFilter(
@@ -173,6 +175,7 @@ Future<void> curateFilters(
...fileTypeFilters,
...contactsFilters,
...uploaderFilters,
+ ...cameraFilters,
...albumFilters,
...locationFilters,
],
@@ -350,6 +353,33 @@ List<ContactsFilter> _curateContactsFilter(
return contactsFilters;
}
+List<CameraFilter> _curateCameraFilters(
+ List<EnteFile> files,
+) {
+ final cameraFilters = <CameraFilter>[];
+ final labelToOccurrence = <String, int>{};
+
+ for (final file in files) {
+ final cameraLabel = file.cameraLabel;
+ if (cameraLabel == null || cameraLabel.isEmpty) {
+ continue;
+ }
+ labelToOccurrence[cameraLabel] =
+ (labelToOccurrence[cameraLabel] ?? 0) + 1;
+ }
+
+ for (final entry in labelToOccurrence.entries) {
+ cameraFilters.add(
+ CameraFilter(
+ cameraLabel: entry.key,
+ occurrence: entry.value,
+ ),
+ );
+ }
+
+ return cameraFilters;
+}
+
List<UploaderFilter> _curateUploaderFilter(
List<EnteFile> files,
) {
@@ -538,6 +568,13 @@ Map<String, List<HierarchicalSearchFilter>> getFiltersForBottomSheet(
searchFilterDataProvider.recommendations.whereType<UploaderFilter>(),
);
+ final cameraFilters = searchFilterDataProvider.appliedFilters
+ .whereType<CameraFilter>()
+ .toList();
+ cameraFilters.addAll(
+ searchFilterDataProvider.recommendations.whereType<CameraFilter>(),
+ );
+
final magicFilters =
searchFilterDataProvider.appliedFilters.whereType<MagicFilter>().toList();
magicFilters.addAll(
@@ -555,6 +592,7 @@ Map<String, List<HierarchicalSearchFilter>> getFiltersForBottomSheet(
"locationFilters": locationFilters,
"contactsFilters": contactsFilters,
"uploaderFilters": uploaderFilters,
+ "cameraFilters": cameraFilters,
"albumFilters": albumFilters,
"fileTypeFilters": fileTypeFilters,
"topLevelGenericFilter": topLevelGenericFilter,
@@ -605,6 +643,7 @@ List<HierarchicalSearchFilter> getRecommendedFiltersForAppBar(
final locationReccos = <LocationFilter>[];
final contactsReccos = <ContactsFilter>[];
final uploaderReccos = <UploaderFilter>[];
+ final cameraReccos = <CameraFilter>[];
final albumReccos = <AlbumFilter>[];
final fileTypeReccos = <FileTypeFilter>[];
final onlyThemFilter = <OnlyThemFilter>[];
@@ -622,6 +661,8 @@ List<HierarchicalSearchFilter> getRecommendedFiltersForAppBar(
contactsReccos.add(recommendation);
} else if (recommendation is UploaderFilter) {
uploaderReccos.add(recommendation);
+ } else if (recommendation is CameraFilter) {
+ cameraReccos.add(recommendation);
} else if (recommendation is AlbumFilter) {
albumReccos.add(recommendation);
} else if (recommendation is FileTypeFilter) {
@@ -636,6 +677,7 @@ List<HierarchicalSearchFilter> getRecommendedFiltersForAppBar(
...locationReccos,
...contactsReccos,
...uploaderReccos,
+ ...cameraReccos,
...albumReccos,
...fileTypeReccos,
];
diff --git a/web/packages/gallery/services/exif.ts b/web/packages/gallery/services/exif.ts
index 3c79619936..33976b7819 100644
--- a/web/packages/gallery/services/exif.ts
+++ b/web/packages/gallery/services/exif.ts
@@ -41,11 +41,13 @@ export const parseExif = (tags: RawExifTags) => {
const creationDate = parseCreationDate(tags);
const dimensions = parseDimensions(tags);
const description = parseDescription(tags);
+ const camera = parseCamera(tags);
const metadata: ParsedMetadata = dimensions ?? {};
if (creationDate) metadata.creationDate = creationDate;
if (location) metadata.location = location;
if (description) metadata.description = description;
+ if (camera?.model) metadata.cameraModel = camera.model;
return metadata;
};
@@ -606,6 +608,13 @@ export const tagNumericValue = (
return Array.isArray(v) ? (v[0] ?? 0) / (v[1] ?? 1) : v;
};
+const parseCamera = (tags: RawExifTags) => {
+ const make = tags.exif?.Make?.description?.trim();
+ const model = tags.exif?.Model?.description?.trim();
+ if (!make && !model) return undefined;
+ return { make, model };
+};
+
/**
* Parse the description for an image from the metadata embedded in the file.
*
diff --git a/web/packages/gallery/services/upload/upload-service.ts b/web/packages/gallery/services/upload/upload-service.ts
index 017b2db572..9cfae0a99c 100644
--- a/web/packages/gallery/services/upload/upload-service.ts
+++ b/web/packages/gallery/services/upload/upload-service.ts
@@ -1274,6 +1274,10 @@ const extractImageOrVideoMetadata = async (
publicMagicMetadata.caption = caption;
}
+ if (parsedMetadata?.cameraModel) {
+ publicMagicMetadata.cameraModel = parsedMetadata.cameraModel;
+ }
+
return { metadata, publicMagicMetadata };
};
diff --git a/web/packages/media/file-metadata.ts b/web/packages/media/file-metadata.ts
index 1f18193993..d18fa69e28 100644
--- a/web/packages/media/file-metadata.ts
+++ b/web/packages/media/file-metadata.ts
@@ -344,6 +344,8 @@ export interface FilePublicMagicMetadataData {
* (The owner of such files will be the owner of the collection)
*/
uploaderName?: string;
+ /** Camera model extracted from metadata. */
+ cameraModel?: string;
/**
* Edited latitude of the file
*
@@ -407,6 +409,7 @@ export const FilePublicMagicMetadataData = z.looseObject({
h: z.number().nullish().transform(nullToUndefined),
caption: z.string().nullish().transform(nullToUndefined),
uploaderName: z.string().nullish().transform(nullToUndefined),
+ cameraModel: z.string().nullish().transform(nullToUndefined),
lat: z.number().nullish().transform(nullToUndefined),
long: z.number().nullish().transform(nullToUndefined),
sv: z.number().nullish().transform(nullToUndefined),
@@ -503,6 +506,15 @@ export const fileLocation = (file: EnteFile): Location | undefined => {
return { latitude, longitude };
};
+/**
+ * Return a user-friendly string describing the camera used for the file.
+ */
+export const fileCameraLabel = (file: EnteFile): string | undefined => {
+ const model = file.pubMagicMetadata?.data?.cameraModel?.trim();
+ if (!model || model.length === 0) return undefined;
+ return model;
+};
+
/**
* Return the duration of the video as a formatted "HH:mm:ss" string (when
* present) for the given {@link EnteFile}.
@@ -587,6 +599,8 @@ export interface ParsedMetadata {
* A caption / description attached by the user to the photo.
*/
description?: string;
+ /** Camera model extracted from metadata (e.g. iPhone 15 Pro). */
+ cameraModel?: string;
}
/**
diff --git a/web/packages/new/photos/components/SearchBar.tsx b/web/packages/new/photos/components/SearchBar.tsx
index 68dfbba4e2..463934cd68 100644
--- a/web/packages/new/photos/components/SearchBar.tsx
+++ b/web/packages/new/photos/components/SearchBar.tsx
@@ -1,4 +1,5 @@
import CalendarIcon from "@mui/icons-material/CalendarMonth";
+import CameraIcon from "@mui/icons-material/PhotoCameraOutlined";
import CloseIcon from "@mui/icons-material/Close";
import ImageIcon from "@mui/icons-material/Image";
import LocationIcon from "@mui/icons-material/LocationOn";
@@ -442,6 +443,8 @@ const iconForOption = (option: SearchOption | undefined) => {
return <ImageIcon />;
case "date":
return <CalendarIcon />;
+ case "camera":
+ return <CameraIcon />;
case "sidebarAction":
return <SettingsIcon />;
case "location":
@@ -655,6 +658,9 @@ const labelForOption = (option: SearchOption) => {
case "fileCaption":
return t("description");
+ case "camera":
+ return t("camera", { defaultValue: "Camera" });
+
case "date":
return t("date");
diff --git a/web/packages/new/photos/services/search/types.ts b/web/packages/new/photos/services/search/types.ts
index 846a1b92c5..46f96092ba 100644
--- a/web/packages/new/photos/services/search/types.ts
+++ b/web/packages/new/photos/services/search/types.ts
@@ -71,6 +71,7 @@ export type SearchSuggestion = { label: string } & (
| { type: "fileType"; fileType: FileType }
| { type: "fileName"; fileIDs: number[] }
| { type: "fileCaption"; fileIDs: number[] }
+ | { type: "camera"; fileIDs: number[] }
| { type: "date"; dateComponents: SearchDateComponents }
| { type: "location"; locationTag: LocationTag }
| { type: "city"; city: City }
diff --git a/web/packages/new/photos/services/search/worker.ts b/web/packages/new/photos/services/search/worker.ts
index 200f154fa3..6d6c2595c8 100644
--- a/web/packages/new/photos/services/search/worker.ts
+++ b/web/packages/new/photos/services/search/worker.ts
@@ -9,6 +9,7 @@ import type { EnteFile } from "ente-media/file";
import {
fileCreationPhotoDate,
fileFileName,
+ fileCameraLabel,
fileLocation,
} from "ente-media/file-metadata";
import { nullToUndefined } from "ente-utils/transform";
@@ -144,6 +145,7 @@ const suggestionsForString = (
collectionSuggestions(re, collections),
fileNameSuggestion(s, re, searchString, files),
fileCaptionSuggestion(re, searchString, files),
+ cameraSuggestions(re, searchString, files),
].flat(),
];
@@ -204,6 +206,31 @@ const fileCaptionSuggestion = (
: [];
};
+const cameraSuggestions = (
+ re: RegExp,
+ _searchString: string,
+ files: EnteFile[],
+): SearchSuggestion[] => {
+ const matches = new Map<string, { label: string; fileIDs: number[] }>();
+ for (const file of files) {
+ const label = fileCameraLabel(file);
+ if (!label || !re.test(label)) continue;
+ const key = label.toLowerCase();
+ const existing = matches.get(key);
+ if (existing) {
+ existing.fileIDs.push(file.id);
+ } else {
+ matches.set(key, { label, fileIDs: [file.id] });
+ }
+ }
+
+ return Array.from(matches.values()).map(({ label, fileIDs }) => ({
+ type: "camera" as const,
+ label,
+ fileIDs,
+ }));
+};
+
const peopleSuggestions = (
re: RegExp,
people: NamedPerson[],
@@ -424,6 +451,7 @@ const isMatchingFile = (file: EnteFile, suggestion: SearchSuggestion) => {
return suggestion.fileIDs.includes(file.id);
case "fileCaption":
+ case "camera":
return suggestion.fileIDs.includes(file.id);
case "date":