mirror of
https://github.com/aditya-K2/gspt.git
synced 2026-01-08 21:37:58 -05:00
Refactor QueueSongsVisual
This commit is contained in:
11
ui/utils.go
11
ui/utils.go
@@ -71,6 +71,17 @@ func addToPlaylist(tracks []spotify.ID) {
|
||||
})
|
||||
}
|
||||
|
||||
func queueSongs(tracks []spotify.ID) {
|
||||
msg := SendNotificationWithChan(fmt.Sprintf("Queueing %d tracks...", len(tracks)))
|
||||
go func() {
|
||||
err := spt.QueueTracks(tracks...)
|
||||
if err != nil {
|
||||
msg <- err.Error()
|
||||
}
|
||||
msg <- fmt.Sprintf("Queued %d tracks!", len(tracks))
|
||||
}()
|
||||
}
|
||||
|
||||
func fileName(a spotify.SimpleAlbum) string {
|
||||
return fmt.Sprintf(filepath.Join(cfg.CacheDir, "%s.jpg"), a.ID)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/aditya-K2/gspt/spt"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/zmb3/spotify/v2"
|
||||
@@ -76,17 +74,10 @@ func (a *AlbumView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcel
|
||||
|
||||
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))
|
||||
}()
|
||||
queueSongs(Map(tracks,
|
||||
func(s spotify.SimpleTrack) spotify.ID {
|
||||
return s.ID
|
||||
}))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -62,17 +62,10 @@ func (l *LikedSongsView) AddToPlaylistVisual(start, end int, e *tcell.EventKey)
|
||||
|
||||
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))
|
||||
}()
|
||||
queueSongs(Map(tracks,
|
||||
func(s spotify.SavedTrack) spotify.ID {
|
||||
return s.ID
|
||||
}))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -74,17 +74,10 @@ func (p *PlaylistView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *t
|
||||
|
||||
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))
|
||||
}()
|
||||
queueSongs(Map(tracks,
|
||||
func(s spotify.PlaylistTrack) spotify.ID {
|
||||
return s.Track.ID
|
||||
}))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -51,17 +51,10 @@ func (r *RecentlyPlayedView) AddToPlaylistVisual(start, end int, e *tcell.EventK
|
||||
|
||||
func (r *RecentlyPlayedView) QueueSongsVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
||||
tracks := r.recentlyPlayed[start : end+1]
|
||||
msg := SendNotificationWithChan(fmt.Sprintf("Queueing %d tracks...", len(tracks)))
|
||||
go func() {
|
||||
err := spt.QueueTracks(Map(tracks,
|
||||
func(s spotify.RecentlyPlayedItem) spotify.ID {
|
||||
return s.Track.ID
|
||||
})...)
|
||||
if err != nil {
|
||||
msg <- err.Error()
|
||||
}
|
||||
msg <- fmt.Sprintf("Queued %d tracks!", len(tracks))
|
||||
}()
|
||||
queueSongs(Map(tracks,
|
||||
func(s spotify.RecentlyPlayedItem) spotify.ID {
|
||||
return s.Track.ID
|
||||
}))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user