mirror of
https://github.com/aditya-K2/gspt.git
synced 2026-01-09 13:58:05 -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 {
|
func fileName(a spotify.SimpleAlbum) string {
|
||||||
return fmt.Sprintf(filepath.Join(cfg.CacheDir, "%s.jpg"), a.ID)
|
return fmt.Sprintf(filepath.Join(cfg.CacheDir, "%s.jpg"), a.ID)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/aditya-K2/gspt/spt"
|
"github.com/aditya-K2/gspt/spt"
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
"github.com/zmb3/spotify/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 {
|
func (a *AlbumView) QueueSongsVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
||||||
tracks := (*(*a.currentFullAlbum).Tracks)[start : end+1]
|
tracks := (*(*a.currentFullAlbum).Tracks)[start : end+1]
|
||||||
msg := SendNotificationWithChan(fmt.Sprintf("Queueing %d tracks...", len(tracks)))
|
queueSongs(Map(tracks,
|
||||||
go func() {
|
func(s spotify.SimpleTrack) spotify.ID {
|
||||||
err := spt.QueueTracks(Map(tracks,
|
return s.ID
|
||||||
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
|
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 {
|
func (l *LikedSongsView) QueueSongsVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
||||||
tracks := (*l.likedSongs)[start : end+1]
|
tracks := (*l.likedSongs)[start : end+1]
|
||||||
msg := SendNotificationWithChan(fmt.Sprintf("Queueing %d tracks...", len(tracks)))
|
queueSongs(Map(tracks,
|
||||||
go func() {
|
func(s spotify.SavedTrack) spotify.ID {
|
||||||
err := spt.QueueTracks(Map(tracks,
|
return s.ID
|
||||||
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
|
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 {
|
func (p *PlaylistView) QueueSongsVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
||||||
tracks := (*(*p.currentUserFullPlaylist).Tracks)[start : end+1]
|
tracks := (*(*p.currentUserFullPlaylist).Tracks)[start : end+1]
|
||||||
msg := SendNotificationWithChan(fmt.Sprintf("Queueing %d tracks...", len(tracks)))
|
queueSongs(Map(tracks,
|
||||||
go func() {
|
func(s spotify.PlaylistTrack) spotify.ID {
|
||||||
err := spt.QueueTracks(Map(tracks,
|
return s.Track.ID
|
||||||
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
|
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 {
|
func (r *RecentlyPlayedView) QueueSongsVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
||||||
tracks := r.recentlyPlayed[start : end+1]
|
tracks := r.recentlyPlayed[start : end+1]
|
||||||
msg := SendNotificationWithChan(fmt.Sprintf("Queueing %d tracks...", len(tracks)))
|
queueSongs(Map(tracks,
|
||||||
go func() {
|
func(s spotify.RecentlyPlayedItem) spotify.ID {
|
||||||
err := spt.QueueTracks(Map(tracks,
|
return s.Track.ID
|
||||||
func(s spotify.RecentlyPlayedItem) spotify.ID {
|
}))
|
||||||
return s.Track.ID
|
|
||||||
})...)
|
|
||||||
if err != nil {
|
|
||||||
msg <- err.Error()
|
|
||||||
}
|
|
||||||
msg <- fmt.Sprintf("Queued %d tracks!", len(tracks))
|
|
||||||
}()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user