2024-08-02 21:48:26 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2024-09-03 07:07:45 +00:00
|
|
|
"html/template"
|
|
|
|
"strings"
|
2024-08-02 21:48:26 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
ReleaseType string
|
2024-09-01 03:43:32 +00:00
|
|
|
|
|
|
|
Release struct {
|
2024-09-01 23:15:23 +00:00
|
|
|
ID string `json:"id"`
|
|
|
|
Visible bool `json:"visible"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
ReleaseType ReleaseType `json:"type" db:"type"`
|
|
|
|
ReleaseDate time.Time `json:"releaseDate" db:"release_date"`
|
|
|
|
Artwork string `json:"artwork"`
|
|
|
|
Buyname string `json:"buyname"`
|
|
|
|
Buylink string `json:"buylink"`
|
|
|
|
Copyright string `json:"copyright" db:"copyright"`
|
|
|
|
CopyrightURL string `json:"copyrightURL" db:"copyrighturl"`
|
2024-09-03 07:07:45 +00:00
|
|
|
Tracks []*Track `json:"tracks"`
|
|
|
|
Credits []*Credit `json:"credits"`
|
|
|
|
Links []*Link `json:"links"`
|
2024-08-02 21:48:26 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2024-08-05 15:49:49 +00:00
|
|
|
Single ReleaseType = "single"
|
|
|
|
Album ReleaseType = "album"
|
2024-08-02 21:48:26 +00:00
|
|
|
EP ReleaseType = "EP"
|
2024-08-05 15:49:49 +00:00
|
|
|
Compilation ReleaseType = "compilation"
|
|
|
|
Upcoming ReleaseType = "upcoming"
|
2024-08-02 21:48:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GETTERS
|
|
|
|
|
2024-09-03 07:07:45 +00:00
|
|
|
func (release Release) GetDescriptionHTML() template.HTML {
|
|
|
|
return template.HTML(strings.Replace(release.Description, "\n", "<br>", -1))
|
|
|
|
}
|
|
|
|
|
2024-08-05 00:23:17 +00:00
|
|
|
func (release Release) TextReleaseDate() string {
|
|
|
|
return release.ReleaseDate.Format("2006-01-02T15:04")
|
2024-08-02 21:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (release Release) PrintReleaseDate() string {
|
|
|
|
return release.ReleaseDate.Format("02 January 2006")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (release Release) GetReleaseYear() int {
|
|
|
|
return release.ReleaseDate.Year()
|
|
|
|
}
|
|
|
|
|
2024-08-05 00:23:17 +00:00
|
|
|
func (release Release) GetArtwork() string {
|
|
|
|
if release.Artwork == "" {
|
|
|
|
return "/img/default-cover-art.png"
|
|
|
|
}
|
|
|
|
return release.Artwork
|
|
|
|
}
|
|
|
|
|
2024-09-03 07:07:45 +00:00
|
|
|
func (release Release) IsSingle() bool {
|
2024-08-02 21:48:26 +00:00
|
|
|
return len(release.Tracks) == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
func (release Release) IsReleased() bool {
|
|
|
|
return release.ReleaseDate.Before(time.Now())
|
|
|
|
}
|
2024-09-03 07:07:45 +00:00
|
|
|
|
|
|
|
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[:], ", ")
|
|
|
|
}
|
|
|
|
}
|