2023-09-27 20:44:51 +02:00
|
|
|
import { AssetEntity, AssetType, ExifEntity } from '@app/infra/entities';
|
|
|
|
import { Inject, Injectable, Logger } from '@nestjs/common';
|
2023-09-27 21:17:18 +02:00
|
|
|
import { ExifDateTime, Tags } from 'exiftool-vendored';
|
2023-09-27 20:44:51 +02:00
|
|
|
import { firstDateTime } from 'exiftool-vendored/dist/FirstDateTime';
|
2023-05-26 14:52:52 +02:00
|
|
|
import { constants } from 'fs/promises';
|
2023-09-27 20:44:51 +02:00
|
|
|
import { Duration } from 'luxon';
|
2023-11-01 04:08:21 +01:00
|
|
|
import { Subscription } from 'rxjs';
|
2023-05-26 14:52:52 +02:00
|
|
|
import { usePagination } from '../domain.util';
|
2023-10-09 16:25:03 +02:00
|
|
|
import { IBaseJob, IEntityJob, JOBS_ASSET_PAGINATION_SIZE, JobName, QueueName } from '../job';
|
|
|
|
import {
|
2023-10-19 20:51:56 +02:00
|
|
|
ExifDuration,
|
2023-10-09 16:25:03 +02:00
|
|
|
IAlbumRepository,
|
|
|
|
IAssetRepository,
|
|
|
|
ICryptoRepository,
|
|
|
|
IJobRepository,
|
|
|
|
IMetadataRepository,
|
2023-10-11 04:14:44 +02:00
|
|
|
IMoveRepository,
|
|
|
|
IPersonRepository,
|
2023-10-09 16:25:03 +02:00
|
|
|
IStorageRepository,
|
|
|
|
ISystemConfigRepository,
|
|
|
|
ImmichTags,
|
|
|
|
WithProperty,
|
|
|
|
WithoutProperty,
|
|
|
|
} from '../repositories';
|
2023-10-11 04:14:44 +02:00
|
|
|
import { StorageCore } from '../storage';
|
2023-10-09 16:25:03 +02:00
|
|
|
import { FeatureFlag, SystemConfigCore } from '../system-config';
|
2023-05-26 14:52:52 +02:00
|
|
|
|
2023-11-21 17:58:56 +01:00
|
|
|
/** look for a date from these tags (in order) */
|
|
|
|
const EXIF_DATE_TAGS: Array<keyof Tags> = [
|
|
|
|
'SubSecDateTimeOriginal',
|
|
|
|
'DateTimeOriginal',
|
|
|
|
'SubSecCreateDate',
|
|
|
|
'CreationDate',
|
|
|
|
'CreateDate',
|
|
|
|
'SubSecMediaCreateDate',
|
|
|
|
'MediaCreateDate',
|
|
|
|
'DateTimeCreated',
|
|
|
|
];
|
|
|
|
|
2023-09-27 20:44:51 +02:00
|
|
|
interface DirectoryItem {
|
|
|
|
Length?: number;
|
|
|
|
Mime: string;
|
|
|
|
Padding?: number;
|
|
|
|
Semantic?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface DirectoryEntry {
|
|
|
|
Item: DirectoryItem;
|
|
|
|
}
|
|
|
|
|
2023-09-27 21:17:18 +02:00
|
|
|
type ExifEntityWithoutGeocodeAndTypeOrm = Omit<
|
|
|
|
ExifEntity,
|
|
|
|
'city' | 'state' | 'country' | 'description' | 'exifTextSearchableColumn'
|
2023-11-20 23:26:53 +01:00
|
|
|
> & { dateTimeOriginal: Date };
|
2023-09-27 21:17:18 +02:00
|
|
|
|
2023-09-27 20:44:51 +02:00
|
|
|
const exifDate = (dt: ExifDateTime | string | undefined) => (dt instanceof ExifDateTime ? dt?.toDate() : null);
|
2023-10-05 00:11:11 +02:00
|
|
|
const tzOffset = (dt: ExifDateTime | string | undefined) => (dt instanceof ExifDateTime ? dt?.tzoffsetMinutes : null);
|
2023-09-27 21:17:18 +02:00
|
|
|
|
|
|
|
const validate = <T>(value: T): NonNullable<T> | null => {
|
2023-09-29 17:42:33 +02:00
|
|
|
// handle lists of numbers
|
|
|
|
if (Array.isArray(value)) {
|
|
|
|
value = value[0];
|
|
|
|
}
|
|
|
|
|
2023-09-27 21:17:18 +02:00
|
|
|
if (typeof value === 'string') {
|
|
|
|
// string means a failure to parse a number, throw out result
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof value === 'number' && (isNaN(value) || !isFinite(value))) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value ?? null;
|
|
|
|
};
|
2023-09-27 20:44:51 +02:00
|
|
|
|
|
|
|
@Injectable()
|
2023-05-26 14:52:52 +02:00
|
|
|
export class MetadataService {
|
2023-09-27 20:44:51 +02:00
|
|
|
private logger = new Logger(MetadataService.name);
|
|
|
|
private storageCore: StorageCore;
|
|
|
|
private configCore: SystemConfigCore;
|
|
|
|
private oldCities?: string;
|
2023-11-01 04:08:21 +01:00
|
|
|
private subscription: Subscription | null = null;
|
2023-09-27 20:44:51 +02:00
|
|
|
|
2023-05-26 14:52:52 +02:00
|
|
|
constructor(
|
2023-09-27 20:44:51 +02:00
|
|
|
@Inject(IAlbumRepository) private albumRepository: IAlbumRepository,
|
2023-05-26 14:52:52 +02:00
|
|
|
@Inject(IAssetRepository) private assetRepository: IAssetRepository,
|
2023-09-27 20:44:51 +02:00
|
|
|
@Inject(ICryptoRepository) private cryptoRepository: ICryptoRepository,
|
2023-05-26 14:52:52 +02:00
|
|
|
@Inject(IJobRepository) private jobRepository: IJobRepository,
|
2023-09-27 20:44:51 +02:00
|
|
|
@Inject(IMetadataRepository) private repository: IMetadataRepository,
|
2023-05-26 14:52:52 +02:00
|
|
|
@Inject(IStorageRepository) private storageRepository: IStorageRepository,
|
2023-09-27 20:44:51 +02:00
|
|
|
@Inject(ISystemConfigRepository) configRepository: ISystemConfigRepository,
|
2023-10-11 04:14:44 +02:00
|
|
|
@Inject(IMoveRepository) moveRepository: IMoveRepository,
|
|
|
|
@Inject(IPersonRepository) personRepository: IPersonRepository,
|
2023-09-27 20:44:51 +02:00
|
|
|
) {
|
2023-10-09 02:51:03 +02:00
|
|
|
this.configCore = SystemConfigCore.create(configRepository);
|
2023-10-23 17:52:21 +02:00
|
|
|
this.storageCore = StorageCore.create(assetRepository, moveRepository, personRepository, storageRepository);
|
2023-09-27 20:44:51 +02:00
|
|
|
}
|
|
|
|
|
2023-11-25 19:53:30 +01:00
|
|
|
async init() {
|
2023-11-01 04:08:21 +01:00
|
|
|
if (!this.subscription) {
|
|
|
|
this.subscription = this.configCore.config$.subscribe(() => this.init());
|
|
|
|
}
|
|
|
|
|
2023-09-27 20:44:51 +02:00
|
|
|
const { reverseGeocoding } = await this.configCore.getConfig();
|
2023-11-25 19:53:30 +01:00
|
|
|
const { enabled } = reverseGeocoding;
|
2023-09-27 20:44:51 +02:00
|
|
|
|
2023-11-25 19:53:30 +01:00
|
|
|
if (!enabled) {
|
2023-09-27 20:44:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await this.jobRepository.pause(QueueName.METADATA_EXTRACTION);
|
2023-11-25 19:53:30 +01:00
|
|
|
await this.repository.init();
|
2023-09-27 20:44:51 +02:00
|
|
|
await this.jobRepository.resume(QueueName.METADATA_EXTRACTION);
|
|
|
|
|
2023-11-25 19:53:30 +01:00
|
|
|
this.logger.log(`Initialized local reverse geocoder`);
|
2023-09-27 20:44:51 +02:00
|
|
|
} catch (error: Error | any) {
|
|
|
|
this.logger.error(`Unable to initialize reverse geocoding: ${error}`, error?.stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 00:02:42 +02:00
|
|
|
async teardown() {
|
2023-11-01 04:08:21 +01:00
|
|
|
this.subscription?.unsubscribe();
|
2023-10-19 00:02:42 +02:00
|
|
|
await this.repository.teardown();
|
|
|
|
}
|
|
|
|
|
2023-09-27 20:44:51 +02:00
|
|
|
async handleLivePhotoLinking(job: IEntityJob) {
|
|
|
|
const { id } = job;
|
|
|
|
const [asset] = await this.assetRepository.getByIds([id]);
|
|
|
|
if (!asset?.exifInfo) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!asset.exifInfo.livePhotoCID) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const otherType = asset.type === AssetType.VIDEO ? AssetType.IMAGE : AssetType.VIDEO;
|
|
|
|
const match = await this.assetRepository.findLivePhotoMatch({
|
|
|
|
livePhotoCID: asset.exifInfo.livePhotoCID,
|
|
|
|
ownerId: asset.ownerId,
|
|
|
|
otherAssetId: asset.id,
|
|
|
|
type: otherType,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!match) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const [photoAsset, motionAsset] = asset.type === AssetType.IMAGE ? [asset, match] : [match, asset];
|
|
|
|
|
|
|
|
await this.assetRepository.save({ id: photoAsset.id, livePhotoVideoId: motionAsset.id });
|
|
|
|
await this.assetRepository.save({ id: motionAsset.id, isVisible: false });
|
|
|
|
await this.albumRepository.removeAsset(motionAsset.id);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleQueueMetadataExtraction(job: IBaseJob) {
|
|
|
|
const { force } = job;
|
|
|
|
const assetPagination = usePagination(JOBS_ASSET_PAGINATION_SIZE, (pagination) => {
|
|
|
|
return force
|
|
|
|
? this.assetRepository.getAll(pagination)
|
|
|
|
: this.assetRepository.getWithout(pagination, WithoutProperty.EXIF);
|
|
|
|
});
|
|
|
|
|
|
|
|
for await (const assets of assetPagination) {
|
|
|
|
for (const asset of assets) {
|
|
|
|
await this.jobRepository.queue({ name: JobName.METADATA_EXTRACTION, data: { id: asset.id } });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleMetadataExtraction({ id }: IEntityJob) {
|
|
|
|
const [asset] = await this.assetRepository.getByIds([id]);
|
|
|
|
if (!asset || !asset.isVisible) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { exifData, tags } = await this.exifData(asset);
|
|
|
|
|
|
|
|
await this.applyMotionPhotos(asset, tags);
|
|
|
|
await this.applyReverseGeocoding(asset, exifData);
|
|
|
|
await this.assetRepository.upsertExif(exifData);
|
2023-10-05 00:11:11 +02:00
|
|
|
|
2023-11-20 23:26:53 +01:00
|
|
|
const dateTimeOriginal = exifData.dateTimeOriginal;
|
2023-10-06 14:12:09 +02:00
|
|
|
let localDateTime = dateTimeOriginal ?? undefined;
|
|
|
|
|
2023-10-05 00:11:11 +02:00
|
|
|
const timeZoneOffset = tzOffset(firstDateTime(tags as Tags)) ?? 0;
|
|
|
|
|
|
|
|
if (dateTimeOriginal && timeZoneOffset) {
|
|
|
|
localDateTime = new Date(dateTimeOriginal.getTime() + timeZoneOffset * 60000);
|
|
|
|
}
|
2023-09-27 20:44:51 +02:00
|
|
|
await this.assetRepository.save({
|
|
|
|
id: asset.id,
|
|
|
|
duration: tags.Duration ? this.getDuration(tags.Duration) : null,
|
2023-10-05 00:11:11 +02:00
|
|
|
localDateTime,
|
2023-09-27 20:44:51 +02:00
|
|
|
fileCreatedAt: exifData.dateTimeOriginal ?? undefined,
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2023-05-26 14:52:52 +02:00
|
|
|
|
|
|
|
async handleQueueSidecar(job: IBaseJob) {
|
2023-05-26 21:43:24 +02:00
|
|
|
const { force } = job;
|
|
|
|
const assetPagination = usePagination(JOBS_ASSET_PAGINATION_SIZE, (pagination) => {
|
|
|
|
return force
|
|
|
|
? this.assetRepository.getWith(pagination, WithProperty.SIDECAR)
|
|
|
|
: this.assetRepository.getWithout(pagination, WithoutProperty.SIDECAR);
|
|
|
|
});
|
|
|
|
|
|
|
|
for await (const assets of assetPagination) {
|
|
|
|
for (const asset of assets) {
|
|
|
|
const name = force ? JobName.SIDECAR_SYNC : JobName.SIDECAR_DISCOVERY;
|
|
|
|
await this.jobRepository.queue({ name, data: { id: asset.id } });
|
2023-05-26 14:52:52 +02:00
|
|
|
}
|
|
|
|
}
|
2023-05-26 21:43:24 +02:00
|
|
|
|
|
|
|
return true;
|
2023-05-26 14:52:52 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 21:43:24 +02:00
|
|
|
async handleSidecarSync() {
|
|
|
|
// TODO: optimize to only queue assets with recent xmp changes
|
|
|
|
return true;
|
|
|
|
}
|
2023-05-26 14:52:52 +02:00
|
|
|
|
2023-05-26 21:43:24 +02:00
|
|
|
async handleSidecarDiscovery({ id }: IEntityJob) {
|
|
|
|
const [asset] = await this.assetRepository.getByIds([id]);
|
|
|
|
if (!asset || !asset.isVisible || asset.sidecarPath) {
|
|
|
|
return false;
|
2023-05-26 14:52:52 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 21:43:24 +02:00
|
|
|
const sidecarPath = `${asset.originalPath}.xmp`;
|
2023-06-30 18:25:08 +02:00
|
|
|
const exists = await this.storageRepository.checkFileExists(sidecarPath, constants.R_OK);
|
2023-05-26 21:43:24 +02:00
|
|
|
if (!exists) {
|
|
|
|
return false;
|
2023-05-26 14:52:52 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 21:43:24 +02:00
|
|
|
await this.assetRepository.save({ id: asset.id, sidecarPath });
|
2023-05-26 14:52:52 +02:00
|
|
|
|
2023-05-26 21:43:24 +02:00
|
|
|
return true;
|
2023-05-26 14:52:52 +02:00
|
|
|
}
|
2023-09-27 20:44:51 +02:00
|
|
|
|
2023-09-27 21:17:18 +02:00
|
|
|
private async applyReverseGeocoding(asset: AssetEntity, exifData: ExifEntityWithoutGeocodeAndTypeOrm) {
|
2023-09-27 20:44:51 +02:00
|
|
|
const { latitude, longitude } = exifData;
|
|
|
|
if (!(await this.configCore.hasFeature(FeatureFlag.REVERSE_GEOCODING)) || !longitude || !latitude) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2023-11-25 19:53:30 +01:00
|
|
|
const reverseGeocode = await this.repository.reverseGeocode({ latitude, longitude });
|
2023-11-28 21:09:20 +01:00
|
|
|
if (!reverseGeocode) {
|
|
|
|
return;
|
|
|
|
}
|
2023-11-25 19:53:30 +01:00
|
|
|
Object.assign(exifData, reverseGeocode);
|
2023-09-27 20:44:51 +02:00
|
|
|
} catch (error: Error | any) {
|
|
|
|
this.logger.warn(
|
|
|
|
`Unable to run reverse geocoding due to ${error} for asset ${asset.id} at ${asset.originalPath}`,
|
|
|
|
error?.stack,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async applyMotionPhotos(asset: AssetEntity, tags: ImmichTags) {
|
|
|
|
if (asset.type !== AssetType.IMAGE || asset.livePhotoVideoId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const rawDirectory = tags.Directory;
|
|
|
|
const isMotionPhoto = tags.MotionPhoto;
|
|
|
|
const isMicroVideo = tags.MicroVideo;
|
|
|
|
const videoOffset = tags.MicroVideoOffset;
|
|
|
|
const directory = Array.isArray(rawDirectory) ? (rawDirectory as DirectoryEntry[]) : null;
|
|
|
|
|
|
|
|
let length = 0;
|
|
|
|
let padding = 0;
|
|
|
|
|
|
|
|
if (isMotionPhoto && directory) {
|
|
|
|
for (const entry of directory) {
|
|
|
|
if (entry.Item.Semantic == 'MotionPhoto') {
|
|
|
|
length = entry.Item.Length ?? 0;
|
|
|
|
padding = entry.Item.Padding ?? 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isMicroVideo && typeof videoOffset === 'number') {
|
|
|
|
length = videoOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.logger.debug(`Starting motion photo video extraction (${asset.id})`);
|
|
|
|
|
|
|
|
try {
|
|
|
|
const stat = await this.storageRepository.stat(asset.originalPath);
|
|
|
|
const position = stat.size - length - padding;
|
|
|
|
const video = await this.storageRepository.readFile(asset.originalPath, {
|
|
|
|
buffer: Buffer.alloc(length),
|
|
|
|
position,
|
|
|
|
length,
|
|
|
|
});
|
2023-09-29 23:25:45 +02:00
|
|
|
const checksum = this.cryptoRepository.hashSha1(video);
|
2023-09-27 20:44:51 +02:00
|
|
|
|
2023-10-23 17:52:21 +02:00
|
|
|
const motionPath = StorageCore.getAndroidMotionPath(asset);
|
2023-10-14 19:12:59 +02:00
|
|
|
this.storageCore.ensureFolders(motionPath);
|
|
|
|
|
2023-09-27 20:44:51 +02:00
|
|
|
let motionAsset = await this.assetRepository.getByChecksum(asset.ownerId, checksum);
|
|
|
|
if (!motionAsset) {
|
2023-10-05 00:11:11 +02:00
|
|
|
const createdAt = asset.fileCreatedAt ?? asset.createdAt;
|
|
|
|
motionAsset = await this.assetRepository.create({
|
2023-09-27 20:44:51 +02:00
|
|
|
libraryId: asset.libraryId,
|
|
|
|
type: AssetType.VIDEO,
|
2023-10-05 00:11:11 +02:00
|
|
|
fileCreatedAt: createdAt,
|
2023-09-27 20:44:51 +02:00
|
|
|
fileModifiedAt: asset.fileModifiedAt,
|
2023-10-05 00:11:11 +02:00
|
|
|
localDateTime: createdAt,
|
2023-09-27 20:44:51 +02:00
|
|
|
checksum,
|
|
|
|
ownerId: asset.ownerId,
|
2023-10-14 19:12:59 +02:00
|
|
|
originalPath: motionPath,
|
2023-09-27 20:44:51 +02:00
|
|
|
originalFileName: asset.originalFileName,
|
|
|
|
isVisible: false,
|
2023-10-09 03:36:02 +02:00
|
|
|
isReadOnly: false,
|
2023-09-27 20:44:51 +02:00
|
|
|
deviceAssetId: 'NONE',
|
|
|
|
deviceId: 'NONE',
|
|
|
|
});
|
|
|
|
|
2023-09-27 22:27:08 +02:00
|
|
|
await this.storageRepository.writeFile(motionAsset.originalPath, video);
|
2023-09-27 20:44:51 +02:00
|
|
|
await this.jobRepository.queue({ name: JobName.METADATA_EXTRACTION, data: { id: motionAsset.id } });
|
|
|
|
}
|
|
|
|
|
|
|
|
await this.assetRepository.save({ id: asset.id, livePhotoVideoId: motionAsset.id });
|
|
|
|
|
|
|
|
this.logger.debug(`Finished motion photo video extraction (${asset.id})`);
|
|
|
|
} catch (error: Error | any) {
|
|
|
|
this.logger.error(`Failed to extract live photo ${asset.originalPath}: ${error}`, error?.stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-27 21:17:18 +02:00
|
|
|
private async exifData(
|
|
|
|
asset: AssetEntity,
|
|
|
|
): Promise<{ exifData: ExifEntityWithoutGeocodeAndTypeOrm; tags: ImmichTags }> {
|
2023-09-27 20:44:51 +02:00
|
|
|
const stats = await this.storageRepository.stat(asset.originalPath);
|
|
|
|
const mediaTags = await this.repository.getExifTags(asset.originalPath);
|
|
|
|
const sidecarTags = asset.sidecarPath ? await this.repository.getExifTags(asset.sidecarPath) : null;
|
2023-11-21 17:58:56 +01:00
|
|
|
|
|
|
|
// ensure date from sidecar is used if present
|
|
|
|
const hasDateOverride = !!this.getDateTimeOriginal(sidecarTags);
|
|
|
|
if (mediaTags && hasDateOverride) {
|
|
|
|
for (const tag of EXIF_DATE_TAGS) {
|
|
|
|
delete mediaTags[tag];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-27 20:44:51 +02:00
|
|
|
const tags = { ...mediaTags, ...sidecarTags };
|
|
|
|
|
|
|
|
this.logger.verbose('Exif Tags', tags);
|
|
|
|
|
|
|
|
return {
|
2023-09-27 21:17:18 +02:00
|
|
|
exifData: {
|
2023-09-27 20:44:51 +02:00
|
|
|
// altitude: tags.GPSAltitude ?? null,
|
|
|
|
assetId: asset.id,
|
|
|
|
bitsPerSample: this.getBitsPerSample(tags),
|
|
|
|
colorspace: tags.ColorSpace ?? null,
|
2023-11-21 17:58:56 +01:00
|
|
|
dateTimeOriginal: this.getDateTimeOriginal(tags) ?? asset.fileCreatedAt,
|
2023-09-27 20:44:51 +02:00
|
|
|
exifImageHeight: validate(tags.ImageHeight),
|
|
|
|
exifImageWidth: validate(tags.ImageWidth),
|
|
|
|
exposureTime: tags.ExposureTime ?? null,
|
|
|
|
fileSizeInByte: stats.size,
|
|
|
|
fNumber: validate(tags.FNumber),
|
|
|
|
focalLength: validate(tags.FocalLength),
|
|
|
|
fps: validate(tags.VideoFrameRate),
|
|
|
|
iso: validate(tags.ISO),
|
|
|
|
latitude: validate(tags.GPSLatitude),
|
|
|
|
lensModel: tags.LensModel ?? null,
|
2023-09-27 22:32:58 +02:00
|
|
|
livePhotoCID: (tags.ContentIdentifier || tags.MediaGroupUUID) ?? null,
|
2023-09-27 20:44:51 +02:00
|
|
|
longitude: validate(tags.GPSLongitude),
|
|
|
|
make: tags.Make ?? null,
|
|
|
|
model: tags.Model ?? null,
|
|
|
|
modifyDate: exifDate(tags.ModifyDate) ?? asset.fileModifiedAt,
|
|
|
|
orientation: validate(tags.Orientation)?.toString() ?? null,
|
|
|
|
profileDescription: tags.ProfileDescription || tags.ProfileName || null,
|
|
|
|
projectionType: tags.ProjectionType ? String(tags.ProjectionType).toUpperCase() : null,
|
2023-09-27 21:17:18 +02:00
|
|
|
timeZone: tags.tz ?? null,
|
2023-09-27 20:44:51 +02:00
|
|
|
},
|
|
|
|
tags,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-11-21 17:58:56 +01:00
|
|
|
private getDateTimeOriginal(tags: ImmichTags | Tags | null) {
|
|
|
|
if (!tags) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return exifDate(firstDateTime(tags as Tags, EXIF_DATE_TAGS));
|
|
|
|
}
|
|
|
|
|
2023-09-27 20:44:51 +02:00
|
|
|
private getBitsPerSample(tags: ImmichTags): number | null {
|
|
|
|
const bitDepthTags = [
|
|
|
|
tags.BitsPerSample,
|
|
|
|
tags.ComponentBitDepth,
|
|
|
|
tags.ImagePixelDepth,
|
|
|
|
tags.BitDepth,
|
|
|
|
tags.ColorBitDepth,
|
|
|
|
// `numericTags` doesn't parse values like '12 12 12'
|
|
|
|
].map((tag) => (typeof tag === 'string' ? Number.parseInt(tag) : tag));
|
|
|
|
|
|
|
|
let bitsPerSample = bitDepthTags.find((tag) => typeof tag === 'number' && !Number.isNaN(tag)) ?? null;
|
|
|
|
if (bitsPerSample && bitsPerSample >= 24 && bitsPerSample % 3 === 0) {
|
|
|
|
bitsPerSample /= 3; // converts per-pixel bit depth to per-channel
|
|
|
|
}
|
|
|
|
|
|
|
|
return bitsPerSample;
|
|
|
|
}
|
|
|
|
|
2023-10-19 20:51:56 +02:00
|
|
|
private getDuration(seconds?: number | ExifDuration): string {
|
|
|
|
let _seconds = seconds as number;
|
|
|
|
if (typeof seconds === 'object') {
|
|
|
|
_seconds = seconds.Value * (seconds?.Scale || 1);
|
|
|
|
}
|
|
|
|
return Duration.fromObject({ seconds: _seconds }).toFormat('hh:mm:ss.SSS');
|
2023-09-27 20:44:51 +02:00
|
|
|
}
|
2023-05-26 14:52:52 +02:00
|
|
|
}
|