diff --git a/src/backend/model/database/enitites/MediaEntity.ts b/src/backend/model/database/enitites/MediaEntity.ts index 1cb9c3ac..60db29e5 100644 --- a/src/backend/model/database/enitites/MediaEntity.ts +++ b/src/backend/model/database/enitites/MediaEntity.ts @@ -134,7 +134,7 @@ export class MediaMetadataEntity implements MediaMetadata { @Column('tinyint', {unsigned: false}) @Index() - rating: -1 | 0 | 1 | 2 | 3 | 4 | 5; + rating: 0 | 1 | 2 | 3 | 4 | 5; @OneToMany(() => PersonJunctionTable, (junctionTable) => junctionTable.media) personJunction: PersonJunctionTable[]; diff --git a/src/backend/model/fileaccess/MetadataLoader.ts b/src/backend/model/fileaccess/MetadataLoader.ts index bce339f2..79abbbf2 100644 --- a/src/backend/model/fileaccess/MetadataLoader.ts +++ b/src/backend/model/fileaccess/MetadataLoader.ts @@ -3,6 +3,7 @@ import { imageSize } from 'image-size'; import { Config } from '../../../common/config/private/Config'; import { FaceRegion, PhotoMetadata } from '../../../common/entities/PhotoDTO'; import { VideoMetadata } from '../../../common/entities/VideoDTO'; +import { RatingTypes } from '../../../common/entities/MediaDTO'; import { Logger } from '../../Logger'; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore @@ -513,17 +514,17 @@ export class MetadataLoader { private static mapRating(metadata: PhotoMetadata, exif: any) { if (exif.xmp && exif.xmp.Rating !== undefined) { - metadata.rating = exif.xmp.Rating; - } - if (metadata.rating !== undefined) { - if (metadata.rating < -1) { //Rating -1 means "rejected" according to adobe's spec - metadata.rating = -1; - } else if (metadata.rating > 5) { + const rting = Math.round(exif.xmp.Rating); + if (rting < 0) { + //We map all ratings below 0 to 0. Lightroom supports value -1, but most other tools (including this) don't. + //Rating 0 means "unrated" according to adobe's spec, so we delete the attribute in pigallery for the same effect + delete metadata.rating; + } else if (rting > 5) { //map all ratings above 5 to 5 metadata.rating = 5; + } else { + metadata.rating = (rting as RatingTypes); } - } //else { - //metadata.rating = 0; //Rating 0 means "unrated" according to adobe's spec - //} + } } private static mapFaces(metadata: PhotoMetadata, exif: any, orientation: number) { diff --git a/src/common/entities/MediaDTO.ts b/src/common/entities/MediaDTO.ts index 5be288a4..92807a39 100644 --- a/src/common/entities/MediaDTO.ts +++ b/src/common/entities/MediaDTO.ts @@ -11,7 +11,7 @@ export interface MediaDTO extends FileDTO { missingThumbnails?: number; } -export type RatingTypes = -1 | 0 | 1 | 2 | 3 | 4 | 5; +export type RatingTypes = 0 | 1 | 2 | 3 | 4 | 5; export interface MediaMetadata { size: MediaDimension; diff --git a/test/backend/assets/Chars.json b/test/backend/assets/Chars.json index 03352e6c..1327364e 100644 --- a/test/backend/assets/Chars.json +++ b/test/backend/assets/Chars.json @@ -17,7 +17,6 @@ }, "keywords": [ ], - "rating": -1, "faces": [ { "box": { diff --git a/test/backend/assets/Chars_exiftool.json b/test/backend/assets/Chars_exiftool.json index 7f57c2f2..19a39345 100644 --- a/test/backend/assets/Chars_exiftool.json +++ b/test/backend/assets/Chars_exiftool.json @@ -16,7 +16,6 @@ }, "keywords": [ ], - "rating": -1, "faces": [ { "box": { diff --git a/test/backend/assets/sidecar/Chars.json b/test/backend/assets/sidecar/Chars.json index b30a3ded..1afd9d01 100644 --- a/test/backend/assets/sidecar/Chars.json +++ b/test/backend/assets/sidecar/Chars.json @@ -17,7 +17,6 @@ }, "keywords": [ ], - "rating": -1, "faces": [ { "box": { diff --git a/test/backend/assets/sidecar/Chars_exiftool.json b/test/backend/assets/sidecar/Chars_exiftool.json index febff88f..5cd41a2a 100644 --- a/test/backend/assets/sidecar/Chars_exiftool.json +++ b/test/backend/assets/sidecar/Chars_exiftool.json @@ -17,7 +17,6 @@ }, "keywords": [ ], - "rating": -1, "faces": [ { "box": {