From ead323eaedbfd8cf0a01f1afa0598363a1e9b692 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Sun, 12 Nov 2023 18:40:45 +0100 Subject: [PATCH] Import result can report total and processed items --- backends/dump/dump.go | 8 ++++++-- backends/scrobblerlog/scrobblerlog.go | 4 ++-- cmd/listens.go | 3 ++- cmd/loves.go | 3 ++- models/interfaces.go | 3 ++- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/backends/dump/dump.go b/backends/dump/dump.go index eeff3a9..715a0a2 100644 --- a/backends/dump/dump.go +++ b/backends/dump/dump.go @@ -37,13 +37,15 @@ func (b DumpBackend) FromConfig(config *viper.Viper) models.Backend { func (b DumpBackend) ImportListens(listens []models.Listen, oldestTimestamp time.Time) (models.ImportResult, error) { result := models.ImportResult{ - Count: len(listens), + TotalCount: len(listens), + ImportCount: 0, LastTimestamp: oldestTimestamp, } for _, listen := range listens { if listen.ListenedAt.Unix() > result.LastTimestamp.Unix() { result.LastTimestamp = listen.ListenedAt } + result.ImportCount += 1 fmt.Printf("🎶 %v: \"%s\" by %s\n", listen.ListenedAt, listen.TrackName, listen.ArtistName()) } return result, nil @@ -51,13 +53,15 @@ func (b DumpBackend) ImportListens(listens []models.Listen, oldestTimestamp time func (b DumpBackend) ImportLoves(loves []models.Love, oldestTimestamp time.Time) (models.ImportResult, error) { result := models.ImportResult{ - Count: len(loves), + TotalCount: len(loves), + ImportCount: 0, LastTimestamp: oldestTimestamp, } for _, love := range loves { if love.Created.Unix() > result.LastTimestamp.Unix() { result.LastTimestamp = love.Created } + result.ImportCount += 1 fmt.Printf("❤️ %v: \"%s\" by %s\n", love.Created, love.TrackName, love.ArtistName()) } return result, nil diff --git a/backends/scrobblerlog/scrobblerlog.go b/backends/scrobblerlog/scrobblerlog.go index 7f20db3..412816a 100644 --- a/backends/scrobblerlog/scrobblerlog.go +++ b/backends/scrobblerlog/scrobblerlog.go @@ -58,7 +58,7 @@ func (b ScrobblerLogBackend) ExportListens(oldestTimestamp time.Time) ([]models. func (b ScrobblerLogBackend) ImportListens(listens []models.Listen, oldestTimestamp time.Time) (models.ImportResult, error) { result := models.ImportResult{ - Count: 0, + TotalCount: len(listens), LastTimestamp: oldestTimestamp, } @@ -82,6 +82,6 @@ func (b ScrobblerLogBackend) ImportListens(listens []models.Listen, oldestTimest } result.LastTimestamp = lastTimestamp - result.Count = len(listens) + result.ImportCount = len(listens) return result, nil } diff --git a/cmd/listens.go b/cmd/listens.go index 99c1f41..f8f8000 100644 --- a/cmd/listens.go +++ b/cmd/listens.go @@ -48,7 +48,8 @@ var listensCmd = &cobra.Command{ cobra.CheckErr(err) result, err := importBackend.ImportListens(listens, timestamp) cobra.CheckErr(err) - fmt.Printf("Imported %v listens (last timestamp %v)\n", result.Count, result.LastTimestamp) + fmt.Printf("Imported %v of %v listens (last timestamp %v)\n", + result.ImportCount, result.TotalCount, result.LastTimestamp) }, } diff --git a/cmd/loves.go b/cmd/loves.go index 859f415..e6c16cd 100644 --- a/cmd/loves.go +++ b/cmd/loves.go @@ -48,7 +48,8 @@ var lovesCmd = &cobra.Command{ cobra.CheckErr(err) result, err := importBackend.ImportLoves(loves, timestamp) cobra.CheckErr(err) - fmt.Printf("Imported %v loves (last timestamp %v)\n", result.Count, result.LastTimestamp) + fmt.Printf("Imported %v of %v loves (last timestamp %v)\n", + result.ImportCount, result.TotalCount, result.LastTimestamp) }, } diff --git a/models/interfaces.go b/models/interfaces.go index cd2596f..1e7063b 100644 --- a/models/interfaces.go +++ b/models/interfaces.go @@ -48,6 +48,7 @@ type LovesImport interface { } type ImportResult struct { - Count int + TotalCount int + ImportCount int LastTimestamp time.Time }