renamed albums to music releases

Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
ari melody 2024-03-20 10:50:37 +00:00
parent 9d56ca63af
commit 6ec813dd58
4 changed files with 135 additions and 135 deletions

View file

@ -44,7 +44,7 @@ func make_date_work(date string) time.Time {
return res return res
} }
var placeholders = []Album{ var placeholders = []MusicRelease{
{ {
Id: "test", Id: "test",
Title: "test album", Title: "test album",
@ -52,28 +52,28 @@ var placeholders = []Album{
ReleaseDate: make_date_work("18-Mar-2024"), ReleaseDate: make_date_work("18-Mar-2024"),
Buyname: "go get it!!", Buyname: "go get it!!",
Buylink: "https://arimelody.me/", Buylink: "https://arimelody.me/",
Links: []AlbumLink{ Links: []MusicLink{
AlbumLink{ MusicLink{
Name: "youtube", Name: "youtube",
Url: "https://youtu.be/dQw4w9WgXcQ", Url: "https://youtu.be/dQw4w9WgXcQ",
}, },
}, },
Description: Description:
`Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas viverra ligula interdum, tempor metus venenatis, tempus est. Praesent semper vulputate nulla, a venenatis libero elementum id. Proin maximus aliquet accumsan. Integer eu orci congue, ultrices leo sed, maximus risus. Integer laoreet non urna non accumsan. Cras ut sollicitudin justo. Vivamus eu orci tempus, aliquet est rhoncus, tempus neque. Aliquam tempor sit amet nibh sed tempus. Nulla vitae bibendum purus. Sed in mi enim. Nam pharetra enim lorem, vel tristique diam malesuada a. Duis dignissim nunc mi, id semper ex tincidunt a. Sed laoreet consequat lacus a consectetur. Nulla est diam, tempus eget lacus ullamcorper, tincidunt faucibus ex. Duis consectetur felis sit amet ante fermentum interdum. Sed pulvinar laoreet tellus.`, `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas viverra ligula interdum, tempor metus venenatis, tempus est. Praesent semper vulputate nulla, a venenatis libero elementum id. Proin maximus aliquet accumsan. Integer eu orci congue, ultrices leo sed, maximus risus. Integer laoreet non urna non accumsan. Cras ut sollicitudin justo. Vivamus eu orci tempus, aliquet est rhoncus, tempus neque. Aliquam tempor sit amet nibh sed tempus. Nulla vitae bibendum purus. Sed in mi enim. Nam pharetra enim lorem, vel tristique diam malesuada a. Duis dignissim nunc mi, id semper ex tincidunt a. Sed laoreet consequat lacus a consectetur. Nulla est diam, tempus eget lacus ullamcorper, tincidunt faucibus ex. Duis consectetur felis sit amet ante fermentum interdum. Sed pulvinar laoreet tellus.`,
Credits: []AlbumCredit{ Credits: []MusicCredit{
AlbumCredit{ MusicCredit{
Artist: &ari, Artist: &ari,
Role: "having the swag", Role: "having the swag",
}, },
AlbumCredit{ MusicCredit{
Artist: &zaire, Artist: &zaire,
Role: "having the swag", Role: "having the swag",
}, },
AlbumCredit{ MusicCredit{
Artist: &mae, Artist: &mae,
Role: "having the swag", Role: "having the swag",
}, },
AlbumCredit{ MusicCredit{
Artist: &loudar, Artist: &loudar,
Role: "having the swag", Role: "having the swag",
}, },
@ -183,35 +183,35 @@ var placeholders = []Album{
ReleaseDate: make_date_work("11-Nov-2022"), ReleaseDate: make_date_work("11-Nov-2022"),
Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_Dream.webp", Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_Dream.webp",
Buylink: "https://arimelody.bandcamp.com/track/dream", Buylink: "https://arimelody.bandcamp.com/track/dream",
Links: []AlbumLink{ Links: []MusicLink{
AlbumLink{ MusicLink{
Name: "spotify", Name: "spotify",
Url: "https://open.spotify.com/album/5talRpqzjExP1w6j5LFIAh", Url: "https://open.spotify.com/album/5talRpqzjExP1w6j5LFIAh",
}, },
AlbumLink{ MusicLink{
Name: "apple music", Name: "apple music",
Url: "https://music.apple.com/ie/album/dream-single/1650037132", Url: "https://music.apple.com/ie/album/dream-single/1650037132",
}, },
AlbumLink{ MusicLink{
Name: "soundcloud", Name: "soundcloud",
Url: "https://soundcloud.com/arimelody/dream2022", Url: "https://soundcloud.com/arimelody/dream2022",
}, },
AlbumLink{ MusicLink{
Name: "youtube", Name: "youtube",
Url: "https://www.youtube.com/watch?v=nfFgtMuYAx8", Url: "https://www.youtube.com/watch?v=nfFgtMuYAx8",
}, },
}, },
Description: "living the dream 🌌 ✨", Description: "living the dream 🌌 ✨",
Credits: []AlbumCredit{ Credits: []MusicCredit{
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "vocals", Role: "vocals",
}, },
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "production", Role: "production",
}, },
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "artwork", Role: "artwork",
}, },
@ -251,35 +251,35 @@ var placeholders = []Album{
ReleaseDate: make_date_work("24-Jan-2021"), ReleaseDate: make_date_work("24-Jan-2021"),
Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_Go_My_Way.webp", Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_Go_My_Way.webp",
Buylink: "https://arimelody.bandcamp.com/track/go-my-way", Buylink: "https://arimelody.bandcamp.com/track/go-my-way",
Links: []AlbumLink{ Links: []MusicLink{
AlbumLink{ MusicLink{
Name: "spotify", Name: "spotify",
Url: "https://open.spotify.com/album/35WNtxK12IDHCUoXHDePGE", Url: "https://open.spotify.com/album/35WNtxK12IDHCUoXHDePGE",
}, },
AlbumLink{ MusicLink{
Name: "apple music", Name: "apple music",
Url: "https://music.apple.com/ie/album/go-my-way-single/1547145699", Url: "https://music.apple.com/ie/album/go-my-way-single/1547145699",
}, },
AlbumLink{ MusicLink{
Name: "soundcloud", Name: "soundcloud",
Url: "https://soundcloud.com/arimelody/go-my-way", Url: "https://soundcloud.com/arimelody/go-my-way",
}, },
AlbumLink{ MusicLink{
Name: "youtube", Name: "youtube",
Url: "https://www.youtube.com/watch?v=CNptNQdLkl0", Url: "https://www.youtube.com/watch?v=CNptNQdLkl0",
}, },
}, },
Description: "hey! go my way! 💥 ✨", Description: "hey! go my way! 💥 ✨",
Credits: []AlbumCredit{ Credits: []MusicCredit{
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "vocals", Role: "vocals",
}, },
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "production", Role: "production",
}, },
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "artwork", Role: "artwork",
}, },
@ -292,7 +292,7 @@ var placeholders = []Album{
ReleaseDate: make_date_work("12-Mar-2020"), ReleaseDate: make_date_work("12-Mar-2020"),
Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_Rowboat.webp", Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_Rowboat.webp",
Buylink: "https://arimelody.bandcamp.com/track/rowboat", Buylink: "https://arimelody.bandcamp.com/track/rowboat",
Links: []AlbumLink{ Links: []MusicLink{
{ {
Name: "spotify", Name: "spotify",
Url: "https://open.spotify.com/album/7jyqJFVKaENCPm58v5O44Y", Url: "https://open.spotify.com/album/7jyqJFVKaENCPm58v5O44Y",
@ -311,16 +311,16 @@ var placeholders = []Album{
}, },
}, },
Description: "let's take a trip. i've got a goddamn boat ⛵️", Description: "let's take a trip. i've got a goddamn boat ⛵️",
Credits: []AlbumCredit{ Credits: []MusicCredit{
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "vocals", Role: "vocals",
}, },
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "production", Role: "production",
}, },
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "artwork", Role: "artwork",
}, },
@ -333,7 +333,7 @@ var placeholders = []Album{
ReleaseDate: make_date_work("25-Dec-2019"), ReleaseDate: make_date_work("25-Dec-2019"),
Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_Hello_World.webp", Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_Hello_World.webp",
Buylink: "https://arimelody.bandcamp.com/track/hello-world", Buylink: "https://arimelody.bandcamp.com/track/hello-world",
Links: []AlbumLink{ Links: []MusicLink{
{ {
Name: "spotify", Name: "spotify",
Url: "https://open.spotify.com/album/3LbElPXD4dsDumttGBuYxx", Url: "https://open.spotify.com/album/3LbElPXD4dsDumttGBuYxx",
@ -352,16 +352,16 @@ var placeholders = []Album{
}, },
}, },
Description: "we'll dawn a new frontier! 👾", Description: "we'll dawn a new frontier! 👾",
Credits: []AlbumCredit{ Credits: []MusicCredit{
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "vocals", Role: "vocals",
}, },
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "production", Role: "production",
}, },
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "artwork", Role: "artwork",
}, },
@ -373,7 +373,7 @@ var placeholders = []Album{
Type: "single", Type: "single",
ReleaseDate: make_date_work("07-Dec-2019"), ReleaseDate: make_date_work("07-Dec-2019"),
Artwork: "https://mellodoot.com/img/music_artwork/zaire_-_Sine_ft._mellodoot.webp", Artwork: "https://mellodoot.com/img/music_artwork/zaire_-_Sine_ft._mellodoot.webp",
Links: []AlbumLink{ Links: []MusicLink{
{ {
Name: "spotify", Name: "spotify",
Url: "https://open.spotify.com/album/4WPuaJtTV7z86KubD9Rnmk", Url: "https://open.spotify.com/album/4WPuaJtTV7z86KubD9Rnmk",
@ -387,12 +387,12 @@ var placeholders = []Album{
Url: "https://www.youtube.com/watch?v=z1H1s6VRnyY", Url: "https://www.youtube.com/watch?v=z1H1s6VRnyY",
}, },
}, },
Credits: []AlbumCredit{ Credits: []MusicCredit{
AlbumCredit{ MusicCredit{
Artist: &zaire, Artist: &zaire,
Role: "production", Role: "production",
}, },
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "production", Role: "production",
}, },
@ -405,7 +405,7 @@ var placeholders = []Album{
ReleaseDate: make_date_work("29-Sep-2019"), ReleaseDate: make_date_work("29-Sep-2019"),
Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_10.webp", Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_10.webp",
Buylink: "https://arimelody.bandcamp.com/track/10", Buylink: "https://arimelody.bandcamp.com/track/10",
Links: []AlbumLink{ Links: []MusicLink{
{ {
Name: "spotify", Name: "spotify",
Url: "https://open.spotify.com/album/2x4gbACfDm99unaXpLXyj0", Url: "https://open.spotify.com/album/2x4gbACfDm99unaXpLXyj0",
@ -423,12 +423,12 @@ var placeholders = []Album{
Url: "https://www.youtube.com/watch?v=C7WP5L2BK4U", Url: "https://www.youtube.com/watch?v=C7WP5L2BK4U",
}, },
}, },
Credits: []AlbumCredit{ Credits: []MusicCredit{
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "production", Role: "production",
}, },
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "artwork", Role: "artwork",
}, },
@ -441,7 +441,7 @@ var placeholders = []Album{
ReleaseDate: make_date_work("03-Nov-2018"), ReleaseDate: make_date_work("03-Nov-2018"),
Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_MAD.webp", Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_MAD.webp",
Buylink: "https://arimelody.bandcamp.com/track/mad", Buylink: "https://arimelody.bandcamp.com/track/mad",
Links: []AlbumLink{ Links: []MusicLink{
{ {
Name: "spotify", Name: "spotify",
Url: "https://open.spotify.com/album/59nFXw1WNoRhXou7lXqBZd", Url: "https://open.spotify.com/album/59nFXw1WNoRhXou7lXqBZd",
@ -459,16 +459,16 @@ var placeholders = []Album{
Url: "https://www.youtube.com/watch?v=OB-Pk6p6mfQ", Url: "https://www.youtube.com/watch?v=OB-Pk6p6mfQ",
}, },
}, },
Credits: []AlbumCredit{ Credits: []MusicCredit{
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "vocals", Role: "vocals",
}, },
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "production", Role: "production",
}, },
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "artwork", Role: "artwork",
}, },
@ -481,7 +481,7 @@ var placeholders = []Album{
ReleaseDate: make_date_work("01-Nov-2018"), ReleaseDate: make_date_work("01-Nov-2018"),
Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_Welcoming_Party.webp", Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_Welcoming_Party.webp",
Buylink: "https://arimelody.bandcamp.com/album/welcoming-party", Buylink: "https://arimelody.bandcamp.com/album/welcoming-party",
Links: []AlbumLink{ Links: []MusicLink{
{ {
Name: "spotify", Name: "spotify",
Url: "https://open.spotify.com/album/3EPa4HZpkISQVRAks64LfR", Url: "https://open.spotify.com/album/3EPa4HZpkISQVRAks64LfR",
@ -499,12 +499,12 @@ var placeholders = []Album{
Url: "https://www.youtube.com/playlist?list=PLBG_QJeOHrB5EeniiXBIlHpoQbD6CUJca", Url: "https://www.youtube.com/playlist?list=PLBG_QJeOHrB5EeniiXBIlHpoQbD6CUJca",
}, },
}, },
Credits: []AlbumCredit{ Credits: []MusicCredit{
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "production", Role: "production",
}, },
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "artwork", Role: "artwork",
}, },
@ -535,7 +535,7 @@ var placeholders = []Album{
Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_How_They_Know_2018.webp", Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_How_They_Know_2018.webp",
Buyname: "free download", Buyname: "free download",
Buylink: "https://arimelody.bandcamp.com/track/how-they-know-2018-remastered", Buylink: "https://arimelody.bandcamp.com/track/how-they-know-2018-remastered",
Links: []AlbumLink{ Links: []MusicLink{
{ {
Name: "soundcloud", Name: "soundcloud",
Url: "https://soundcloud.com/arimelody/how-they-know-2018", Url: "https://soundcloud.com/arimelody/how-they-know-2018",
@ -545,12 +545,12 @@ var placeholders = []Album{
Url: "https://www.youtube.com/watch?v=mbAgSwCzyMw", Url: "https://www.youtube.com/watch?v=mbAgSwCzyMw",
}, },
}, },
Credits: []AlbumCredit{ Credits: []MusicCredit{
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "production", Role: "production",
}, },
AlbumCredit{ MusicCredit{
Artist: &red, Artist: &red,
Role: "artwork", Role: "artwork",
Meta: true, Meta: true,
@ -565,7 +565,7 @@ var placeholders = []Album{
Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_How_They_Know.webp", Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_How_They_Know.webp",
Buyname: "free download", Buyname: "free download",
Buylink: "https://arimelody.bandcamp.com/track/how-they-know", Buylink: "https://arimelody.bandcamp.com/track/how-they-know",
Links: []AlbumLink{ Links: []MusicLink{
{ {
Name: "soundcloud", Name: "soundcloud",
Url: "https://soundcloud.com/arimelody/how-they-know", Url: "https://soundcloud.com/arimelody/how-they-know",
@ -575,12 +575,12 @@ var placeholders = []Album{
Url: "https://www.youtube.com/watch?v=q6lzKuG1Emo", Url: "https://www.youtube.com/watch?v=q6lzKuG1Emo",
}, },
}, },
Credits: []AlbumCredit{ Credits: []MusicCredit{
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "production", Role: "production",
}, },
AlbumCredit{ MusicCredit{
Artist: &red, Artist: &red,
Role: "artwork", Role: "artwork",
Meta: true, Meta: true,
@ -595,7 +595,7 @@ var placeholders = []Album{
Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_Traveller.webp", Artwork: "https://mellodoot.com/img/music_artwork/mellodoot_-_Traveller.webp",
Buyname: "free download", Buyname: "free download",
Buylink: "https://arimelody.bandcamp.com/track/traveller", Buylink: "https://arimelody.bandcamp.com/track/traveller",
Links: []AlbumLink{ Links: []MusicLink{
{ {
Name: "soundcloud", Name: "soundcloud",
Url: "https://soundcloud.com/arimelody/traveller", Url: "https://soundcloud.com/arimelody/traveller",
@ -606,12 +606,12 @@ var placeholders = []Album{
}, },
}, },
Description: "an 8-bit expedition! ⚔️🛡️", Description: "an 8-bit expedition! ⚔️🛡️",
Credits: []AlbumCredit{ Credits: []MusicCredit{
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "production", Role: "production",
}, },
AlbumCredit{ MusicCredit{
Artist: &mellodoot, Artist: &mellodoot,
Role: "artwork", Role: "artwork",
}, },
@ -619,16 +619,16 @@ var placeholders = []Album{
}, },
} }
func GetAlbum(id string) (Album, bool) { func GetAlbum(id string) (MusicRelease, bool) {
for _, album := range placeholders { for _, album := range placeholders {
if album.Id == id { if album.Id == id {
return album, true return album, true
} }
} }
return Album{}, false return MusicRelease{}, false
} }
func QueryAllAlbums() ([]Album) { func QueryAllAlbums() ([]MusicRelease) {
return placeholders return placeholders
} }

View file

@ -8,38 +8,38 @@ import (
type ( type (
Artist struct { Artist struct {
Id string; Id string
Name string; Name string
Website string; Website string
} }
Album struct { MusicRelease struct {
Id string; Id string
Title string; Title string
Type string; Type string
ReleaseDate time.Time; ReleaseDate time.Time
Artwork string; Artwork string
Buyname string; Buyname string
Buylink string; Buylink string
Links []AlbumLink; Links []MusicLink
Description string; Description string
Credits []AlbumCredit; Credits []MusicCredit
Lyrics string; Lyrics string
} }
AlbumLink struct { MusicLink struct {
Name string; Name string
Url string; Url string
} }
AlbumCredit struct { MusicCredit struct {
Artist *Artist; Artist *Artist
Role string; Role string
Meta bool; // for "meta" contributors (i.e. not credited for the musical work, but other related assets) Meta bool // for "meta" contributors (i.e. not credited for the musical work, but other related assets)
} }
) )
func (album Album) GetUniqueArtists() []Artist { func (album MusicRelease) GetUniqueArtists() []Artist {
if len(album.Credits) == 1 { if len(album.Credits) == 1 {
return []Artist{*album.Credits[0].Artist} return []Artist{*album.Credits[0].Artist}
} }
@ -65,7 +65,7 @@ func (album Album) GetUniqueArtists() []Artist {
return res return res
} }
func (album Album) GetUniqueNonMetaArtists() []Artist { func (album MusicRelease) GetUniqueNonMetaArtists() []Artist {
if len(album.Credits) == 1 { if len(album.Credits) == 1 {
return []Artist{*album.Credits[0].Artist} return []Artist{*album.Credits[0].Artist}
} }
@ -94,7 +94,7 @@ func (album Album) GetUniqueNonMetaArtists() []Artist {
return res return res
} }
func (album Album) GetUniqueArtistNames() []string { func (album MusicRelease) GetUniqueArtistNames() []string {
if len(album.Credits) == 1 { if len(album.Credits) == 1 {
return []string{album.Credits[0].Artist.Name} return []string{album.Credits[0].Artist.Name}
} }
@ -105,10 +105,10 @@ func (album Album) GetUniqueArtistNames() []string {
names = append(names, artist.Name) names = append(names, artist.Name)
} }
return names; return names
} }
func (album Album) GetUniqueNonMetaArtistNames() []string { func (album MusicRelease) GetUniqueNonMetaArtistNames() []string {
if len(album.Credits) == 1 { if len(album.Credits) == 1 {
return []string{album.Credits[0].Artist.Name} return []string{album.Credits[0].Artist.Name}
} }
@ -119,11 +119,11 @@ func (album Album) GetUniqueNonMetaArtistNames() []string {
names = append(names, artist.Name) names = append(names, artist.Name)
} }
return names; return names
} }
func (album Album) PrintPrimaryArtists() string { func (album MusicRelease) PrintPrimaryArtists() string {
names := album.GetUniqueNonMetaArtistNames(); names := album.GetUniqueNonMetaArtistNames()
if len(names) == 1 { if len(names) == 1 {
return names[0] return names[0]
} }
@ -132,41 +132,41 @@ func (album Album) PrintPrimaryArtists() string {
return res return res
} }
func (album Album) PrintCommaPrimaryArtists() string { func (album MusicRelease) PrintCommaPrimaryArtists() string {
names := album.GetUniqueNonMetaArtistNames(); names := album.GetUniqueNonMetaArtistNames()
if len(names) == 1 { if len(names) == 1 {
return names[0] return names[0]
} }
return strings.Join(names[:len(names)], ", ") return strings.Join(names[:], ", ")
} }
func (album Album) ResolveType() string { func (album MusicRelease) ResolveType() string {
if album.Type != "" { if album.Type != "" {
return album.Type return album.Type
} }
return "unknown" return "unknown"
} }
func (album Album) ResolveArtwork() string { func (album MusicRelease) ResolveArtwork() string {
if album.Artwork != "" { if album.Artwork != "" {
return album.Artwork return album.Artwork
} }
return "/img/music-artwork/default.png" return "/img/music-artwork/default.png"
} }
func (album Album) PrintReleaseDate() string { func (album MusicRelease) PrintReleaseDate() string {
return album.ReleaseDate.Format("02 January 2006") return album.ReleaseDate.Format("02 January 2006")
} }
func (album Album) GetReleaseYear() int { func (album MusicRelease) GetReleaseYear() int {
return album.ReleaseDate.Year() return album.ReleaseDate.Year()
} }
func (link AlbumLink) NormaliseName() string { func (link MusicLink) NormaliseName() string {
re := regexp.MustCompile(`[^a-z0-9]`) re := regexp.MustCompile(`[^a-z0-9]`)
return strings.ToLower(re.ReplaceAllString(link.Name, "")) return strings.ToLower(re.ReplaceAllString(link.Name, ""))
} }
func (credit AlbumCredit) ResolveArtist() Artist { func (credit MusicCredit) ResolveArtist() Artist {
return *credit.Artist return *credit.Artist
} }

38
db.go
View file

@ -12,13 +12,13 @@ import (
) )
var schema = var schema =
`CREATE TABLE IF NOT EXISTS Artists ( `CREATE TABLE IF NOT EXISTS artists (
id TEXT PRIMARY KEY, id TEXT PRIMARY KEY,
name TEXT, name TEXT,
website TEXT website TEXT
); );
CREATE TABLE IF NOT EXISTS Albums ( CREATE TABLE IF NOT EXISTS musicreleases (
id VARCHAR(64) PRIMARY KEY, id VARCHAR(64) PRIMARY KEY,
title TEXT NOT NULL, title TEXT NOT NULL,
type TEXT, type TEXT,
@ -30,19 +30,19 @@ CREATE TABLE IF NOT EXISTS Albums (
lyrics TEXT lyrics TEXT
); );
CREATE TABLE IF NOT EXISTS AlbumLinks ( CREATE TABLE IF NOT EXISTS musiclinks (
album VARCHAR(64) REFERENCES Albums(id) ON DELETE CASCADE ON UPDATE CASCADE, album VARCHAR(64) REFERENCES musicreleases(id) ON DELETE CASCADE ON UPDATE CASCADE,
name TEXT, name TEXT,
url TEXT, url TEXT,
CONSTRAINT albumlinks_pk PRIMARY KEY (album, name) CONSTRAINT musiclinks_pk PRIMARY KEY (album, name)
); );
CREATE TABLE IF NOT EXISTS AlbumCredits ( CREATE TABLE IF NOT EXISTS musiccredits (
album VARCHAR(64) REFERENCES Albums(ID) ON DELETE CASCADE, album VARCHAR(64) REFERENCES musicreleases(ID) ON DELETE CASCADE,
artist TEXT REFERENCES Artists(id) ON DELETE CASCADE, artist TEXT REFERENCES artists(id) ON DELETE CASCADE,
role TEXT, role TEXT,
meta BOOLEAN, meta BOOLEAN,
constraint albumcredits_pk PRIMARY KEY (album, artist, role) constraint musiccredits_pk PRIMARY KEY (album, artist, role)
);` );`
func PushArtist(db *sqlx.DB, artist music.Artist) { func PushArtist(db *sqlx.DB, artist music.Artist) {
@ -57,21 +57,21 @@ func PushArtist(db *sqlx.DB, artist music.Artist) {
fmt.Printf("done!\n") fmt.Printf("done!\n")
} }
func PushAlbum(db *sqlx.DB, album music.Album) { func PushRelease(db *sqlx.DB, release music.MusicRelease) {
fmt.Printf("syncing album [%s] to database...", album.Id) fmt.Printf("syncing release [%s] to database...", release.Id)
tx := db.MustBegin() tx := db.MustBegin()
tx.MustExec("INSERT INTO albums (id, title, release_date, artwork, buyname, buylink, description, lyrics) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) "+ tx.MustExec("INSERT INTO musicreleases (id, title, release_date, artwork, buyname, buylink, description, lyrics) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) "+
"ON CONFLICT (id) DO UPDATE SET title=$2, release_date=$3, artwork=$4, buyname=$5, buylink=$6, description=$7, lyrics=$8", "ON CONFLICT (id) DO UPDATE SET title=$2, release_date=$3, artwork=$4, buyname=$5, buylink=$6, description=$7, lyrics=$8",
&album.Id, &album.Title, album.ReleaseDate.Format("2-Jan-2006"), &album.Artwork, &album.Buyname, &album.Buylink, &album.Description, &album.Lyrics) &release.Id, &release.Title, release.ReleaseDate.Format("2-Jan-2006"), &release.Artwork, &release.Buyname, &release.Buylink, &release.Description, &release.Lyrics)
for _, link := range album.Links { for _, link := range release.Links {
tx.MustExec("INSERT INTO albumlinks (album, name, url) VALUES ($1, $2, $3) ON CONFLICT (album, name) DO UPDATE SET url=$3", tx.MustExec("INSERT INTO musiclinks (album, name, url) VALUES ($1, $2, $3) ON CONFLICT (album, name) DO UPDATE SET url=$3",
&album.Id, &link.Name, &link.Url) &release.Id, &link.Name, &link.Url)
} }
for _, credit := range album.Credits { for _, credit := range release.Credits {
tx.MustExec("INSERT INTO albumcredits (album, artist, role, meta) VALUES ($1, $2, $3, $4) ON CONFLICT DO NOTHING", tx.MustExec("INSERT INTO musiccredits (album, artist, role, meta) VALUES ($1, $2, $3, $4) ON CONFLICT DO NOTHING",
&album.Id, &credit.Artist.Id, &credit.Role, &credit.Meta) &release.Id, &credit.Artist.Id, &credit.Role, &credit.Meta)
} }
tx.Commit() tx.Commit()

View file

@ -186,7 +186,7 @@ func push_to_db_this_is_a_testing_thing_and_will_be_superfluous_later() {
} }
for _, album := range music.QueryAllAlbums() { for _, album := range music.QueryAllAlbums() {
PushAlbum(db, album) PushRelease(db, album)
} }
defer db.Close() defer db.Close()