2025-10-07 16:45:52 +02:00

61 lines
1.2 KiB
Go

package data
import (
"regexp"
)
type SourceType struct {
Name string
Regex *regexp.Regexp
RegexArtist *regexp.Regexp
RegexAlbum *regexp.Regexp
RegexSong *regexp.Regexp
}
type ObjectType string
const SongSource = ObjectType("song")
const AlbumSource = ObjectType("album")
const ArtistSource = ObjectType("artist")
type Source struct {
Url string
SourceType *SourceType
ObjectType ObjectType
}
func dedupeSources(inputSources []Source) []Source {
urlMapping := map[string]int{}
deduped := []Source{}
for _, source := range inputSources {
if mergeWithIndex, ok := urlMapping[source.Url]; ok {
// has to merge current source with source at index
if source.ObjectType != "" {
deduped[mergeWithIndex].ObjectType = source.ObjectType
}
if source.SourceType != nil {
deduped[mergeWithIndex].SourceType = source.SourceType
}
} else {
// just appending
urlMapping[source.Url] = len(deduped)
deduped = append(deduped, source)
}
}
return deduped
}
func sourceIndices(sources []Source) []string {
res := []string{}
for _, source := range sources {
res = append(res, "url"+source.Url)
}
return res
}