implement unify
This commit is contained in:
parent
bd62068e09
commit
e833af1ecc
12
internal/common/strings.go
Normal file
12
internal/common/strings.go
Normal file
@ -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
|
||||
}
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user