Skip to content

armgit / ente

Public Imported from GitHub
0

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

Store make and model seperately

Neeraj Gupta294b01c7b084
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 ce654b391c..bd4568b09d 100644
--- a/mobile/apps/photos/lib/models/file/extensions/file_props.dart
+++ b/mobile/apps/photos/lib/models/file/extensions/file_props.dart
@@ -49,14 +49,20 @@ extension FilePropsExtn on EnteFile {
String? get uploaderName => pubMagicMetadata?.uploaderName;
+ String? get cameraMake => pubMagicMetadata?.cameraMake;
+
String? get cameraModel => pubMagicMetadata?.cameraModel;
String? get cameraLabel {
+ final make = cameraMake?.trim();
final model = cameraModel?.trim();
- if (model == null || model.isEmpty) {
+ if ((make == null || make.isEmpty) && (model == null || model.isEmpty)) {
return null;
}
- return model;
+ if (make != null && make.isNotEmpty && model != null && model.isNotEmpty) {
+ return '$make $model';
+ }
+ return model ?? make;
}
bool get skipIndex => !isUploaded || fileType == FileType.other;
diff --git a/mobile/apps/photos/lib/models/metadata/file_magic.dart b/mobile/apps/photos/lib/models/metadata/file_magic.dart
index 0dc988eb67..a9818633f3 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 cameraMakeKey = 'cameraMake';
const cameraModelKey = 'cameraModel';
const motionVideoIndexKey = "mvi";
const noThumbKey = "noThumb";
@@ -49,6 +50,7 @@ class PubMagicMetadata {
int? h;
double? lat;
double? long;
+ String? cameraMake;
String? cameraModel;
// Indicates streaming version of the file.
@@ -85,6 +87,7 @@ class PubMagicMetadata {
this.h,
this.lat,
this.long,
+ this.cameraMake,
this.cameraModel,
this.mvi,
this.noThumb,
@@ -111,6 +114,7 @@ class PubMagicMetadata {
h: safeParseInt(map[heightKey], heightKey),
lat: map[latKey],
long: map[longKey],
+ cameraMake: map[cameraMakeKey],
cameraModel: map[cameraModelKey],
mvi: map[motionVideoIndexKey],
noThumb: map[noThumbKey],
diff --git a/mobile/apps/photos/lib/models/search/hierarchical/camera_filter.dart b/mobile/apps/photos/lib/models/search/hierarchical/camera_filter.dart
index 8229aa6400..1889705e96 100644
--- a/mobile/apps/photos/lib/models/search/hierarchical/camera_filter.dart
+++ b/mobile/apps/photos/lib/models/search/hierarchical/camera_filter.dart
@@ -4,11 +4,11 @@ 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 String cameraModel;
final int occurrence;
CameraFilter({
- required this.cameraLabel,
+ required this.cameraModel,
required this.occurrence,
super.filterTypeName = "cameraFilter",
super.matchedUploadedIDs,
@@ -16,7 +16,7 @@ class CameraFilter extends HierarchicalSearchFilter {
@override
String name() {
- return cameraLabel;
+ return cameraModel;
}
@override
@@ -26,13 +26,13 @@ class CameraFilter extends HierarchicalSearchFilter {
@override
bool isMatch(EnteFile file) {
- return file.cameraLabel == cameraLabel;
+ return file.cameraModel == cameraModel;
}
@override
bool isSameFilter(HierarchicalSearchFilter other) {
if (other is CameraFilter) {
- return other.cameraLabel == cameraLabel;
+ return other.cameraModel == cameraModel;
}
return false;
}
diff --git a/mobile/apps/photos/lib/models/search/search_types.dart b/mobile/apps/photos/lib/models/search/search_types.dart
index d9d13d37a7..adc57c4c90 100644
--- a/mobile/apps/photos/lib/models/search/search_types.dart
+++ b/mobile/apps/photos/lib/models/search/search_types.dart
@@ -38,7 +38,8 @@ enum ResultType {
shared,
faces,
magic,
- camera,
+ cameraMake,
+ cameraModel,
}
enum SectionType {
diff --git a/mobile/apps/photos/lib/services/search_service.dart b/mobile/apps/photos/lib/services/search_service.dart
index c04ab85b75..f11edae930 100644
--- a/mobile/apps/photos/lib/services/search_service.dart
+++ b/mobile/apps/photos/lib/services/search_service.dart
@@ -478,7 +478,8 @@ class SearchService {
final List<EnteFile> captionMatch = <EnteFile>[];
final List<EnteFile> displayNameMatch = <EnteFile>[];
final Map<String, List<EnteFile>> uploaderToFile = {};
- final Map<String, List<EnteFile>> cameraToFiles = {};
+ final Map<String, List<EnteFile>> cameraMakeToFiles = {};
+ final Map<String, List<EnteFile>> cameraModelToFiles = {};
for (EnteFile eachFile in allFiles) {
if (eachFile.caption != null && pattern.hasMatch(eachFile.caption!)) {
captionMatch.add(eachFile);
@@ -493,9 +494,13 @@ class SearchService {
}
uploaderToFile[eachFile.uploaderName!]!.add(eachFile);
}
- final cameraLabel = eachFile.cameraLabel;
- if (cameraLabel != null && pattern.hasMatch(cameraLabel)) {
- cameraToFiles.putIfAbsent(cameraLabel, () => []).add(eachFile);
+ final cameraMake = eachFile.cameraMake;
+ if (cameraMake != null && pattern.hasMatch(cameraMake)) {
+ cameraMakeToFiles.putIfAbsent(cameraMake, () => []).add(eachFile);
+ }
+ final cameraModel = eachFile.cameraModel;
+ if (cameraModel != null && pattern.hasMatch(cameraModel)) {
+ cameraModelToFiles.putIfAbsent(cameraModel, () => []).add(eachFile);
}
}
if (captionMatch.isNotEmpty) {
@@ -545,15 +550,33 @@ class SearchService {
);
}
}
- if (cameraToFiles.isNotEmpty) {
- for (final entry in cameraToFiles.entries) {
+ if (cameraMakeToFiles.isNotEmpty) {
+ for (final entry in cameraMakeToFiles.entries) {
+ searchResults.add(
+ GenericSearchResult(
+ ResultType.cameraMake,
+ entry.key,
+ entry.value,
+ hierarchicalSearchFilter: TopLevelGenericFilter(
+ filterName: entry.key,
+ occurrence: kMostRelevantFilter,
+ filterResultType: ResultType.cameraMake,
+ matchedUploadedIDs: filesToUploadedFileIDs(entry.value),
+ filterIcon: Icons.photo_camera_outlined,
+ ),
+ ),
+ );
+ }
+ }
+ if (cameraModelToFiles.isNotEmpty) {
+ for (final entry in cameraModelToFiles.entries) {
searchResults.add(
GenericSearchResult(
- ResultType.camera,
+ ResultType.cameraModel,
entry.key,
entry.value,
hierarchicalSearchFilter: CameraFilter(
- cameraLabel: entry.key,
+ cameraModel: entry.key,
occurrence: kMostRelevantFilter,
matchedUploadedIDs: filesToUploadedFileIDs(entry.value),
),
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 35bf88106f..626f68b670 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,8 +166,10 @@ class SearchResultWidget extends StatelessWidget {
return "Person";
case ResultType.uploader:
return "Uploaded by";
- case ResultType.camera:
- return "Camera";
+ case ResultType.cameraMake:
+ return "Camera Make";
+ case ResultType.cameraModel:
+ return "Camera Model";
}
}
}
diff --git a/mobile/apps/photos/lib/utils/file_uploader.dart b/mobile/apps/photos/lib/utils/file_uploader.dart
index 65049324e7..58be49910c 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.cameraMake ?? '').isNotEmpty) {
+ pubMetadata[cameraMakeKey] = mediaUploadData.cameraMake;
+ }
if ((mediaUploadData.cameraModel ?? '').isNotEmpty) {
pubMetadata[cameraModelKey] = mediaUploadData.cameraModel;
}
diff --git a/mobile/apps/photos/lib/utils/file_uploader_util.dart b/mobile/apps/photos/lib/utils/file_uploader_util.dart
index d16ccff826..dd61e50f94 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? cameraMake;
final String? cameraModel;
// For android motion photos, the startIndex is the index of the first frame
@@ -57,6 +58,7 @@ class MediaUploadData {
this.hashData, {
this.height,
this.width,
+ this.cameraMake,
this.cameraModel,
this.motionPhotoStartIndex,
this.isPanorama,
@@ -108,6 +110,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(
String? zipHash;
String fileHash;
Map<String, IfdTag>? exifData;
+ String? cameraMake;
String? cameraModel;
// The timeouts are to safeguard against https://github.com/CaiJingLong/flutter_photo_manager/issues/467
@@ -147,6 +150,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(
if (parseExif) {
exifData = await tryExifFromFile(sourceFile);
if (exifData != null) {
+ cameraMake = _extractPrintableExifValue(exifData['Image Make']);
cameraModel = _extractPrintableExifValue(exifData['Image Model']);
}
}
@@ -211,6 +215,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(
FileHashData(fileHash, zipHash: zipHash),
height: h,
width: w,
+ cameraMake: cameraMake,
cameraModel: cameraModel,
motionPhotoStartIndex: motionPhotoStartingIndex,
exifData: exifData,
@@ -382,6 +387,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAppCache(
File sourceFile;
Uint8List? thumbnailData;
Map<String, IfdTag>? exifData;
+ String? cameraMake;
String? cameraModel;
const bool isDeleted = false;
final localPath = getSharedMediaFilePath(file);
@@ -402,6 +408,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAppCache(
dimensions = await getImageHeightAndWith(imagePath: localPath);
exifData = await tryExifFromFile(sourceFile);
if (exifData != null) {
+ cameraMake = _extractPrintableExifValue(exifData['Image Make']);
cameraModel = _extractPrintableExifValue(exifData['Image Model']);
}
} else if (thumbnailData != null) {
@@ -422,6 +429,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAppCache(
FileHashData(fileHash),
height: dimensions?['height'],
width: dimensions?['width'],
+ cameraMake: cameraMake,
cameraModel: cameraModel,
exifData: exifData,
);
diff --git a/mobile/apps/photos/lib/utils/hierarchical_search_util.dart b/mobile/apps/photos/lib/utils/hierarchical_search_util.dart
index 96e0acf21e..ef5f1081fe 100644
--- a/mobile/apps/photos/lib/utils/hierarchical_search_util.dart
+++ b/mobile/apps/photos/lib/utils/hierarchical_search_util.dart
@@ -357,21 +357,20 @@ List<CameraFilter> _curateCameraFilters(
List<EnteFile> files,
) {
final cameraFilters = <CameraFilter>[];
- final labelToOccurrence = <String, int>{};
+ final modelToOccurrence = <String, int>{};
for (final file in files) {
- final cameraLabel = file.cameraLabel;
- if (cameraLabel == null || cameraLabel.isEmpty) {
+ final cameraModel = file.cameraModel;
+ if (cameraModel == null || cameraModel.isEmpty) {
continue;
}
- labelToOccurrence[cameraLabel] =
- (labelToOccurrence[cameraLabel] ?? 0) + 1;
+ modelToOccurrence[cameraModel] = (modelToOccurrence[cameraModel] ?? 0) + 1;
}
- for (final entry in labelToOccurrence.entries) {
+ for (final entry in modelToOccurrence.entries) {
cameraFilters.add(
CameraFilter(
- cameraLabel: entry.key,
+ cameraModel: entry.key,
occurrence: entry.value,
),
);
diff --git a/web/packages/gallery/services/exif.ts b/web/packages/gallery/services/exif.ts
index 857c437505..f758b738d8 100644
--- a/web/packages/gallery/services/exif.ts
+++ b/web/packages/gallery/services/exif.ts
@@ -47,6 +47,7 @@ export const parseExif = (tags: RawExifTags) => {
if (creationDate) metadata.creationDate = creationDate;
if (location) metadata.location = location;
if (description) metadata.description = description;
+ if (camera?.make) metadata.cameraMake = camera.make;
if (camera?.model) metadata.cameraModel = camera.model;
return metadata;
};
diff --git a/web/packages/gallery/services/upload/upload-service.ts b/web/packages/gallery/services/upload/upload-service.ts
index 9cfae0a99c..30276a71d4 100644
--- a/web/packages/gallery/services/upload/upload-service.ts
+++ b/web/packages/gallery/services/upload/upload-service.ts
@@ -1274,6 +1274,9 @@ const extractImageOrVideoMetadata = async (
publicMagicMetadata.caption = caption;
}
+ if (parsedMetadata?.cameraMake) {
+ publicMagicMetadata.cameraMake = parsedMetadata.cameraMake;
+ }
if (parsedMetadata?.cameraModel) {
publicMagicMetadata.cameraModel = parsedMetadata.cameraModel;
}
diff --git a/web/packages/media/file-metadata.ts b/web/packages/media/file-metadata.ts
index bc0ef2df2b..6990a51a27 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 make (manufacturer) extracted from metadata. */
+ cameraMake?: string;
/** Camera model extracted from metadata. */
cameraModel?: string;
/**
@@ -409,6 +411,7 @@ export const FilePublicMagicMetadataData = z.looseObject({
h: z.number().nullish().transform(nullToUndefined),
caption: z.string().nullish().transform(nullToUndefined),
uploaderName: z.string().nullish().transform(nullToUndefined),
+ cameraMake: z.string().nullish().transform(nullToUndefined),
cameraModel: z.string().nullish().transform(nullToUndefined),
lat: z.number().nullish().transform(nullToUndefined),
long: z.number().nullish().transform(nullToUndefined),
@@ -507,18 +510,38 @@ export const fileLocation = (file: EnteFile): Location | undefined => {
};
/**
- * Return a user-friendly string describing the camera used for the file.
+ * Return the camera make (manufacturer) for the file.
*/
-export const fileCameraLabel = (file: EnteFile): string | undefined => {
- const pubMetadata = file.pubMagicMetadata?.data;
- if (!pubMetadata) return undefined;
- const cameraModel = pubMetadata.cameraModel;
- if (!cameraModel) return undefined;
- const model = cameraModel.trim();
+export const fileCameraMake = (file: EnteFile): string | undefined => {
+ const rawMake = file.pubMagicMetadata?.data.cameraMake;
+ if (!rawMake) return undefined;
+ const make = rawMake.trim();
+ if (make.length === 0) return undefined;
+ return make;
+};
+
+/**
+ * Return the camera model for the file.
+ */
+export const fileCameraModel = (file: EnteFile): string | undefined => {
+ const rawModel = file.pubMagicMetadata?.data.cameraModel;
+ if (!rawModel) return undefined;
+ const model = rawModel.trim();
if (model.length === 0) return undefined;
return model;
};
+/**
+ * Return a user-friendly string describing the camera used for the file.
+ */
+export const fileCameraLabel = (file: EnteFile): string | undefined => {
+ const make = fileCameraMake(file);
+ const model = fileCameraModel(file);
+ if (!make && !model) return undefined;
+ if (make && model) return `${make} ${model}`;
+ return model ?? make;
+};
+
/**
* Return the duration of the video as a formatted "HH:mm:ss" string (when
* present) for the given {@link EnteFile}.
@@ -603,6 +626,8 @@ export interface ParsedMetadata {
* A caption / description attached by the user to the photo.
*/
description?: string;
+ /** Camera make (manufacturer) extracted from metadata (e.g. Apple, Canon). */
+ cameraMake?: 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 6087656c8b..bd2dbae95e 100644
--- a/web/packages/new/photos/components/SearchBar.tsx
+++ b/web/packages/new/photos/components/SearchBar.tsx
@@ -443,7 +443,8 @@ const iconForOption = (option: SearchOption | undefined) => {
return <ImageIcon />;
case "date":
return <CalendarIcon />;
- case "camera":
+ case "cameraMake":
+ case "cameraModel":
return <CameraIcon />;
case "sidebarAction":
return <SettingsIcon />;
@@ -658,8 +659,11 @@ const labelForOption = (option: SearchOption) => {
case "fileCaption":
return t("description");
- case "camera":
- return t("camera", { defaultValue: "Camera" });
+ case "cameraMake":
+ return t("cameraMake", { defaultValue: "Camera Make" });
+
+ case "cameraModel":
+ return t("cameraModel", { defaultValue: "Camera Model" });
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 46f96092ba..c469418ec7 100644
--- a/web/packages/new/photos/services/search/types.ts
+++ b/web/packages/new/photos/services/search/types.ts
@@ -71,7 +71,8 @@ export type SearchSuggestion = { label: string } & (
| { type: "fileType"; fileType: FileType }
| { type: "fileName"; fileIDs: number[] }
| { type: "fileCaption"; fileIDs: number[] }
- | { type: "camera"; fileIDs: number[] }
+ | { type: "cameraMake"; fileIDs: number[] }
+ | { type: "cameraModel"; 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 9598fa1477..831cdc9df3 100644
--- a/web/packages/new/photos/services/search/worker.ts
+++ b/web/packages/new/photos/services/search/worker.ts
@@ -7,7 +7,8 @@ import type { Location } from "ente-base/types";
import type { Collection } from "ente-media/collection";
import type { EnteFile } from "ente-media/file";
import {
- fileCameraLabel,
+ fileCameraMake,
+ fileCameraModel,
fileCreationPhotoDate,
fileFileName,
fileLocation,
@@ -145,7 +146,8 @@ const suggestionsForString = (
collectionSuggestions(re, collections),
fileNameSuggestion(s, re, searchString, files),
fileCaptionSuggestion(re, searchString, files),
- cameraSuggestions(re, searchString, files),
+ cameraMakeSuggestions(re, files),
+ cameraModelSuggestions(re, files),
].flat(),
];
@@ -206,14 +208,13 @@ const fileCaptionSuggestion = (
: [];
};
-const cameraSuggestions = (
+const cameraMakeSuggestions = (
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);
+ const label = fileCameraMake(file);
if (!label || !re.test(label)) continue;
const key = label.toLowerCase();
const existing = matches.get(key);
@@ -225,7 +226,31 @@ const cameraSuggestions = (
}
return Array.from(matches.values()).map(({ label, fileIDs }) => ({
- type: "camera" as const,
+ type: "cameraMake" as const,
+ label,
+ fileIDs,
+ }));
+};
+
+const cameraModelSuggestions = (
+ re: RegExp,
+ files: EnteFile[],
+): SearchSuggestion[] => {
+ const matches = new Map<string, { label: string; fileIDs: number[] }>();
+ for (const file of files) {
+ const label = fileCameraModel(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: "cameraModel" as const,
label,
fileIDs,
}));
@@ -451,7 +476,8 @@ const isMatchingFile = (file: EnteFile, suggestion: SearchSuggestion) => {
return suggestion.fileIDs.includes(file.id);
case "fileCaption":
- case "camera":
+ case "cameraMake":
+ case "cameraModel":
return suggestion.fileIDs.includes(file.id);
case "date":