HOLY REFACTOR GOOD GRIEF (also finally started some CRUD work)
Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
parent
1c310c9101
commit
442889340c
80 changed files with 1571 additions and 1330 deletions
109
music/model/release.go
Normal file
109
music/model/release.go
Normal file
|
@ -0,0 +1,109 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
ReleaseType string
|
||||
Release struct {
|
||||
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"`
|
||||
Links []Link `json:"links"`
|
||||
Credits []Credit `json:"credits"`
|
||||
Tracks []Track `json:"tracks"`
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
Single ReleaseType = "Single"
|
||||
Album ReleaseType = "Album"
|
||||
EP ReleaseType = "EP"
|
||||
Compilation ReleaseType = "Compilation"
|
||||
)
|
||||
|
||||
// GETTERS
|
||||
|
||||
func (release Release) GetArtwork() string {
|
||||
if release.Artwork == "" {
|
||||
return "/img/default-cover-art.png"
|
||||
}
|
||||
return release.Artwork
|
||||
}
|
||||
|
||||
func (release Release) PrintReleaseDate() string {
|
||||
return release.ReleaseDate.Format("02 January 2006")
|
||||
}
|
||||
|
||||
func (release Release) GetReleaseYear() int {
|
||||
return release.ReleaseDate.Year()
|
||||
}
|
||||
|
||||
func (release Release) IsSingle() bool {
|
||||
return len(release.Tracks) == 1;
|
||||
}
|
||||
|
||||
func (release Release) IsReleased() bool {
|
||||
return release.ReleaseDate.Before(time.Now())
|
||||
}
|
||||
|
||||
func (release Release) 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 Release) GetUniqueArtistNames(only_primary bool) []string {
|
||||
var names = []string{}
|
||||
for _, artist := range release.GetUniqueArtists(only_primary) {
|
||||
names = append(names, 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[:], ", ")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue