Implement QueueSongsVisual for liked_songs_view

This commit is contained in:
aditya-K2
2023-12-17 15:01:00 +05:30
parent 09acc39ead
commit ca21280734
3 changed files with 18 additions and 0 deletions

View File

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

View File

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

View File

@@ -60,6 +60,22 @@ func (l *LikedSongsView) AddToPlaylistVisual(start, end int, e *tcell.EventKey)
return nil
}
func (l *LikedSongsView) QueueSongsVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
tracks := (*l.likedSongs)[start : end+1]
msg := SendNotificationWithChan(fmt.Sprintf("Queueing %d tracks...", len(tracks)))
go func() {
err := spt.QueueTracks(Map(tracks,
func(s spotify.SavedTrack) spotify.ID {
return s.ID
})...)
if err != nil {
msg <- err.Error()
}
msg <- fmt.Sprintf("Queued %d tracks!", len(tracks))
}()
return nil
}
func (l *LikedSongsView) OpenEntry() {
r, _ := Main.GetSelection()
if err := spt.PlaySong((*l.likedSongs)[r].URI); err != nil {