Use date from file name if no metadata was found #396

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-07-13 19:33:58 +02:00
parent 119784ef2c
commit 70c6a68169
6 changed files with 55 additions and 1 deletions

View file

@ -468,7 +468,7 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) (
photo.PhotoExposure = m.Exposure() photo.PhotoExposure = m.Exposure()
} }
if photo.TakenAt.IsZero() || photo.TakenAtLocal.IsZero() { if photo.TakenSrc == entity.SrcAuto {
takenUtc, takenSrc := m.TakenAt() takenUtc, takenSrc := m.TakenAt()
photo.SetTakenAt(takenUtc, takenUtc, "", takenSrc) photo.SetTakenAt(takenUtc, takenUtc, "", takenSrc)
} }

View file

@ -67,7 +67,26 @@ func TestMediaFile_DateCreated(t *testing.T) {
func TestMediaFile_TakenAt(t *testing.T) { func TestMediaFile_TakenAt(t *testing.T) {
conf := config.TestConfig() conf := config.TestConfig()
t.Run("testdata/2018-04-12 19:24:49.gif", func(t *testing.T) {
mediaFile, err := NewMediaFile("testdata/2018-04-12 19:24:49.gif")
if err != nil {
t.Fatal(err)
}
date, src := mediaFile.TakenAt()
assert.Equal(t, "2018-04-12 19:24:49 +0000 UTC", date.String())
assert.Equal(t, entity.SrcName, src)
})
t.Run("testdata/2018-04-12 19:24:49.jpg", func(t *testing.T) {
mediaFile, err := NewMediaFile("testdata/2018-04-12 19:24:49.jpg")
if err != nil {
t.Fatal(err)
}
date, src := mediaFile.TakenAt()
assert.Equal(t, "2018-04-12 19:24:49 +0000 UTC", date.String())
assert.Equal(t, entity.SrcName, src)
})
t.Run("telegram_2020-01-30_09-57-18.jpg", func(t *testing.T) { t.Run("telegram_2020-01-30_09-57-18.jpg", func(t *testing.T) {
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/telegram_2020-01-30_09-57-18.jpg") mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/telegram_2020-01-30_09-57-18.jpg")
if err != nil { if err != nil {

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View file

@ -0,0 +1,29 @@
[{
"SourceFile": "/go/src/github.com/photoprism/photoprism/storage/originals/Debug/2018-04-12 19:24:49.gif",
"ExifToolVersion": 10.80,
"FileName": "2018-04-12 19:24:49.gif",
"Directory": "/go/src/github.com/photoprism/photoprism/storage/originals/Debug",
"FileSize": "4.9 MB",
"FileModifyDate": "2020:07:13 16:41:17+00:00",
"FileAccessDate": "2020:07:13 16:45:39+00:00",
"FileInodeChangeDate": "2020:07:13 16:45:37+00:00",
"FilePermissions": "rw-r--r--",
"FileType": "GIF",
"FileTypeExtension": "gif",
"MIMEType": "image/gif",
"GIFVersion": "89a",
"ImageWidth": 640,
"ImageHeight": 480,
"HasColorMap": "No",
"ColorResolutionDepth": 8,
"BitsPerPixel": 8,
"BackgroundColor": 0,
"AnimationIterations": "Infinite",
"XMPToolkit": "Adobe XMP Core 5.1.0-jc003",
"CameraBurstID": "830cb602-95b4-4c2e-aed3-0ce827b226de",
"Type": "GCameraAnimation",
"FrameCount": 35,
"Duration": "2.25 s",
"ImageSize": "640x480",
"Megapixels": 0.307
}]

View file

@ -13,6 +13,12 @@ func TestTime(t *testing.T) {
assert.Equal(t, "2018-04-12 19:24:49 +0000 UTC", result.String()) assert.Equal(t, "2018-04-12 19:24:49 +0000 UTC", result.String())
}) })
t.Run("2018-04-12 19/24/49.gif", func(t *testing.T) {
result := Time("2018-04-12 19/24/49.gif")
assert.False(t, result.IsZero())
assert.Equal(t, "2018-04-12 19:24:49 +0000 UTC", result.String())
})
t.Run("/2020/1212/20130518_142022_3D657EBD.jpg", func(t *testing.T) { t.Run("/2020/1212/20130518_142022_3D657EBD.jpg", func(t *testing.T) {
result := Time("/2020/1212/20130518_142022_3D657EBD.jpg") result := Time("/2020/1212/20130518_142022_3D657EBD.jpg")
//assert.False(t, result.IsZero()) //assert.False(t, result.IsZero())