From e833af1ecc745abb4ebaf675dffb90de4cea9eec Mon Sep 17 00:00:00 2001 From: Hazel Noack Date: Tue, 7 Oct 2025 13:26:35 +0200 Subject: [PATCH] implement unify --- internal/common/strings.go | 12 ++++++++++++ internal/data/song.go | 11 ++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 internal/common/strings.go diff --git a/internal/common/strings.go b/internal/common/strings.go new file mode 100644 index 0000000..7fca90e --- /dev/null +++ b/internal/common/strings.go @@ -0,0 +1,12 @@ +package common + +import "strings" + +func Unify(s string) string { + s = strings.TrimSpace(s) + s = strings.ToLower(s) + for strings.Contains(s, " ") { + s = strings.ReplaceAll(s, " ", " ") + } + return s +} diff --git a/internal/data/song.go b/internal/data/song.go index eef28a5..76deecd 100644 --- a/internal/data/song.go +++ b/internal/data/song.go @@ -1,6 +1,11 @@ package data -import "strconv" +import ( + "strconv" + + "gitea.elara.ws/Hazel/music-kraken/internal/common" + "github.com/gohugoio/hugo/common" +) type MusicObject interface { Compile() MusicObject @@ -13,6 +18,7 @@ func dedupeMusicObjects[T MusicObject](inputMusicObjects []T) []T { deduped := []T{} for _, musicObject := range inputMusicObjects { + musicObject = musicObject.Compile().(T) indices := musicObject.GetIndices() // Check if we've seen any of these indices before @@ -99,6 +105,7 @@ func (m Song) Merge(other MusicObject) MusicObject { func (m Song) Compile() MusicObject { m.Sources = dedupeSources(m.Sources) + m.UnifiedName = common.Unify(m.Name) m.Artists = dedupeMusicObjects(m.Artists) return m } @@ -150,6 +157,7 @@ func (m Album) Merge(other MusicObject) MusicObject { func (m Album) Compile() MusicObject { m.Sources = dedupeSources(m.Sources) + m.UnifiedName = common.Unify(m.Name) m.Songs = dedupeMusicObjects(m.Songs) m.Artists = dedupeMusicObjects(m.Artists) return m @@ -199,6 +207,7 @@ func (m Artist) GetIndices() []string { func (m Artist) Compile() MusicObject { m.Sources = dedupeSources(m.Sources) + m.UnifiedName = common.Unify(m.Name) m.Albums = dedupeMusicObjects(m.Albums) return m }