Implement QueueSongsVisual for album_view

This commit is contained in:
aditya-K2
2023-12-17 14:46:27 +05:30
parent 3b1bf3dc4c
commit 9e4d9a97ee
3 changed files with 20 additions and 0 deletions

View File

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

View File

@@ -370,6 +370,7 @@ func NewApplication() *tview.Application {
// Visual Actions
albumView.SetVisualActions(map[string]func(start, end int, e *tcell.EventKey) *tcell.EventKey{
"add_to_playlist": albumView.AddToPlaylistVisual,
"queue_entry": albumView.QueueSongsVisual,
})
recentlyPlayedView.SetVisualActions(map[string]func(start, end int, e *tcell.EventKey) *tcell.EventKey{
"add_to_playlist": recentlyPlayedView.AddToPlaylistVisual,

View File

@@ -1,6 +1,8 @@
package ui
import (
"fmt"
"github.com/aditya-K2/gspt/spt"
"github.com/gdamore/tcell/v2"
"github.com/zmb3/spotify/v2"
@@ -72,6 +74,22 @@ func (a *AlbumView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcel
return nil
}
func (a *AlbumView) QueueSongsVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
tracks := (*(*a.currentFullAlbum).Tracks)[start : end+1]
msg := SendNotificationWithChan(fmt.Sprintf("Queueing %d tracks...", len(tracks)))
go func() {
err := spt.QueueTracks(Map(tracks,
func(s spotify.SimpleTrack) spotify.ID {
return s.ID
})...)
if err != nil {
msg <- err.Error()
}
msg <- fmt.Sprintf("Queued %d tracks!", len(tracks))
}()
return nil
}
func (a *AlbumView) OpenEntry() {
r, _ := Main.GetSelection()
if err := spt.PlaySongWithContext(a.currentFullAlbum.URI, r); err != nil {