Index metadata from RAW and video files
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
aeca4b99e9
commit
c2b60d340b
3 changed files with 108 additions and 13 deletions
|
@ -135,7 +135,7 @@ func (c *Convert) ConvertCommand(mf *MediaFile, jpegName string, xmpName string)
|
|||
|
||||
// ToJson uses exiftool to export metadata to a json file.
|
||||
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)
|
||||
|
||||
|
|
|
@ -226,18 +226,117 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) (
|
|||
}
|
||||
}
|
||||
case m.IsRaw():
|
||||
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 photo.PhotoType == entity.TypeImage {
|
||||
photo.PhotoType = entity.TypeRaw
|
||||
}
|
||||
case m.IsVideo():
|
||||
metaData = m.MetaData()
|
||||
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)
|
||||
|
||||
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 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 {
|
||||
photo.PhotoType = entity.TypeVideo
|
||||
|
@ -245,10 +344,6 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) (
|
|||
photo.PhotoType = entity.TypeLive
|
||||
}
|
||||
|
||||
if res := metaData.Megapixels(); res > photo.PhotoResolution {
|
||||
photo.PhotoResolution = res
|
||||
}
|
||||
|
||||
if file.FileWidth == 0 && primaryFile.FileWidth > 0 {
|
||||
file.FileWidth = primaryFile.FileWidth
|
||||
file.FileHeight = primaryFile.FileHeight
|
||||
|
|
|
@ -20,7 +20,7 @@ func (m *MediaFile) MetaData() (result meta.Data) {
|
|||
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())))
|
||||
} else if jsonErr := m.metaData.JSON(jsonFile, m.BaseName()); jsonErr != nil {
|
||||
log.Debug(jsonErr)
|
||||
|
|
Loading…
Reference in a new issue