Index metadata from RAW and video files

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-06-07 15:49:50 +02:00
parent aeca4b99e9
commit c2b60d340b
3 changed files with 108 additions and 13 deletions

View file

@ -135,7 +135,7 @@ func (c *Convert) ConvertCommand(mf *MediaFile, jpegName string, xmpName string)
// ToJson uses exiftool to export metadata to a json file. // ToJson uses exiftool to export metadata to a json file.
func (c *Convert) ToJson(mf *MediaFile) (*MediaFile, error) { func (c *Convert) ToJson(mf *MediaFile) (*MediaFile, error) {
jsonName := fs.TypeJson.FindFirst(mf.FileName(), []string{c.conf.SidecarPath(), c.conf.OriginalsPath(), fs.HiddenPath}, c.conf.OriginalsPath(), c.conf.Settings().Index.Group) jsonName := fs.TypeJson.FindFirst(mf.FileName(), []string{c.conf.SidecarPath(), fs.HiddenPath}, c.conf.OriginalsPath(), c.conf.Settings().Index.Group)
result, err := NewMediaFile(jsonName) result, err := NewMediaFile(jsonName)

View file

@ -226,11 +226,47 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) (
} }
} }
case m.IsRaw(): case m.IsRaw():
if photo.PhotoType == entity.TypeImage { if metaData := m.MetaData(); metaData.Error == nil {
photo.PhotoType = entity.TypeRaw photo.SetTitle(metaData.Title, entity.SrcMeta)
photo.SetDescription(metaData.Description, entity.SrcMeta)
photo.SetTakenAt(metaData.TakenAt, metaData.TakenAtLocal, metaData.TimeZone, entity.SrcMeta)
photo.SetCoordinates(metaData.Lat, metaData.Lng, metaData.Altitude, entity.SrcMeta)
if photo.Details.NoNotes() {
photo.Details.Notes = metaData.Comment
}
if photo.Details.NoSubject() {
photo.Details.Subject = metaData.Subject
}
if photo.Details.NoKeywords() {
photo.Details.Keywords = metaData.Keywords
}
if photo.Details.NoArtist() && metaData.Artist != "" {
photo.Details.Artist = metaData.Artist
}
if photo.Details.NoArtist() && metaData.CameraOwner != "" {
photo.Details.Artist = metaData.CameraOwner
}
if photo.NoCameraSerial() {
photo.CameraSerial = metaData.CameraSerial
}
if metaData.HasDocumentID() && photo.UUID == "" {
log.Debugf("index: %s has document id %s", quotedName, txt.Quote(metaData.DocumentID))
photo.UUID = metaData.DocumentID
}
if metaData.HasInstanceID() && file.UUID == "" {
log.Debugf("index: %s has instance id %s", quotedName, txt.Quote(metaData.InstanceID))
file.UUID = metaData.InstanceID
} }
case m.IsVideo():
metaData = m.MetaData()
file.FileCodec = metaData.Codec file.FileCodec = metaData.Codec
file.FileWidth = metaData.ActualWidth() file.FileWidth = metaData.ActualWidth()
@ -239,16 +275,75 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) (
file.FileAspectRatio = metaData.AspectRatio() file.FileAspectRatio = metaData.AspectRatio()
file.FilePortrait = metaData.Portrait() file.FilePortrait = metaData.Portrait()
if res := metaData.Megapixels(); res > photo.PhotoResolution {
photo.PhotoResolution = res
}
}
if photo.PhotoType == entity.TypeImage {
photo.PhotoType = entity.TypeRaw
}
case m.IsVideo():
if metaData := m.MetaData(); metaData.Error == nil {
photo.SetTitle(metaData.Title, entity.SrcMeta)
photo.SetDescription(metaData.Description, entity.SrcMeta)
photo.SetTakenAt(metaData.TakenAt, metaData.TakenAtLocal, metaData.TimeZone, entity.SrcMeta)
photo.SetCoordinates(metaData.Lat, metaData.Lng, metaData.Altitude, entity.SrcMeta)
if photo.Details.NoNotes() {
photo.Details.Notes = metaData.Comment
}
if photo.Details.NoSubject() {
photo.Details.Subject = metaData.Subject
}
if photo.Details.NoKeywords() {
photo.Details.Keywords = metaData.Keywords
}
if photo.Details.NoArtist() && metaData.Artist != "" {
photo.Details.Artist = metaData.Artist
}
if photo.Details.NoArtist() && metaData.CameraOwner != "" {
photo.Details.Artist = metaData.CameraOwner
}
if photo.NoCameraSerial() {
photo.CameraSerial = metaData.CameraSerial
}
if metaData.HasDocumentID() && photo.UUID == "" {
log.Debugf("index: %s has document id %s", quotedName, txt.Quote(metaData.DocumentID))
photo.UUID = metaData.DocumentID
}
if metaData.HasInstanceID() && file.UUID == "" {
log.Debugf("index: %s has instance id %s", quotedName, txt.Quote(metaData.InstanceID))
file.UUID = metaData.InstanceID
}
file.FileCodec = metaData.Codec
file.FileWidth = metaData.ActualWidth()
file.FileHeight = metaData.ActualHeight()
file.FileDuration = metaData.Duration
file.FileAspectRatio = metaData.AspectRatio()
file.FilePortrait = metaData.Portrait()
if res := metaData.Megapixels(); res > photo.PhotoResolution {
photo.PhotoResolution = res
}
}
if file.FileDuration == 0 || file.FileDuration > time.Millisecond*3100 { if file.FileDuration == 0 || file.FileDuration > time.Millisecond*3100 {
photo.PhotoType = entity.TypeVideo photo.PhotoType = entity.TypeVideo
} else { } else {
photo.PhotoType = entity.TypeLive photo.PhotoType = entity.TypeLive
} }
if res := metaData.Megapixels(); res > photo.PhotoResolution {
photo.PhotoResolution = res
}
if file.FileWidth == 0 && primaryFile.FileWidth > 0 { if file.FileWidth == 0 && primaryFile.FileWidth > 0 {
file.FileWidth = primaryFile.FileWidth file.FileWidth = primaryFile.FileWidth
file.FileHeight = primaryFile.FileHeight file.FileHeight = primaryFile.FileHeight

View file

@ -20,7 +20,7 @@ func (m *MediaFile) MetaData() (result meta.Data) {
err = errors.New("not a photo") err = errors.New("not a photo")
} }
if jsonFile := fs.TypeJson.FindFirst(m.FileName(), []string{Config().OriginalsPath(), Config().SidecarPath(), fs.HiddenPath}, Config().OriginalsPath(), false); jsonFile == "" { if jsonFile := fs.TypeJson.FindFirst(m.FileName(), []string{Config().SidecarPath(), fs.HiddenPath}, Config().OriginalsPath(), false); jsonFile == "" {
log.Debugf("mediafile: no json sidecar file found for %s", txt.Quote(filepath.Base(m.FileName()))) log.Debugf("mediafile: no json sidecar file found for %s", txt.Quote(filepath.Base(m.FileName())))
} else if jsonErr := m.metaData.JSON(jsonFile, m.BaseName()); jsonErr != nil { } else if jsonErr := m.metaData.JSON(jsonFile, m.BaseName()); jsonErr != nil {
log.Debug(jsonErr) log.Debug(jsonErr)