Skip to content

Commit

Permalink
fix for #78: mp4-files do not get imported
Browse files Browse the repository at this point in the history
  • Loading branch information
simulot committed Nov 22, 2023
1 parent edc40a3 commit b8827c8
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 89 deletions.
44 changes: 6 additions & 38 deletions browser/files/localassets.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,40 +96,9 @@ func (la *LocalAssetBrowser) handleFolder(ctx context.Context, fileChan chan *br
}

for _, es := range fileMap {
hasHEIC := 0
hasMP4 := 0
hasJPG := 0
hasXMP := 0
hasOther := 0
// Same base, different extensions

livePhotoBin := ""
for _, e := range es {
n := e.Name()
ext := strings.ToLower(path.Ext(n))
switch ext {
case ".heic":
hasHEIC++
case ".mp4":
hasMP4++
livePhotoBin = e.Name()
case ".jpg":
hasJPG++
case ".xmp":
hasXMP++
default:
hasOther++
}
}

isLivePhoto := hasMP4 == 1 && ((hasHEIC == 1 && hasJPG == 0) || (hasHEIC == 0 && hasJPG == 1)) && hasOther == 0

for _, e := range es {
name := e.Name()
if isLivePhoto && e.Name() == livePhotoBin {
// Don't sent the mp4 part of the live photo as a separate asset
continue
}
ext := path.Ext(name)
if _, err := fshelper.MimeFromExt(strings.ToLower(ext)); err != nil {
la.log.Debug("%s", err)
Expand All @@ -145,13 +114,12 @@ func (la *LocalAssetBrowser) handleFolder(ctx context.Context, fileChan chan *br
}
la.log.Debug("file '%s'", name)
f := browser.LocalAssetFile{
FSys: la.fsys,
FileName: path.Join(folder, name),
Title: path.Base(name),
LivePhotoData: livePhotoBin,
FileSize: 0,
Err: err,
DateTaken: metadata.TakeTimeFromName(filepath.Base(name)),
FSys: la.fsys,
FileName: path.Join(folder, name),
Title: path.Base(name),
FileSize: 0,
Err: err,
DateTaken: metadata.TakeTimeFromName(filepath.Base(name)),
}

s, err := e.Info()
Expand Down
36 changes: 0 additions & 36 deletions browser/gp/googlephotos.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,41 +125,8 @@ func (to *Takeout) Browse(ctx context.Context) chan *browser.LocalAssetFile {
to.log.Debug("Checking '%s', %d", k.name, k.year)
assets := to.jsonAssets(k, md)

hasHEIC := 0
hasMP4 := 0
hasJPG := 0
hasXMP := 0
hasOther := 0
livePhotoBin := ""

for _, a := range assets {
// Same base, different extensions

n := a.FileName
ext := strings.ToLower(path.Ext(n))
switch ext {
case ".heic":
hasHEIC++
case ".mp4":
hasMP4++
livePhotoBin = n
case ".jpg":
hasJPG++
case ".xmp":
hasXMP++
default:
hasOther++
}
}

isLivePhoto := hasMP4 == 1 && ((hasHEIC == 1 && hasJPG == 0) || (hasHEIC == 0 && hasJPG == 1)) && hasOther == 0

for _, a := range assets {
ext := path.Ext(a.FileName)
if isLivePhoto && strings.ToLower(ext) == ".mp4" {
to.log.Debug("live photo: '%s'", a.FileName)
continue
}
if !to.conf.SelectExtensions.Include(ext) {
to.log.Debug("file not selected: '%s'", a.FileName)
continue
Expand All @@ -176,9 +143,6 @@ func (to *Takeout) Browse(ctx context.Context) chan *browser.LocalAssetFile {
case <-ctx.Done():
return
default:
if isLivePhoto {
a.LivePhotoData = livePhotoBin
}
c <- a
}
} else {
Expand Down
7 changes: 7 additions & 0 deletions docs/releases.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release notes

## Release 0.8.5

### fix for #78: mp4-files do not get imported

Thanks to @Zack and @jrasm91 to have nailed the problem.


## Release 0.8.4

### fix for #67 : Live photos files are stacked and not recognized as live photos
Expand Down
28 changes: 13 additions & 15 deletions helpers/stacking/stack.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stacking

import (
"immich-go/helpers/fshelper"
"immich-go/helpers/gen"
"immich-go/immich"
"path"
Expand Down Expand Up @@ -77,26 +78,23 @@ func (sb *StackBuilder) Stacks() []Stack {
s := sb.stacks[k]

// Exclude live photos
hasHEIC := 0
hasMP4 := 0
hasJPG := 0
hasOther := 0
hasPhoto := 0
hasVideo := 0

for _, n := range s.Names {
ext := strings.ToLower(path.Ext(n))
switch ext {
case ".heic":
hasHEIC++
case ".mp4":
hasMP4++
case ".jpg":
hasJPG++
default:
hasOther++
mime, err := fshelper.MimeFromExt(path.Ext(n))
if err != nil {
continue
}
switch mime[0] {
case "video":
hasVideo++
case "photo":
hasPhoto++
}
}

if hasOther == 0 && (hasHEIC == 1 || hasJPG == 1) && hasMP4 == 1 {
if hasPhoto == 1 && hasVideo == 1 {
// oh, a live photo!
continue
}
Expand Down
106 changes: 106 additions & 0 deletions journal/journal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package journal

import (
"fmt"
"immich-go/helpers/gen"
"immich-go/logger"
"io"
"sort"
"sync"
"time"
)

type Journal struct {
sync.RWMutex
Files map[string][]Entry
log logger.Logger
}

type Entry struct {
ts time.Time
action Action
comment string
}

type Action string

const (
// INFO Action = "Information"
SCANNED Action = "Scanned"
DISCARDED Action = "Discarded"
UPLOADED Action = "Uploaded"
UPGRADED Action = "Server photo upgraded"
ERROR Action = "Error"
LOCAL_DUPLICATE Action = "Local duplicate"
SERVER_DUPLICATE Action = "Server has photo"
STACKED Action = "Stacked"
SERVER_BETTER Action = "Server photo is better"
ALBUM Action = "Added to an album"
LIVE_PHOTO Action = "Live photo"
FAILED_VIDEO Action = "Failed video"
)

func NewJournal(log logger.Logger) *Journal {
return &Journal{
Files: map[string][]Entry{},
log: log,
}
}

func (j *Journal) AddEntry(file string, action Action, comment string) {
if j == nil {
return
}
if j.log != nil {
switch action {

case ERROR:
j.log.Error("%-40s: %s: %s", action, file, comment)
case UPLOADED:
j.log.OK("%-40s: %s: %s", action, file, comment)
default:
j.log.Info("%-40s: %s: %s", action, file, comment)
}
}
j.Lock()
defer j.Unlock()
j.Files[file] = append(j.Files[file], Entry{ts: time.Now(), action: action, comment: comment})
}

func (j *Journal) Report() {
counts := map[Action]int{}

for _, es := range j.Files {
for _, e := range es {
counts[e.action]++
}
}
j.log.OK("Upload report:")
j.log.OK("%6d errors", counts[ERROR])
j.log.OK("%6d files scanned", counts[SCANNED])
j.log.OK("%6d files discarded because in folder failed videos", counts[FAILED_VIDEO])
j.log.OK("%6d files discarded because of options", counts[DISCARDED])
j.log.OK("%6d files discarded because server has a better image", counts[SERVER_BETTER])
j.log.OK("%6d files duplicated locally", counts[LOCAL_DUPLICATE])
j.log.OK("%6d files already on the server", counts[SERVER_DUPLICATE])

j.log.OK("%6d files uploaded on the server", counts[UPLOADED])
j.log.OK("%6d files upgraded on the server", counts[UPGRADED])

}

func (j *Journal) WriteJournal(w io.Writer) {
keys := gen.MapKeys(j.Files)
sort.Strings(keys)
for _, k := range keys {
fmt.Fprintln(w, "File:", k)
for _, e := range j.Files[k] {
fmt.Fprint(w, "\t", e.action)
if len(e.comment) > 0 {
fmt.Fprint(w, ", ", e.comment)
}
fmt.Fprintln(w)
}
}

}

0 comments on commit b8827c8

Please sign in to comment.