2024-08-02 21:48:26 +00:00
|
|
|
package model
|
|
|
|
|
2024-09-01 03:43:32 +00:00
|
|
|
import "strings"
|
|
|
|
|
2024-08-02 21:48:26 +00:00
|
|
|
type (
|
|
|
|
Artist struct {
|
2024-09-01 03:43:32 +00:00
|
|
|
ID string `json:"id"`
|
2024-08-02 21:48:26 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
Website string `json:"website"`
|
|
|
|
Avatar string `json:"avatar"`
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2024-08-05 00:23:17 +00:00
|
|
|
func (artist Artist) GetWebsite() string {
|
|
|
|
return artist.Website
|
|
|
|
}
|
|
|
|
|
2024-08-02 21:48:26 +00:00
|
|
|
func (artist Artist) GetAvatar() string {
|
2024-09-01 03:43:32 +00:00
|
|
|
if artist.Avatar == "" {
|
|
|
|
return "/img/default-avatar.png"
|
|
|
|
}
|
2024-08-02 21:48:26 +00:00
|
|
|
return artist.Avatar
|
|
|
|
}
|
2024-09-01 03:43:32 +00:00
|
|
|
|
|
|
|
func (release FullRelease) GetUniqueArtists(only_primary bool) []*Artist {
|
|
|
|
var artists = []*Artist{}
|
|
|
|
|
|
|
|
for _, credit := range release.Credits {
|
|
|
|
if only_primary && !credit.Primary {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
exists := false
|
|
|
|
for _, a := range artists {
|
|
|
|
if a.ID == credit.Artist.ID {
|
|
|
|
exists = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if exists {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
artists = append(artists, &credit.Artist)
|
|
|
|
}
|
|
|
|
|
|
|
|
return artists
|
|
|
|
}
|
|
|
|
|
|
|
|
func (release FullRelease) GetUniqueArtistNames(only_primary bool) []string {
|
|
|
|
var names = []string{}
|
|
|
|
for _, artist := range release.GetUniqueArtists(only_primary) {
|
|
|
|
names = append(names, artist.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
return names
|
|
|
|
}
|
|
|
|
|
|
|
|
func (release FullRelease) PrintArtists(only_primary bool, ampersand bool) string {
|
|
|
|
names := release.GetUniqueArtistNames(only_primary)
|
|
|
|
|
|
|
|
if len(names) == 0 {
|
|
|
|
return "Unknown Artist"
|
|
|
|
} else if len(names) == 1 {
|
|
|
|
return names[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
if ampersand {
|
|
|
|
res := strings.Join(names[:len(names)-1], ", ")
|
|
|
|
res += " & " + names[len(names)-1]
|
|
|
|
return res
|
|
|
|
} else {
|
|
|
|
return strings.Join(names[:], ", ")
|
|
|
|
}
|
|
|
|
}
|