-
Notifications
You must be signed in to change notification settings - Fork 2
/
menu_utils.go
48 lines (42 loc) · 1.39 KB
/
menu_utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package utils
import (
"strings"
"github.com/anhoder/foxful-cli/model"
"github.com/zmb3/spotify/v2"
)
func MenuItemsFromSongs(songs []spotify.FullTrack) []model.MenuItem {
var menus []model.MenuItem
for _, song := range songs {
var artists []string
for _, a := range song.Artists {
artists = append(artists, a.Name)
}
menus = append(menus, model.MenuItem{Title: ReplaceSpecialStr(song.Name), Subtitle: ReplaceSpecialStr(strings.Join(artists, ","))})
}
return menus
}
func MenuItemsFromAlbums(albums []spotify.SimpleAlbum) []model.MenuItem {
var menus []model.MenuItem
for _, album := range albums {
menus = append(menus, model.MenuItem{Title: ReplaceSpecialStr(album.Name), Subtitle: "[" + ReplaceSpecialStr(ArtistNameStrOfAlbum(&album)) + "]"})
}
return menus
}
func MenuItemsFromArtists(artists []spotify.SimpleArtist) []model.MenuItem {
var menus []model.MenuItem
for _, artist := range artists {
menus = append(menus, model.MenuItem{Title: ReplaceSpecialStr(artist.Name)})
}
return menus
}
func MenuItemsFromPlaylists(playlists []spotify.SimplePlaylist) []model.MenuItem {
var menus []model.MenuItem
for _, playlist := range playlists {
var owner string
if playlist.Owner.DisplayName != "" {
owner = "[" + playlist.Owner.DisplayName + "]"
}
menus = append(menus, model.MenuItem{Title: ReplaceSpecialStr(playlist.Name), Subtitle: ReplaceSpecialStr(owner)})
}
return menus
}