Skip to content

Commit

Permalink
fix: #108 user-generated-memory-titles.json cannot unmarshal array
Browse files Browse the repository at this point in the history
  • Loading branch information
simulot committed Dec 24, 2023
1 parent dfd95ac commit 8a82a8c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
17 changes: 15 additions & 2 deletions browser/gp/googlephotos.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/fs"
"path"
"slices"
"sort"
"strings"
"unicode/utf8"
Expand Down Expand Up @@ -117,6 +118,11 @@ func (to *Takeout) passOneFsWalk(ctx context.Context, w fs.FS) error {
dir = strings.TrimSuffix(dir, "/")
ext := strings.ToLower(path.Ext(base))

if slices.Contains(uselessFiles, base) {
to.conf.Journal.AddEntry(name, journal.DISCARDED, "Useless file")
return nil
}

dirCatalog := to.catalogs[w][dir]
if dirCatalog.files == nil {
dirCatalog.files = map[string]fileInfo{}
Expand All @@ -137,11 +143,11 @@ func (to *Takeout) passOneFsWalk(ctx context.Context, w fs.FS) error {
to.albums[dir] = md.Title
to.conf.Journal.AddEntry(name, journal.METADATA, "Album title: "+md.Title)
default:
to.conf.Journal.AddEntry(name, journal.ERROR, "Unknown json file")
to.conf.Journal.AddEntry(name, journal.DISCARDED, "Unknown json file")
return nil
}
} else {
to.conf.Journal.AddEntry(name, journal.ERROR, "Unknown json file")
to.conf.Journal.AddEntry(name, journal.DISCARDED, "Unknown json file")
return nil
}
default:
Expand Down Expand Up @@ -519,3 +525,10 @@ func (to *Takeout) googleMDToAsset(md *GoogleMetaData, key fileKey, fsys fs.FS,
}
return &a
}

var uselessFiles = []string{
"archive_browser.html",
"print-subscriptions.json",
"shared_album_comments.json",
"user-generated-memory-titles.json",
}
4 changes: 3 additions & 1 deletion browser/gp/testgp_bigread_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/simulot/immich-go/browser"
"github.com/simulot/immich-go/helpers/fshelper"
"github.com/simulot/immich-go/journal"
"github.com/simulot/immich-go/logger"
)

Expand All @@ -20,6 +21,7 @@ func TestReadBigTakeout(t *testing.T) {
panic(err)
}
l := logger.NewLogger(logger.Info, true, false)
j := journal.NewJournal(l)
l.SetWriter(f)
m, err := filepath.Glob("../../../test-data/full_takeout/*.zip")
if err != nil {
Expand All @@ -28,7 +30,7 @@ func TestReadBigTakeout(t *testing.T) {
}
cnt := 0
fsyss, err := fshelper.ParsePath(m, true)
to, err := NewTakeout(context.Background(), l, &browser.Configuration{}, fsyss...)
to, err := NewTakeout(context.Background(), l, &browser.Configuration{Journal: j}, fsyss...)
if err != nil {
t.Error(err)
return
Expand Down
4 changes: 2 additions & 2 deletions journal/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ func (j *Journal) AddEntry(file string, action Action, comment ...string) {
}
func (j *Journal) Report() {

checkFiles := j.counts[SCANNED_IMAGE] + j.counts[SCANNED_VIDEO] + j.counts[METADATA] + j.counts[UNSUPPORTED] + j.counts[FAILED_VIDEO] + j.counts[ERROR]
checkFiles := j.counts[SCANNED_IMAGE] + j.counts[SCANNED_VIDEO] + j.counts[METADATA] + j.counts[UNSUPPORTED] + j.counts[FAILED_VIDEO] + j.counts[ERROR] + j.counts[DISCARDED]

j.log.OK("Scan of the sources:")
j.log.OK("%6d files in the input", j.counts[DISCOVERED_FILE])
j.log.OK("--------------------------------------------------------")
j.log.OK("%6d photos", j.counts[SCANNED_IMAGE])
j.log.OK("%6d videos", j.counts[SCANNED_VIDEO])
j.log.OK("%6d metadata files", j.counts[METADATA])
j.log.OK("%6d discarded files", j.counts[DISCARDED])
j.log.OK("%6d files having a type not supported", j.counts[UNSUPPORTED])
j.log.OK("%6d discarded files because in folder failed videos", j.counts[FAILED_VIDEO])
j.log.OK("%6d errors", j.counts[ERROR])
Expand All @@ -80,7 +81,6 @@ func (j *Journal) Report() {
j.log.OK("%6d files already on the server", j.counts[SERVER_DUPLICATE])
j.log.OK("%6d uploaded files on the server", j.counts[UPLOADED])
j.log.OK("%6d upgraded files on the server", j.counts[UPGRADED])
j.log.OK("%6d discarded files because of options", j.counts[DISCARDED])
j.log.OK("%6d discarded files because server has a better image", j.counts[SERVER_BETTER])

}

0 comments on commit 8a82a8c

Please sign in to comment.