Skip to content

Commit

Permalink
fix: #99 and #100 burst detection for Huawei and Samsung
Browse files Browse the repository at this point in the history
  • Loading branch information
simulot committed Dec 13, 2023
1 parent bc620c1 commit eb50788
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/releases.md
@@ -1,5 +1,14 @@
# Release notes

## Release 0.9.0

### fix: stack: Samsung #99
Now,Samsung bursts are detected

### fix:stack: Huawei Nexus 6P #100
Now, Huawei bursts are detected


## Release 0.9.0

### feat:transfer google-photo favorite to immich
Expand Down
12 changes: 11 additions & 1 deletion helpers/stacking/stack.go
Expand Up @@ -104,7 +104,7 @@ func (sb *StackBuilder) ProcessAsset(ID string, fileName string, captureDate tim
// bool -> is this is the cover if the burst
type stackMatcher func(name string) (bool, string, bool)

var stackMatchers = []stackMatcher{huaweiBurst, pixelBurst, samsungBurst}
var stackMatchers = []stackMatcher{nexusBurst, huaweiBurst, pixelBurst, samsungBurst}

var huaweiBurstRE = regexp.MustCompile(`^(.*)(_BURST\d+)(_COVER)?(\..*)$`)

Expand Down Expand Up @@ -136,6 +136,16 @@ func samsungBurst(name string) (bool, string, bool) {
return true, parts[1], parts[2] == "001"
}

var nexusBurstRE = regexp.MustCompile(`^\d{5}IMG_\d{5}_(BURST\d{14})(_COVER)?\..{3}$`)

func nexusBurst(name string) (bool, string, bool) {
parts := nexusBurstRE.FindStringSubmatch(name)
if len(parts) == 0 {
return false, "", false
}
return true, parts[1], parts[2] == "001"
}

func (sb *StackBuilder) Stacks() []Stack {
keys := gen.MapFilterKeys(sb.stacks, func(i Stack) bool {
return len(i.IDs) > 1
Expand Down
17 changes: 17 additions & 0 deletions helpers/stacking/statck_test.go
Expand Up @@ -181,6 +181,23 @@ func Test_Stack(t *testing.T) {
},
},
},
{
name: " stack: Huawei Nexus 6P #100 ",
input: []asset{
{ID: "1", FileName: "00001IMG_00001_BURST20171111030039.jpg", DateTaken: metadata.TakeTimeFromName("00001IMG_00001_BURST20171111030039.jpg")},
{ID: "2", FileName: "00002IMG_00002_BURST20171111030039.jpg", DateTaken: metadata.TakeTimeFromName("00002IMG_00002_BURST20171111030039.jpg")},
{ID: "3", FileName: "00003IMG_00003_BURST20171111030039_COVER.jpg", DateTaken: metadata.TakeTimeFromName("00003IMG_00003_BURST20171111030039_COVER.jpg")},
},
want: []Stack{
{
CoverID: "1",
IDs: []string{"2", "3"},
Date: metadata.TakeTimeFromName("00001IMG_00001_BURST20171111030039.jpg"),
Names: []string{"00001IMG_00001_BURST20171111030039.jpg", "00002IMG_00002_BURST20171111030039.jpg", "00003IMG_00003_BURST20171111030039_COVER.jpg"},
StackType: StackBurst,
},
},
},
}

for _, tt := range tc {
Expand Down
9 changes: 8 additions & 1 deletion immich/metadata/namesdate.go
Expand Up @@ -17,13 +17,20 @@ import (
// Return the value time.Time{} when there isn't any date in the name, or if the date is invalid like 2023-02-30 20:65:00

var guessTimePattern = regexp.MustCompile(`(\d{4})\D?(\d\d)\D?(\d\d)\D?(\d\d)?\D?(\d\d)?\D?(\d\d)?`)
var nexusBurstRE = regexp.MustCompile(`^\d{5}IMG_\d{5}_BURST(\d{14})(_COVER)?\..{3}$`)

func TakeTimeFromName(name string) time.Time {
local, err := tzone.Local()
if err != nil {
panic(err)
}
mm := guessTimePattern.FindStringSubmatch(name)

// check for known exceptions...
mm := nexusBurstRE.FindStringSubmatch(name)
if len(mm) > 2 {
name = mm[1]
}
mm = guessTimePattern.FindStringSubmatch(name)
m := [7]int{}
if len(mm) >= 4 {
for i := range mm {
Expand Down
4 changes: 4 additions & 0 deletions immich/metadata/namesdate_test.go
Expand Up @@ -60,6 +60,10 @@ func TestTakeTimeFromName(t *testing.T) {
name: "20223112-125200",
expected: time.Time{},
},
{
name: "00015IMG_00015_BURST20171111030039_COVER.jpg",
expected: time.Date(2017, 11, 11, 4, 0, 39, 0, local),
},
}

for _, tt := range tests {
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Expand Up @@ -97,6 +97,8 @@ Currently the bursts following this schema are detected:
- xxxxx_BURSTnnn_COVER.*
- xxxxx.RAW-01.COVER.jpg and xxxxx.RAW-02.ORIGINAL.dng
- xxxxx.RAW-01.MP.COVER.jpg and xxxxx.RAW-02.ORIGINAL.dng
- xxxxxIMG_xxxxx_BURSTyyyymmddhhmmss.jpg and xxxxxIMG_xxxxx_BURSTyyyymmddhhmmss_COVER.jpg (Huawei Nexus 6P)
- yyyymmdd_hhmmss_xxx.jpg (Samsung)

All images must be taken during the same minute.
The COVER image will be the parent image of the stack
Expand Down

0 comments on commit eb50788

Please sign in to comment.