1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-07-17 01:32:29 +02:00

xmp-rating valid values now 1-5. 0 means "unrated" and the attribute does not exist with value 0

This commit is contained in:
gras
2024-03-30 21:07:41 +01:00
parent 77982e6c10
commit b071b6daae
7 changed files with 12 additions and 15 deletions

View File

@ -134,7 +134,7 @@ export class MediaMetadataEntity implements MediaMetadata {
@Column('tinyint', {unsigned: false}) @Column('tinyint', {unsigned: false})
@Index() @Index()
rating: -1 | 0 | 1 | 2 | 3 | 4 | 5; rating: 0 | 1 | 2 | 3 | 4 | 5;
@OneToMany(() => PersonJunctionTable, (junctionTable) => junctionTable.media) @OneToMany(() => PersonJunctionTable, (junctionTable) => junctionTable.media)
personJunction: PersonJunctionTable[]; personJunction: PersonJunctionTable[];

View File

@ -3,6 +3,7 @@ import { imageSize } from 'image-size';
import { Config } from '../../../common/config/private/Config'; import { Config } from '../../../common/config/private/Config';
import { FaceRegion, PhotoMetadata } from '../../../common/entities/PhotoDTO'; import { FaceRegion, PhotoMetadata } from '../../../common/entities/PhotoDTO';
import { VideoMetadata } from '../../../common/entities/VideoDTO'; import { VideoMetadata } from '../../../common/entities/VideoDTO';
import { RatingTypes } from '../../../common/entities/MediaDTO';
import { Logger } from '../../Logger'; import { Logger } from '../../Logger';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
@ -513,17 +514,17 @@ export class MetadataLoader {
private static mapRating(metadata: PhotoMetadata, exif: any) { private static mapRating(metadata: PhotoMetadata, exif: any) {
if (exif.xmp && if (exif.xmp &&
exif.xmp.Rating !== undefined) { exif.xmp.Rating !== undefined) {
metadata.rating = exif.xmp.Rating; const rting = Math.round(exif.xmp.Rating);
} if (rting < 0) {
if (metadata.rating !== undefined) { //We map all ratings below 0 to 0. Lightroom supports value -1, but most other tools (including this) don't.
if (metadata.rating < -1) { //Rating -1 means "rejected" according to adobe's spec //Rating 0 means "unrated" according to adobe's spec, so we delete the attribute in pigallery for the same effect
metadata.rating = -1; delete metadata.rating;
} else if (metadata.rating > 5) { } else if (rting > 5) { //map all ratings above 5 to 5
metadata.rating = 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) { private static mapFaces(metadata: PhotoMetadata, exif: any, orientation: number) {

View File

@ -11,7 +11,7 @@ export interface MediaDTO extends FileDTO {
missingThumbnails?: number; missingThumbnails?: number;
} }
export type RatingTypes = -1 | 0 | 1 | 2 | 3 | 4 | 5; export type RatingTypes = 0 | 1 | 2 | 3 | 4 | 5;
export interface MediaMetadata { export interface MediaMetadata {
size: MediaDimension; size: MediaDimension;

View File

@ -17,7 +17,6 @@
}, },
"keywords": [ "keywords": [
], ],
"rating": -1,
"faces": [ "faces": [
{ {
"box": { "box": {

View File

@ -16,7 +16,6 @@
}, },
"keywords": [ "keywords": [
], ],
"rating": -1,
"faces": [ "faces": [
{ {
"box": { "box": {

View File

@ -17,7 +17,6 @@
}, },
"keywords": [ "keywords": [
], ],
"rating": -1,
"faces": [ "faces": [
{ {
"box": { "box": {

View File

@ -17,7 +17,6 @@
}, },
"keywords": [ "keywords": [
], ],
"rating": -1,
"faces": [ "faces": [
{ {
"box": { "box": {