Skip to content

Commit

Permalink
improvement: date for file that haven't exif data
Browse files Browse the repository at this point in the history
  • Loading branch information
laaqxdze1k committed Sep 6, 2023
1 parent a8ddd36 commit 1e6547a
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 163 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ notes.md
log.txt
idées.md
poc/
list.txt
log.log
*.txt
*.log
debug*.*
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/kr/fs v0.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/sftp v1.13.5 // indirect
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/pkg/sftp v1.13.5 h1:a3RLUqkyjYRtBTZJZ1VRrKbN3zhuPLlUc3sphVz81go=
github.com/pkg/sftp v1.13.5/go.mod h1:wHDZ0IZX6JcBYRK1TH9bcVq8G7TLpVHYIGJRFnmPfxg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd h1:CmH9+J6ZSsIjUK3dcGsnCnO41eRBOnY12zwkn5qVwgc=
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
27 changes: 27 additions & 0 deletions immich/assets/localassets.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path"
"path/filepath"
"strings"
"time"
)

type LocalAssetBrowser struct {
Expand All @@ -25,6 +26,8 @@ func (fsys LocalAssetBrowser) Stat(name string) (fs.FileInfo, error) {
return fs.Stat(fsys.FS, name)
}

var toOldDate = time.Date(1980, 1, 1, 0, 0, 0, 0, time.UTC)

func (fsys LocalAssetBrowser) Browse(ctx context.Context) chan *LocalAssetFile {
fileChan := make(chan *LocalAssetFile)
// Browse all given FS to collect the list of files
Expand Down Expand Up @@ -61,6 +64,14 @@ func (fsys LocalAssetBrowser) Browse(ctx context.Context) chan *LocalAssetFile {
DateTaken: metadata.TakeTimeFromName(filepath.Base(name)),
}

if f.DateTaken.IsZero() {
err = f.ReadMetadataFromFile(name)
_ = err
if f.DateTaken.Before(toOldDate) {
f.DateTaken = time.Now()
}
}

if fsys.albums[path.Dir(name)] != "" {
f.AddAlbum(fsys.albums[path.Dir(name)])
}
Expand Down Expand Up @@ -101,6 +112,22 @@ func (fsys LocalAssetBrowser) Browse(ctx context.Context) chan *LocalAssetFile {
return fileChan
}

func (l *LocalAssetFile) ReadMetadataFromFile(name string) error {
ext := strings.ToLower(path.Ext(l.FileName))

// Open the file
r, err := l.partialSourceReader()

if err != nil {
return err
}
m, err := metadata.GetFromReader(r, ext)
if err == nil {
l.DateTaken = m.DateTaken
}
return err
}

func (fsys LocalAssetBrowser) BrowseAlbums(ctx context.Context) error {
fsys.albums = map[string]string{}
err := fs.WalkDir(fsys, ".",
Expand Down
Loading

0 comments on commit 1e6547a

Please sign in to comment.