Refactor QueueSongsVisual

This commit is contained in:
aditya-K2
2023-12-17 15:10:36 +05:30
parent 1893d144fd
commit 1076cb816f
5 changed files with 27 additions and 46 deletions

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}