my god...it's finally done

This commit is contained in:
ari melody 2024-09-03 08:07:45 +01:00
parent 2baf71214e
commit 19d76ebc47
Signed by: ari
GPG key ID: CF99829C92678188
43 changed files with 1008 additions and 550 deletions

View file

@ -1,6 +1,8 @@
package model
import (
"html/template"
"strings"
"time"
)
@ -19,22 +21,9 @@ type (
Buylink string `json:"buylink"`
Copyright string `json:"copyright" db:"copyright"`
CopyrightURL string `json:"copyrightURL" db:"copyrighturl"`
}
FullRelease struct {
*Release
Tracks []DisplayTrack `json:"tracks"`
Credits []Credit `json:"credits"`
Links []Link `json:"links"`
}
ReleaseShorthand struct {
ID string `json:"id"`
Title string `json:"title"`
ReleaseType ReleaseType `json:"type" db:"type"`
ReleaseDate time.Time `json:"releaseDate" db:"release_date"`
Artwork string `json:"artwork"`
Buylink string `json:"buylink"`
Tracks []*Track `json:"tracks"`
Credits []*Credit `json:"credits"`
Links []*Link `json:"links"`
}
)
@ -48,6 +37,10 @@ const (
// GETTERS
func (release Release) GetDescriptionHTML() template.HTML {
return template.HTML(strings.Replace(release.Description, "\n", "<br>", -1))
}
func (release Release) TextReleaseDate() string {
return release.ReleaseDate.Format("2006-01-02T15:04")
}
@ -67,10 +60,39 @@ func (release Release) GetArtwork() string {
return release.Artwork
}
func (release FullRelease) IsSingle() bool {
func (release Release) IsSingle() bool {
return len(release.Tracks) == 1;
}
func (release Release) IsReleased() bool {
return release.ReleaseDate.Before(time.Now())
}
func (release Release) GetUniqueArtistNames(only_primary bool) []string {
names := []string{}
for _, credit := range release.Credits {
if only_primary && !credit.Primary { continue }
names = append(names, credit.Artist.Name)
}
return names
}
func (release Release) 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[:], ", ")
}
}