mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 20:59:03 +00:00
Update external exif parser method
Exiftool meta data parsed as intergers and not strings. Keep internal exif parsing functionality. Signed-off-by: Kjeldgaard <Kjeldgaard@users.noreply.github.com>
This commit is contained in:
@@ -1889,7 +1889,7 @@ type MediaEXIF {
|
||||
"The focal length of the lens, when the image was taken"
|
||||
focalLength: Float
|
||||
"A formatted description of the flash settings, when the image was taken"
|
||||
flash: String
|
||||
flash: Int
|
||||
"An index describing the mode for adjusting the exposure of the image"
|
||||
exposureProgram: Int
|
||||
}
|
||||
@@ -4584,9 +4584,9 @@ func (ec *executionContext) _MediaEXIF_flash(ctx context.Context, field graphql.
|
||||
if resTmp == nil {
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(*string)
|
||||
res := resTmp.(*int64)
|
||||
fc.Result = res
|
||||
return ec.marshalOString2ᚖstring(ctx, field.Selections, res)
|
||||
return ec.marshalOInt2ᚖint64(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _MediaEXIF_exposureProgram(ctx context.Context, field graphql.CollectedField, obj *models.MediaEXIF) (ret graphql.Marshaler) {
|
||||
|
||||
@@ -14,7 +14,7 @@ type MediaEXIF struct {
|
||||
Aperture *float64
|
||||
Iso *int64
|
||||
FocalLength *float64
|
||||
Flash *string
|
||||
Flash *int64
|
||||
Orientation *int64
|
||||
ExposureProgram *int64
|
||||
GPSLatitude *float64
|
||||
|
||||
@@ -312,7 +312,7 @@ type MediaEXIF {
|
||||
"The focal length of the lens, when the image was taken"
|
||||
focalLength: Float
|
||||
"A formatted description of the flash settings, when the image was taken"
|
||||
flash: String
|
||||
flash: Int
|
||||
"An index describing the mode for adjusting the exposure of the image"
|
||||
exposureProgram: Int
|
||||
}
|
||||
|
||||
@@ -14,10 +14,8 @@ type externalExifParser struct{}
|
||||
|
||||
func (p *externalExifParser) ParseExif(media *models.Media) (returnExif *models.MediaEXIF, returnErr error) {
|
||||
// Init ExifTool
|
||||
|
||||
et2 := exiftool.Charset("-n")
|
||||
|
||||
et, err := .NewExiftool(et2)
|
||||
extraInitArgs := []string{"-n"}
|
||||
et, err := exiftool.NewExiftool(exiftool.AddInitArgs(extraInitArgs))
|
||||
if err != nil {
|
||||
log.Printf("Error initializing ExifTool: %s\n", err)
|
||||
return nil, err
|
||||
@@ -99,9 +97,9 @@ func (p *externalExifParser) ParseExif(media *models.Media) (returnExif *models.
|
||||
}
|
||||
|
||||
// Get flash info
|
||||
flash, err := fileInfo.GetString("Flash")
|
||||
flash, err := fileInfo.GetInt("Flash")
|
||||
if err == nil {
|
||||
log.Printf("Flash: %s", flash)
|
||||
log.Printf("Flash: %d", flash)
|
||||
newExif.Flash = &flash
|
||||
}
|
||||
|
||||
@@ -113,71 +111,27 @@ func (p *externalExifParser) ParseExif(media *models.Media) (returnExif *models.
|
||||
}
|
||||
|
||||
// Get exposure program
|
||||
expProgram, err := fileInfo.GetStrings("ExposureProgram")
|
||||
expProgram, err := fileInfo.GetInt("ExposureProgram")
|
||||
if err == nil {
|
||||
for _, value := range expProgram {
|
||||
log.Printf("%s", value)
|
||||
}
|
||||
//log.Printf("Exposure Program: %d", expProgram)
|
||||
log.Printf("Exposure Program: %d", expProgram)
|
||||
newExif.ExposureProgram = &expProgram
|
||||
}
|
||||
|
||||
// GPS coordinates - longitude
|
||||
longitudeRaw, err := fileInfo.GetString("GPSLongitude")
|
||||
longitudeRaw, err := fileInfo.GetFloat("GPSLongitude")
|
||||
if err == nil {
|
||||
log.Printf("GPS longitude: %s", longitudeRaw)
|
||||
value, err := ConvertCoodinateToFloat(longitudeRaw)
|
||||
if err == nil {
|
||||
newExif.GPSLongitude = &value
|
||||
}
|
||||
log.Printf("GPS longitude: %f", longitudeRaw)
|
||||
newExif.GPSLongitude = &longitudeRaw
|
||||
}
|
||||
|
||||
// GPS coordinates - latitude
|
||||
latitudeRaw, err := fileInfo.GetString("GPSLatitude")
|
||||
latitudeRaw, err := fileInfo.GetFloat("GPSLatitude")
|
||||
if err == nil {
|
||||
log.Printf("GPS latitude: %s", latitudeRaw)
|
||||
value, err := ConvertCoodinateToFloat(latitudeRaw)
|
||||
if err == nil {
|
||||
newExif.GPSLatitude = &value
|
||||
}
|
||||
log.Printf("GPS latitude: %f", latitudeRaw)
|
||||
newExif.GPSLatitude = &latitudeRaw
|
||||
}
|
||||
}
|
||||
|
||||
returnExif = &newExif
|
||||
return
|
||||
}
|
||||
|
||||
func ConvertCoodinateToFloat(coordinate string) (value float64, err error) {
|
||||
reg, err := regexp.Compile("[0-9.]+")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
coordinateStr := reg.FindAllString(coordinate, -1)
|
||||
log.Printf("GPS: %s length: %d\n", coordinateStr, len(coordinateStr))
|
||||
if len(coordinateStr) != 3 {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
deg, err := strconv.ParseFloat(coordinateStr[0], 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
minute, err := strconv.ParseFloat(coordinateStr[1], 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
second, err := strconv.ParseFloat(coordinateStr[2], 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var multiplier float64 = 1
|
||||
if deg < 0 {
|
||||
multiplier = -1
|
||||
}
|
||||
|
||||
value = (deg + minute / 60 + second / 3600) * multiplier
|
||||
return value, nil
|
||||
}
|
||||
|
||||
@@ -106,9 +106,10 @@ func (p *internalExifParser) ParseExif(media *models.Media) (returnExif *models.
|
||||
}
|
||||
}
|
||||
|
||||
flash, err := exifTags.Flash()
|
||||
flash, err := p.readIntegerTag(exifTags, exif.Flash, media)
|
||||
if err == nil {
|
||||
newExif.Flash = &flash
|
||||
flash64 := int64(*flash)
|
||||
newExif.Flash = &flash64
|
||||
}
|
||||
|
||||
orientation, err := p.readIntegerTag(exifTags, exif.Orientation, media)
|
||||
|
||||
Reference in New Issue
Block a user