whoever was responsible for that indentation blunder, you're fired
Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
parent
cddd5656f2
commit
63221e9fd2
5 changed files with 937 additions and 934 deletions
File diff suppressed because it is too large
Load diff
|
@ -1,172 +1,172 @@
|
|||
package music
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
Artist struct {
|
||||
Id string
|
||||
Name string
|
||||
Website string
|
||||
}
|
||||
Artist struct {
|
||||
Id string
|
||||
Name string
|
||||
Website string
|
||||
}
|
||||
|
||||
MusicRelease struct {
|
||||
Id string
|
||||
Title string
|
||||
Type string
|
||||
ReleaseDate time.Time
|
||||
Artwork string
|
||||
Buyname string
|
||||
Buylink string
|
||||
Links []MusicLink
|
||||
Description string
|
||||
Credits []MusicCredit
|
||||
Lyrics string
|
||||
}
|
||||
MusicRelease struct {
|
||||
Id string
|
||||
Title string
|
||||
Type string
|
||||
ReleaseDate time.Time
|
||||
Artwork string
|
||||
Buyname string
|
||||
Buylink string
|
||||
Links []MusicLink
|
||||
Description string
|
||||
Credits []MusicCredit
|
||||
Lyrics string
|
||||
}
|
||||
|
||||
MusicLink struct {
|
||||
Name string
|
||||
Url string
|
||||
}
|
||||
MusicLink struct {
|
||||
Name string
|
||||
Url string
|
||||
}
|
||||
|
||||
MusicCredit struct {
|
||||
Artist *Artist
|
||||
Role string
|
||||
Meta bool // for "meta" contributors (i.e. not credited for the musical work, but other related assets)
|
||||
}
|
||||
)
|
||||
MusicCredit struct {
|
||||
Artist *Artist
|
||||
Role string
|
||||
Meta bool // for "meta" contributors (i.e. not credited for the musical work, but other related assets)
|
||||
}
|
||||
)
|
||||
|
||||
func (album MusicRelease) GetUniqueArtists() []Artist {
|
||||
if len(album.Credits) == 1 {
|
||||
return []Artist{*album.Credits[0].Artist}
|
||||
}
|
||||
if len(album.Credits) == 1 {
|
||||
return []Artist{*album.Credits[0].Artist}
|
||||
}
|
||||
|
||||
// create a map of artists to prevent duplicates
|
||||
res := []Artist{}
|
||||
for _, credit := range album.Credits {
|
||||
artist := *credit.Artist
|
||||
exists := false
|
||||
for _, c := range res {
|
||||
if c == *credit.Artist {
|
||||
exists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if exists {
|
||||
continue
|
||||
}
|
||||
res = append(res, artist)
|
||||
}
|
||||
// create a map of artists to prevent duplicates
|
||||
res := []Artist{}
|
||||
for _, credit := range album.Credits {
|
||||
artist := *credit.Artist
|
||||
exists := false
|
||||
for _, c := range res {
|
||||
if c == *credit.Artist {
|
||||
exists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if exists {
|
||||
continue
|
||||
}
|
||||
res = append(res, artist)
|
||||
}
|
||||
|
||||
// now create the actual array to send
|
||||
return res
|
||||
// now create the actual array to send
|
||||
return res
|
||||
}
|
||||
|
||||
func (album MusicRelease) GetUniqueNonMetaArtists() []Artist {
|
||||
if len(album.Credits) == 1 {
|
||||
return []Artist{*album.Credits[0].Artist}
|
||||
}
|
||||
if len(album.Credits) == 1 {
|
||||
return []Artist{*album.Credits[0].Artist}
|
||||
}
|
||||
|
||||
// create a map of artists to prevent duplicates
|
||||
res := []Artist{}
|
||||
for _, credit := range album.Credits {
|
||||
if credit.Meta {
|
||||
continue
|
||||
}
|
||||
artist := *credit.Artist
|
||||
exists := false
|
||||
for _, c := range res {
|
||||
if c == *credit.Artist {
|
||||
exists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if exists {
|
||||
continue
|
||||
}
|
||||
res = append(res, artist)
|
||||
}
|
||||
// create a map of artists to prevent duplicates
|
||||
res := []Artist{}
|
||||
for _, credit := range album.Credits {
|
||||
if credit.Meta {
|
||||
continue
|
||||
}
|
||||
artist := *credit.Artist
|
||||
exists := false
|
||||
for _, c := range res {
|
||||
if c == *credit.Artist {
|
||||
exists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if exists {
|
||||
continue
|
||||
}
|
||||
res = append(res, artist)
|
||||
}
|
||||
|
||||
// now create the actual array to send
|
||||
return res
|
||||
// now create the actual array to send
|
||||
return res
|
||||
}
|
||||
|
||||
func (album MusicRelease) GetUniqueArtistNames() []string {
|
||||
if len(album.Credits) == 1 {
|
||||
return []string{album.Credits[0].Artist.Name}
|
||||
}
|
||||
if len(album.Credits) == 1 {
|
||||
return []string{album.Credits[0].Artist.Name}
|
||||
}
|
||||
|
||||
artists := album.GetUniqueArtists()
|
||||
names := []string{}
|
||||
for _, artist := range artists {
|
||||
names = append(names, artist.Name)
|
||||
}
|
||||
artists := album.GetUniqueArtists()
|
||||
names := []string{}
|
||||
for _, artist := range artists {
|
||||
names = append(names, artist.Name)
|
||||
}
|
||||
|
||||
return names
|
||||
return names
|
||||
}
|
||||
|
||||
func (album MusicRelease) GetUniqueNonMetaArtistNames() []string {
|
||||
if len(album.Credits) == 1 {
|
||||
return []string{album.Credits[0].Artist.Name}
|
||||
}
|
||||
if len(album.Credits) == 1 {
|
||||
return []string{album.Credits[0].Artist.Name}
|
||||
}
|
||||
|
||||
artists := album.GetUniqueNonMetaArtists()
|
||||
names := []string{}
|
||||
for _, artist := range artists {
|
||||
names = append(names, artist.Name)
|
||||
}
|
||||
artists := album.GetUniqueNonMetaArtists()
|
||||
names := []string{}
|
||||
for _, artist := range artists {
|
||||
names = append(names, artist.Name)
|
||||
}
|
||||
|
||||
return names
|
||||
return names
|
||||
}
|
||||
|
||||
func (album MusicRelease) PrintPrimaryArtists() string {
|
||||
names := album.GetUniqueNonMetaArtistNames()
|
||||
if len(names) == 1 {
|
||||
return names[0]
|
||||
}
|
||||
res := strings.Join(names[:len(names)-1], ", ")
|
||||
res += " & " + names[len(names)-1]
|
||||
return res
|
||||
names := album.GetUniqueNonMetaArtistNames()
|
||||
if len(names) == 1 {
|
||||
return names[0]
|
||||
}
|
||||
res := strings.Join(names[:len(names)-1], ", ")
|
||||
res += " & " + names[len(names)-1]
|
||||
return res
|
||||
}
|
||||
|
||||
func (album MusicRelease) PrintCommaPrimaryArtists() string {
|
||||
names := album.GetUniqueNonMetaArtistNames()
|
||||
if len(names) == 1 {
|
||||
return names[0]
|
||||
}
|
||||
return strings.Join(names[:], ", ")
|
||||
names := album.GetUniqueNonMetaArtistNames()
|
||||
if len(names) == 1 {
|
||||
return names[0]
|
||||
}
|
||||
return strings.Join(names[:], ", ")
|
||||
}
|
||||
|
||||
func (album MusicRelease) ResolveType() string {
|
||||
if album.Type != "" {
|
||||
return album.Type
|
||||
}
|
||||
return "unknown"
|
||||
if album.Type != "" {
|
||||
return album.Type
|
||||
}
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
func (album MusicRelease) ResolveArtwork() string {
|
||||
if album.Artwork != "" {
|
||||
return album.Artwork
|
||||
}
|
||||
return "/img/music-artwork/default.png"
|
||||
if album.Artwork != "" {
|
||||
return album.Artwork
|
||||
}
|
||||
return "/img/music-artwork/default.png"
|
||||
}
|
||||
|
||||
func (album MusicRelease) PrintReleaseDate() string {
|
||||
return album.ReleaseDate.Format("02 January 2006")
|
||||
return album.ReleaseDate.Format("02 January 2006")
|
||||
}
|
||||
|
||||
func (album MusicRelease) GetReleaseYear() int {
|
||||
return album.ReleaseDate.Year()
|
||||
return album.ReleaseDate.Year()
|
||||
}
|
||||
|
||||
func (link MusicLink) NormaliseName() string {
|
||||
re := regexp.MustCompile(`[^a-z0-9]`)
|
||||
return strings.ToLower(re.ReplaceAllString(link.Name, ""))
|
||||
re := regexp.MustCompile(`[^a-z0-9]`)
|
||||
return strings.ToLower(re.ReplaceAllString(link.Name, ""))
|
||||
}
|
||||
|
||||
func (credit MusicCredit) ResolveArtist() Artist {
|
||||
return *credit.Artist
|
||||
return *credit.Artist
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue