Implement QueueSongsVisual for playlist_view

This commit is contained in:
aditya-K2
2023-12-17 14:57:21 +05:30
parent 9f73b4bb06
commit 09acc39ead
3 changed files with 18 additions and 0 deletions

View File

@@ -66,6 +66,7 @@ var (
},
"visual": {
{R: 'a'}: "add_to_playlist",
{R: 'q'}: "queue_entry",
},
},
"top_tracks_view": {

View File

@@ -378,6 +378,7 @@ func NewApplication() *tview.Application {
})
playlistView.SetVisualActions(map[string]func(start, end int, e *tcell.EventKey) *tcell.EventKey{
"add_to_playlist": playlistView.AddToPlaylistVisual,
"queue_entry": playlistView.QueueSongsVisual,
})
likedSongsView.SetVisualActions(map[string]func(start, end int, e *tcell.EventKey) *tcell.EventKey{
"add_to_playlist": likedSongsView.AddToPlaylistVisual,

View File

@@ -72,6 +72,22 @@ func (p *PlaylistView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *t
return nil
}
func (p *PlaylistView) QueueSongsVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
tracks := (*(*p.currentUserFullPlaylist).Tracks)[start : end+1]
msg := SendNotificationWithChan(fmt.Sprintf("Queueing %d tracks...", len(tracks)))
go func() {
err := spt.QueueTracks(Map(tracks,
func(s spotify.PlaylistTrack) spotify.ID {
return s.Track.ID
})...)
if err != nil {
msg <- err.Error()
}
msg <- fmt.Sprintf("Queued %d tracks!", len(tracks))
}()
return nil
}
func (p *PlaylistView) OpenEntry() {
r, _ := Main.GetSelection()
if err := spt.PlaySongWithContext(p.currentPlaylist.URI, r); err != nil {