mirror of
https://github.com/aditya-K2/gspt.git
synced 2026-01-09 13:58:05 -05:00
Implement addToPlaylist for some views
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/aditya-K2/gspt/spt"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/zmb3/spotify/v2"
|
||||
)
|
||||
|
||||
@@ -59,30 +60,18 @@ func (a *AlbumView) Content() func() [][]Content {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *AlbumView) ContextHandler() func(start, end, sel int) {
|
||||
return func(start, end, sel int) {
|
||||
// Assuming that there are no external effects on the user's playlists
|
||||
// (i.e Any Creation or Deletion of Playlists while the context Menu is
|
||||
// open
|
||||
// TODO: Better Error Handler
|
||||
userPlaylists, ch := spt.CurrentUserPlaylists()
|
||||
err := <-ch
|
||||
if err != nil {
|
||||
SendNotification("Error Retrieving User Playlists")
|
||||
}
|
||||
sp := (*userPlaylists)[sel]
|
||||
tracks := make([]spotify.ID, 0)
|
||||
for k := start; k <= end; k++ {
|
||||
tracks = append(tracks, (*(*a.currentFullAlbum).Tracks)[k].ID)
|
||||
}
|
||||
aerr := spt.AddTracksToPlaylist(sp.ID, tracks...)
|
||||
if aerr != nil {
|
||||
SendNotification(aerr.Error())
|
||||
return
|
||||
} else {
|
||||
SendNotification(fmt.Sprintf("Added %d tracks to %s", len(tracks), sp.Name))
|
||||
}
|
||||
func (a *AlbumView) AddToPlaylist() {
|
||||
r, _ := Main.Table.GetSelection()
|
||||
addToPlaylist([]spotify.ID{(*(*a.currentFullAlbum).Tracks)[r].ID})
|
||||
}
|
||||
|
||||
func (a *AlbumView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
||||
tracks := make([]spotify.ID, 0)
|
||||
for k := start; k <= end; k++ {
|
||||
tracks = append(tracks, (*(*a.currentFullAlbum).Tracks)[k].ID)
|
||||
}
|
||||
addToPlaylist(tracks)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *AlbumView) PlaySelectEntry() {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/aditya-K2/gspt/spt"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/zmb3/spotify/v2"
|
||||
)
|
||||
|
||||
@@ -46,30 +45,18 @@ func (p *LikedSongsView) Content() func() [][]Content {
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LikedSongsView) ContextHandler() func(start, end, sel int) {
|
||||
return func(start, end, sel int) {
|
||||
// Assuming that there are no external effects on the user's playlists
|
||||
// (i.e Any Creation or Deletion of Playlists while the context Menu is
|
||||
// open
|
||||
// TODO: Better Error Handler
|
||||
userPlaylists, ch := spt.CurrentUserPlaylists()
|
||||
err := <-ch
|
||||
if err != nil {
|
||||
SendNotification("Error Retrieving User Playlists")
|
||||
return
|
||||
}
|
||||
tracks := make([]spotify.ID, 0)
|
||||
for k := start; k <= end; k++ {
|
||||
tracks = append(tracks, (*l.likedSongs)[k].ID)
|
||||
}
|
||||
aerr := spt.AddTracksToPlaylist((*userPlaylists)[sel].ID, tracks...)
|
||||
if aerr != nil {
|
||||
SendNotification(aerr.Error())
|
||||
return
|
||||
} else {
|
||||
SendNotification(fmt.Sprintf("Added %d tracks to %s", len(tracks), (*userPlaylists)[sel].Name))
|
||||
}
|
||||
func (l *LikedSongsView) AddToPlaylist() {
|
||||
r, _ := Main.Table.GetSelection()
|
||||
addToPlaylist([]spotify.ID{(*l.likedSongs)[r].ID})
|
||||
}
|
||||
|
||||
func (l *LikedSongsView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
||||
tracks := make([]spotify.ID, 0)
|
||||
for k := start; k <= end; k++ {
|
||||
tracks = append(tracks, (*l.likedSongs)[k].ID)
|
||||
}
|
||||
addToPlaylist(tracks)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LikedSongsView) OpenEntry() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/aditya-K2/gspt/spt"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/zmb3/spotify/v2"
|
||||
)
|
||||
|
||||
@@ -58,30 +59,18 @@ func (p *PlaylistView) Content() func() [][]Content {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PlaylistView) ContextHandler() func(start, end, sel int) {
|
||||
return func(start, end, sel int) {
|
||||
// Assuming that there are no external effects on the user's playlists
|
||||
// (i.e Any Creation or Deletion of Playlists while the context Menu is
|
||||
// open
|
||||
// TODO: Better Error Handling
|
||||
userPlaylists, ch := spt.CurrentUserPlaylists()
|
||||
err := <-ch
|
||||
if err != nil {
|
||||
SendNotification("Error Retrieving User Playlists")
|
||||
return
|
||||
}
|
||||
tracks := make([]spotify.ID, 0)
|
||||
for k := start; k <= end; k++ {
|
||||
tracks = append(tracks, (*(*p.currentUserFullPlaylist).Tracks)[k].Track.ID)
|
||||
}
|
||||
aerr := spt.AddTracksToPlaylist((*userPlaylists)[sel].ID, tracks...)
|
||||
if aerr != nil {
|
||||
SendNotification(aerr.Error())
|
||||
return
|
||||
} else {
|
||||
SendNotification(fmt.Sprintf("Added %d tracks to %s", len(tracks), (*userPlaylists)[sel].Name))
|
||||
}
|
||||
func (p *PlaylistView) AddToPlaylist() {
|
||||
r, _ := Main.Table.GetSelection()
|
||||
addToPlaylist([]spotify.ID{(*(*p.currentUserFullPlaylist).Tracks)[r].Track.ID})
|
||||
}
|
||||
|
||||
func (p *PlaylistView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
||||
tracks := make([]spotify.ID, 0)
|
||||
for k := start; k <= end; k++ {
|
||||
tracks = append(tracks, (*(*p.currentUserFullPlaylist).Tracks)[k].Track.ID)
|
||||
}
|
||||
addToPlaylist(tracks)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PlaylistView) PlaySelectEntry() {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/aditya-K2/gspt/spt"
|
||||
"github.com/aditya-K2/utils"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
@@ -42,30 +40,18 @@ func (r *RecentlyPlayedView) Content() func() [][]Content {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RecentlyPlayedView) ContextHandler() func(start, end, sel int) {
|
||||
return func(start, end, sel int) {
|
||||
// Assuming that there are no external effects on the user's playlists
|
||||
// (i.e Any Creation or Deletion of Playlists while the context Menu is
|
||||
// open
|
||||
// TODO: Better Error Handler
|
||||
userPlaylists, ch := spt.CurrentUserPlaylists()
|
||||
err := <-ch
|
||||
if err != nil {
|
||||
SendNotification("Error Retrieving User Playlists")
|
||||
return
|
||||
}
|
||||
tracks := make([]spotify.ID, 0)
|
||||
for k := start; k <= end; k++ {
|
||||
tracks = append(tracks, r.recentlyPlayed[k].Track.ID)
|
||||
}
|
||||
aerr := spt.AddTracksToPlaylist((*userPlaylists)[sel].ID, tracks...)
|
||||
if aerr != nil {
|
||||
SendNotification(aerr.Error())
|
||||
return
|
||||
} else {
|
||||
SendNotification(fmt.Sprintf("Added %d tracks to %s", len(tracks), (*userPlaylists)[sel].Name))
|
||||
}
|
||||
func (r *RecentlyPlayedView) AddToPlaylist() {
|
||||
_r, _ := Main.Table.GetSelection()
|
||||
addToPlaylist([]spotify.ID{r.recentlyPlayed[_r].Track.ID})
|
||||
}
|
||||
|
||||
func (r *RecentlyPlayedView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
||||
tracks := make([]spotify.ID, 0)
|
||||
for k := start; k <= end; k++ {
|
||||
tracks = append(tracks, r.recentlyPlayed[k].Track.ID)
|
||||
}
|
||||
addToPlaylist(tracks)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RecentlyPlayedView) Name() string { return "RecentlyPlayedView" }
|
||||
|
||||
Reference in New Issue
Block a user