home to your local SPACEGIRL 馃挮
arimelody.space
1package model
2
3import (
4 "html/template"
5 "strings"
6 "time"
7)
8
9type (
10 ReleaseType string
11
12 Release struct {
13 ID string `json:"id"`
14 Visible bool `json:"visible"`
15 Title string `json:"title"`
16 Description string `json:"description"`
17 ReleaseType ReleaseType `json:"type" db:"type"`
18 ReleaseDate time.Time `json:"releaseDate" db:"release_date"`
19 Artwork string `json:"artwork"`
20 Buyname string `json:"buyname"`
21 Buylink string `json:"buylink"`
22 Copyright string `json:"copyright" db:"copyright"`
23 CopyrightURL string `json:"copyrightURL" db:"copyrighturl"`
24 Tracks []*Track `json:"tracks"`
25 Credits []*Credit `json:"credits"`
26 Links []*Link `json:"links"`
27 CreatedAt time.Time `json:"-" db:"created_at"`
28 }
29)
30
31const (
32 Single ReleaseType = "single"
33 Album ReleaseType = "album"
34 EP ReleaseType = "EP"
35 Compilation ReleaseType = "compilation"
36 Upcoming ReleaseType = "upcoming"
37)
38
39// GETTERS
40
41func (release Release) GetDescriptionHTML() template.HTML {
42 return template.HTML(strings.ReplaceAll(release.Description, "\n", "<br>"))
43}
44
45func (release Release) TextReleaseDate() string {
46 return release.ReleaseDate.Format("2006-01-02T15:04")
47}
48
49func (release Release) PrintReleaseDate() string {
50 return release.ReleaseDate.Format("02 January 2006")
51}
52
53func (release Release) GetArtwork() string {
54 if release.Artwork == "" {
55 return "/img/default-cover-art.png"
56 }
57 return release.Artwork
58}
59
60func (release Release) IsSingle() bool {
61 return len(release.Tracks) == 1;
62}
63
64func (release Release) IsReleased() bool {
65 return release.ReleaseDate.Before(time.Now())
66}
67
68func (release Release) GetUniqueArtistNames(only_primary bool) []string {
69 names := []string{}
70
71 for _, credit := range release.Credits {
72 if only_primary && !credit.Primary { continue }
73 names = append(names, credit.Artist.Name)
74 }
75
76 return names
77}
78
79func (release Release) PrintArtists(only_primary bool, ampersand bool) string {
80 names := release.GetUniqueArtistNames(only_primary)
81
82 if len(names) == 0 {
83 return "Unknown Artist"
84 } else if len(names) == 1 {
85 return names[0]
86 }
87
88 if ampersand {
89 res := strings.Join(names[:len(names)-1], ", ")
90 res += " & " + names[len(names)-1]
91 return res
92 } else {
93 return strings.Join(names[:], ", ")
94 }
95}