2023-03-04 00:38:30 +02:00
|
|
|
import 'package:isar/isar.dart';
|
2023-02-04 22:42:42 +02:00
|
|
|
import 'package:openapi/api.dart';
|
|
|
|
import 'package:immich_mobile/utils/builtin_extensions.dart';
|
|
|
|
|
2023-03-04 00:38:30 +02:00
|
|
|
part 'exif_info.g.dart';
|
|
|
|
|
|
|
|
/// Exif information 1:1 relation with Asset
|
|
|
|
@Collection(inheritance: false)
|
2023-02-04 22:42:42 +02:00
|
|
|
class ExifInfo {
|
2023-03-04 00:38:30 +02:00
|
|
|
Id? id;
|
2023-02-04 22:42:42 +02:00
|
|
|
int? fileSize;
|
|
|
|
String? make;
|
|
|
|
String? model;
|
2023-03-04 00:38:30 +02:00
|
|
|
String? lens;
|
|
|
|
float? f;
|
|
|
|
float? mm;
|
|
|
|
short? iso;
|
|
|
|
float? exposureSeconds;
|
|
|
|
float? lat;
|
|
|
|
float? long;
|
2023-02-04 22:42:42 +02:00
|
|
|
String? city;
|
|
|
|
String? state;
|
|
|
|
String? country;
|
|
|
|
|
2023-03-04 00:38:30 +02:00
|
|
|
@ignore
|
|
|
|
String get exposureTime {
|
|
|
|
if (exposureSeconds == null) {
|
|
|
|
return "";
|
|
|
|
} else if (exposureSeconds! < 1) {
|
|
|
|
return "1/${(1.0 / exposureSeconds!).round()} s";
|
|
|
|
} else {
|
|
|
|
return "${exposureSeconds!.toStringAsFixed(1)} s";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ignore
|
|
|
|
String get fNumber => f != null ? f!.toStringAsFixed(1) : "";
|
|
|
|
|
|
|
|
@ignore
|
|
|
|
String get focalLength => mm != null ? mm!.toStringAsFixed(1) : "";
|
|
|
|
|
|
|
|
@ignore
|
|
|
|
double? get latitude => lat;
|
|
|
|
|
|
|
|
@ignore
|
|
|
|
double? get longitude => long;
|
|
|
|
|
2023-02-04 22:42:42 +02:00
|
|
|
ExifInfo.fromDto(ExifResponseDto dto)
|
|
|
|
: fileSize = dto.fileSizeInByte,
|
|
|
|
make = dto.make,
|
|
|
|
model = dto.model,
|
2023-03-04 00:38:30 +02:00
|
|
|
lens = dto.lensModel,
|
|
|
|
f = dto.fNumber?.toDouble(),
|
|
|
|
mm = dto.focalLength?.toDouble(),
|
2023-02-04 22:42:42 +02:00
|
|
|
iso = dto.iso?.toInt(),
|
2023-03-04 00:38:30 +02:00
|
|
|
exposureSeconds = _exposureTimeToSeconds(dto.exposureTime),
|
|
|
|
lat = dto.latitude?.toDouble(),
|
|
|
|
long = dto.longitude?.toDouble(),
|
2023-02-04 22:42:42 +02:00
|
|
|
city = dto.city,
|
|
|
|
state = dto.state,
|
|
|
|
country = dto.country;
|
|
|
|
|
2023-03-04 00:38:30 +02:00
|
|
|
ExifInfo({
|
2023-02-04 22:42:42 +02:00
|
|
|
this.fileSize,
|
|
|
|
this.make,
|
|
|
|
this.model,
|
2023-03-04 00:38:30 +02:00
|
|
|
this.lens,
|
|
|
|
this.f,
|
|
|
|
this.mm,
|
2023-02-04 22:42:42 +02:00
|
|
|
this.iso,
|
2023-03-04 00:38:30 +02:00
|
|
|
this.exposureSeconds,
|
|
|
|
this.lat,
|
|
|
|
this.long,
|
2023-02-04 22:42:42 +02:00
|
|
|
this.city,
|
|
|
|
this.state,
|
|
|
|
this.country,
|
2023-03-04 00:38:30 +02:00
|
|
|
});
|
|
|
|
}
|
2023-02-04 22:42:42 +02:00
|
|
|
|
2023-03-04 00:38:30 +02:00
|
|
|
double? _exposureTimeToSeconds(String? s) {
|
|
|
|
if (s == null) {
|
2023-02-04 22:42:42 +02:00
|
|
|
return null;
|
|
|
|
}
|
2023-03-04 00:38:30 +02:00
|
|
|
double? value = double.tryParse(s);
|
|
|
|
if (value != null) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
final parts = s.split("/");
|
|
|
|
if (parts.length == 2) {
|
|
|
|
return parts[0].toDouble() / parts[1].toDouble();
|
|
|
|
}
|
|
|
|
return null;
|
2023-02-04 22:42:42 +02:00
|
|
|
}
|