From ac7fd68e4fd635d05f1d17cc0ffc7f417d129013 Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Sat, 13 May 2023 00:17:17 +0530 Subject: [PATCH] Check if Artist is actually available --- ui/cover_art.go | 4 ++++ ui/progress.go | 2 +- ui/utils.go | 19 +++++++++++++++++++ ui/view_album.go | 2 +- ui/view_albums.go | 2 +- ui/view_artist.go | 4 ++-- ui/view_liked.go | 2 +- ui/view_playlist.go | 2 +- ui/view_recent.go | 2 +- ui/view_search.go | 4 ++-- ui/view_top.go | 14 +------------- 11 files changed, 34 insertions(+), 23 deletions(-) diff --git a/ui/cover_art.go b/ui/cover_art.go index 54d00ad..e854dc0 100644 --- a/ui/cover_art.go +++ b/ui/cover_art.go @@ -79,6 +79,10 @@ func (c *CoverArt) RefreshState() { }() return } + if len(state.Item.Album.Images) == 0 { + SendNotification("No Cover Art found for album: %s!", state.Item.Album.Name) + return + } err = state.Item.Album.Images[0].Download(f) if err != nil { go func() { diff --git a/ui/progress.go b/ui/progress.go index 37dadf0..ffdd871 100644 --- a/ui/progress.go +++ b/ui/progress.go @@ -156,7 +156,7 @@ func progressFunc() (string, string, string, float64) { if state.Item != nil { barTitle = fmt.Sprintf("%s%s[-:-:-] - %s%s", cfg.Colors.PBarTrack.String(), state.Item.Name, - cfg.Colors.PBarArtist.String(), state.Item.Artists[0].Name) + cfg.Colors.PBarArtist.String(), artistName(state.Item.Artists)) barText = utils.StrTime(float64(state.Progress/1000)) + "/" + utils.StrTime(float64(state.Item.Duration/1000)) percentage = (float64(state.Progress) / float64(state.Item.Duration)) * 100 } diff --git a/ui/utils.go b/ui/utils.go index d351695..53438f3 100644 --- a/ui/utils.go +++ b/ui/utils.go @@ -108,3 +108,22 @@ func openCurrentAlbum() { App.SetFocus(Main) } } + +func mergeGenres(g []string) string { + s := "" + for k, v := range g { + sep := "," + if k == 0 { + sep = "" + } + s += sep + v + } + return s +} + +func artistName(s []spotify.SimpleArtist) string { + if len(s) != 0 { + return s[0].Name + } + return "" +} diff --git a/ui/view_album.go b/ui/view_album.go index ce874af..2fd1cb4 100644 --- a/ui/view_album.go +++ b/ui/view_album.go @@ -48,7 +48,7 @@ func (a *AlbumView) Content() func() [][]Content { for _, v := range *(*a.currentFullAlbum).Tracks { ca := make([]Content, 0) ca = append(ca, Content{v.Name, TrackStyle}) - ca = append(ca, Content{v.Artists[0].Name, ArtistStyle}) + ca = append(ca, Content{artistName(v.Artists), ArtistStyle}) ca = append(ca, Content{a.currentAlbumName, AlbumStyle}) c = append(c, ca) } diff --git a/ui/view_albums.go b/ui/view_albums.go index 65f763d..d85d2af 100644 --- a/ui/view_albums.go +++ b/ui/view_albums.go @@ -37,7 +37,7 @@ func (a *AlbumsView) Content() func() [][]Content { for _, v := range *a.savedAlbums { c = append(c, []Content{ {Content: v.Name, Style: AlbumStyle}, - {Content: v.Artists[0].Name, Style: ArtistStyle}, + {Content: artistName(v.Artists), Style: ArtistStyle}, {Content: v.ReleaseDate, Style: TimeStyle}, }) } diff --git a/ui/view_artist.go b/ui/view_artist.go index a959a77..d8cb668 100644 --- a/ui/view_artist.go +++ b/ui/view_artist.go @@ -55,7 +55,7 @@ func (a *ArtistView) Content() func() [][]Content { for _, v := range a.albums { c = append(c, []Content{ {Content: v.Name, Style: AlbumStyle}, - {Content: v.Artists[0].Name, Style: ArtistStyle}, + {Content: artistName(v.Artists), Style: ArtistStyle}, {Content: v.ReleaseDate, Style: TimeStyle}, }) } @@ -63,7 +63,7 @@ func (a *ArtistView) Content() func() [][]Content { for _, v := range a.topTracks { c = append(c, []Content{ {Content: v.Name, Style: TrackStyle}, - {Content: v.Artists[0].Name, Style: ArtistStyle}, + {Content: artistName(v.Artists), Style: ArtistStyle}, {Content: v.Album.Name, Style: AlbumStyle}, }) } diff --git a/ui/view_liked.go b/ui/view_liked.go index bc4b046..ae35ccd 100644 --- a/ui/view_liked.go +++ b/ui/view_liked.go @@ -36,7 +36,7 @@ func (p *LikedSongsView) Content() func() [][]Content { for _, v := range *p.likedSongs { c = append(c, []Content{ {Content: v.Name, Style: TrackStyle}, - {Content: v.Artists[0].Name, Style: ArtistStyle}, + {Content: artistName(v.Artists), Style: ArtistStyle}, {Content: v.Album.Name, Style: AlbumStyle}, }) } diff --git a/ui/view_playlist.go b/ui/view_playlist.go index 113106a..a017531 100644 --- a/ui/view_playlist.go +++ b/ui/view_playlist.go @@ -47,7 +47,7 @@ func (p *PlaylistView) Content() func() [][]Content { for _, v := range *(*p.currentUserFullPlaylist).Tracks { c = append(c, []Content{ {Content: v.Track.Name, Style: TrackStyle}, - {Content: v.Track.Artists[0].Name, Style: ArtistStyle}, + {Content: artistName(v.Track.Artists), Style: ArtistStyle}, {Content: v.Track.Album.Name, Style: AlbumStyle}, }) } diff --git a/ui/view_recent.go b/ui/view_recent.go index 032c65a..024a576 100644 --- a/ui/view_recent.go +++ b/ui/view_recent.go @@ -26,7 +26,7 @@ func (r *RecentlyPlayedView) Content() func() [][]Content { for _, v := range r.recentlyPlayed { c = append(c, []Content{ {Content: v.Track.Name, Style: TrackStyle}, - {Content: v.Track.Artists[0].Name, Style: ArtistStyle}, + {Content: artistName(v.Track.Artists), Style: ArtistStyle}, {Content: utils.StrTime(float64(v.Track.Duration / 1000)), Style: TimeStyle}, }) } diff --git a/ui/view_search.go b/ui/view_search.go index 1a4f271..cbd41fc 100644 --- a/ui/view_search.go +++ b/ui/view_search.go @@ -46,7 +46,7 @@ func (a *SearchView) Content() func() [][]Content { } c = append(c, []Content{ {Content: v.Name, Style: TrackStyle}, - {Content: v.Artists[0].Name, Style: ArtistStyle}, + {Content: artistName(v.Artists), Style: ArtistStyle}, {Content: v.Album.Name, Style: AlbumStyle}, }) } @@ -62,7 +62,7 @@ func (a *SearchView) Content() func() [][]Content { } c = append(c, []Content{ {Content: v.Name, Style: AlbumStyle}, - {Content: v.Artists[0].Name, Style: ArtistStyle}, + {Content: artistName(v.Artists), Style: ArtistStyle}, {Content: v.ReleaseDate, Style: TimeStyle}, }) } diff --git a/ui/view_top.go b/ui/view_top.go index 1d03c60..b0fe8b7 100644 --- a/ui/view_top.go +++ b/ui/view_top.go @@ -35,18 +35,6 @@ func (a *TopTracksView) RefreshState() { a.topArtists = artists } -func mergeGenres(g []string) string { - s := "" - for k, v := range g { - sep := "," - if k == 0 { - sep = "" - } - s += sep + v - } - return s -} - func (a *TopTracksView) Content() func() [][]Content { return func() [][]Content { c := make([][]Content, 0) @@ -61,7 +49,7 @@ func (a *TopTracksView) Content() func() [][]Content { for _, v := range a.topTracks { c = append(c, []Content{ {Content: v.Name, Style: TrackStyle}, - {Content: v.Artists[0].Name, Style: ArtistStyle}, + {Content: artistName(v.Artists), Style: ArtistStyle}, {Content: v.Album.Name, Style: AlbumStyle}, }) }