diff --git a/internal/entity/photo.go b/internal/entity/photo.go index e15361c6f..1c1d27e2f 100644 --- a/internal/entity/photo.go +++ b/internal/entity/photo.go @@ -668,21 +668,24 @@ func (m *Photo) SaveDetails() error { // FileTitle returns a photo title based on the file name and/or path. func (m *Photo) FileTitle() string { + // Generate title based on photo name, if not generated: if !fs.IsGenerated(m.PhotoName) { if title := txt.FileTitle(m.PhotoName); title != "" { return title } } - if m.OriginalName != "" && !fs.IsGenerated(m.OriginalName) { - if title := txt.FileTitle(m.OriginalName); title != "" { + // Generate title based on original file name, if any: + if m.OriginalName != "" { + if title := txt.FileTitle(m.OriginalName); !fs.IsGenerated(m.OriginalName) && title != "" { return title - } else if title := txt.FileTitle(path.Dir(m.OriginalName)); title != "" { + } else if title := txt.FileTitle(filepath.Dir(m.OriginalName)); title != "" { return title } } - if m.PhotoPath != "" { + // Generate title based on photo path, if any: + if m.PhotoPath != "" && !fs.IsGenerated(m.PhotoPath) { return txt.FileTitle(m.PhotoPath) } diff --git a/internal/photoprism/index_mediafile.go b/internal/photoprism/index_mediafile.go index df1097409..3d2dcd556 100644 --- a/internal/photoprism/index_mediafile.go +++ b/internal/photoprism/index_mediafile.go @@ -277,8 +277,8 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) ( file.OriginalName = originalName } - // Set photo original name based on file original name if empty. - if photo.OriginalName == "" && file.OriginalName != "" { + // Set photo original name based on file original name. + if file.OriginalName != "" { photo.OriginalName = fs.StripKnownExt(file.OriginalName) } @@ -682,9 +682,11 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) ( w = append(w, txt.FilenameKeywords(fileBase)...) } - if file.OriginalName != "" && !fs.IsGenerated(file.OriginalName) { - w = append(w, txt.FilenameKeywords(file.OriginalName)...) - } else if photo.OriginalName != "" && !fs.IsGenerated(photo.OriginalName) { + if photo.OriginalName == "" { + // Do nothing. + } else if fs.IsGenerated(photo.OriginalName) { + w = append(w, txt.FilenameKeywords(filepath.Dir(photo.OriginalName))...) + } else { w = append(w, txt.FilenameKeywords(photo.OriginalName)...) }