Skip to content

Commit

Permalink
Burst images not being stacked
Browse files Browse the repository at this point in the history
Fixes #345
  • Loading branch information
simulot committed Nov 1, 2024
1 parent 9d2c13a commit c44642b
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/filenames/infoCollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type nameMatcher func(name string) (bool, NameInfo)

// GetInfo analyze the name and return the information extracted from the name
func (ic InfoCollector) GetInfo(name string) NameInfo {
for _, m := range []nameMatcher{ic.Pixel, ic.Samsung, ic.Nexus, ic.Huawei} {
for _, m := range []nameMatcher{ic.Pixel, ic.Samsung, ic.Nexus, ic.Huawei, ic.SonyXperia} {
if ok, i := m(name); ok {
return i
}
Expand Down
15 changes: 15 additions & 0 deletions internal/filenames/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ func TestGetInfo(t *testing.T) {
Taken: time.Date(2017, 11, 11, 3, 1, 28, 0, time.Local),
},
},
{
name: "Sony Xperia",
filename: "DSC_0002_BURST20230709220904977.JPG",
expected: true,
info: NameInfo{
Radical: "BURST20230709220904977",
Base: "DSC_0002_BURST20230709220904977.JPG",
IsCover: false,
Ext: ".JPG",
Type: metadata.TypeImage,
Kind: KindBurst,
Index: 2,
Taken: time.Date(2023, 7, 9, 22, 9, 4, int(977*time.Millisecond), time.Local),
},
},
{
name: "InvalidFilename",
filename: "IMG_1123.jpg",
Expand Down
30 changes: 30 additions & 0 deletions internal/filenames/sony_xperia.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package filenames

import (
"regexp"
"strconv"
"strings"
"time"
)

var sonyXperiaRE = regexp.MustCompile(`^DSC_(\d+)_BURST(\d+)(\D+)?(\..+)$`)

func (ic InfoCollector) SonyXperia(name string) (bool, NameInfo) {
parts := sonyXperiaRE.FindStringSubmatch(name)
if len(parts) == 0 {
return false, NameInfo{}
}
ext := parts[4]
info := NameInfo{
Radical: "BURST" + parts[2],
Base: name,
IsCover: strings.Contains(parts[3], "COVER"),
Ext: strings.ToLower(ext),
Type: ic.SM.TypeFromExt(ext),
Kind: KindBurst,
}
info.Index, _ = strconv.Atoi(parts[1])

info.Taken, _ = time.ParseInLocation("20060102150405.000", parts[2][:14]+"."+parts[2][14:], ic.TZ)
return true, info
}
70 changes: 70 additions & 0 deletions internal/filenames/sony_xperia_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package filenames

import (
"testing"
"time"

"github.com/simulot/immich-go/internal/metadata"
)

func TestSonyXperia(t *testing.T) {
tests := []struct {
name string
filename string
expected bool
info NameInfo
}{
{
name: "Sony Xperia BURST",
filename: "DSC_0001_BURST20230709220904977.JPG",
expected: true,
info: NameInfo{
Radical: "BURST20230709220904977",
Base: "DSC_0001_BURST20230709220904977.JPG",
IsCover: false,
Ext: ".jpg",
Type: metadata.TypeImage,
Kind: KindBurst,
Index: 1,
Taken: time.Date(2023, 7, 9, 22, 9, 4, int(977*time.Millisecond), time.Local),
},
},
{
name: "Sony Xperia BURST cover",
filename: "DSC_0052_BURST20230709220904977_COVER.JPG",
expected: true,
info: NameInfo{
Radical: "BURST20230709220904977",
Base: "DSC_0052_BURST20230709220904977_COVER.JPG",
IsCover: true,
Ext: ".jpg",
Type: metadata.TypeImage,
Kind: KindBurst,
Index: 52,
Taken: time.Date(2023, 7, 9, 22, 9, 4, int(977*time.Millisecond), time.Local),
},
},
{
name: "InvalidFilename",
filename: "IMG_1123.jpg",
expected: false,
info: NameInfo{},
},
}

ic := InfoCollector{
TZ: time.Local,
SM: metadata.DefaultSupportedMedia,
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, info := ic.SonyXperia(tt.filename)
if got != tt.expected {
t.Errorf("expected %v, got %v", tt.expected, got)
}
if got && info != tt.info {
t.Errorf("expected \n%+v,\n got \n%+v", tt.info, info)
}
})
}
}

0 comments on commit c44642b

Please sign in to comment.