diff --git a/src/cmd/clearradio.go b/src/cmd/clearradio.go index 5110224..b9bb903 100644 --- a/src/cmd/clearradio.go +++ b/src/cmd/clearradio.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -15,6 +13,6 @@ var clearRadioCmd = &cobra.Command{ Short: "Wipes the radio playlist and creates an empty one", Long: `Wipes the radio playlist and creates an empty one, mostly for debugging or if something goes wrong`, Run: func(cmd *cobra.Command, args []string) { - commands.ClearRadio(ctx, client) + commands.ClearRadio(ctx) }, } diff --git a/src/cmd/devices.go b/src/cmd/devices.go index 71c9677..044d34c 100644 --- a/src/cmd/devices.go +++ b/src/cmd/devices.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -15,6 +13,6 @@ var devicesCmd = &cobra.Command{ Short: "Prints out devices", Long: `Prints out devices`, Run: func(cmd *cobra.Command, args []string) { - commands.Devices(ctx, client) + commands.Devices(ctx) }, } diff --git a/src/cmd/like.go b/src/cmd/like.go index db42e3e..62c71e9 100644 --- a/src/cmd/like.go +++ b/src/cmd/like.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -16,6 +14,6 @@ var likeCmd = &cobra.Command{ Short: "Likes song", Long: `Likes song`, Run: func(cmd *cobra.Command, args []string) { - commands.Like(ctx, client) + commands.Like(ctx) }, } diff --git a/src/cmd/link.go b/src/cmd/link.go index bd19458..c1a97d6 100644 --- a/src/cmd/link.go +++ b/src/cmd/link.go @@ -4,8 +4,6 @@ import ( "fmt" "os" - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -16,7 +14,7 @@ var linkCmd = &cobra.Command{ Short: "Print link to currently playing song", Long: `Print link to currently playing song`, Run: func(cmd *cobra.Command, args []string) { - link, err := commands.Link(ctx, client) + link, err := commands.Link(ctx) if err != nil { fmt.Println(err) os.Exit(1) diff --git a/src/cmd/linkcontext.go b/src/cmd/linkcontext.go index e2992e6..97386d7 100644 --- a/src/cmd/linkcontext.go +++ b/src/cmd/linkcontext.go @@ -4,8 +4,6 @@ import ( "fmt" "os" - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -16,7 +14,7 @@ var linkContextCmd = &cobra.Command{ Short: "Get url to current context(album, playlist)", Long: `Get url to current context(album, playlist)`, Run: func(cmd *cobra.Command, args []string) { - link, err := commands.LinkContext(ctx, client) + link, err := commands.LinkContext(ctx) if err != nil { fmt.Println(err) os.Exit(1) diff --git a/src/cmd/mute.go b/src/cmd/mute.go index ef999f9..1754009 100644 --- a/src/cmd/mute.go +++ b/src/cmd/mute.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -15,7 +13,7 @@ var muteCmd = &cobra.Command{ Short: "mutes playback", Long: `Mutes the spotify device, playback will continue`, RunE: func(cmd *cobra.Command, args []string) error { - err := commands.SetVolume(ctx, client, 0) + err := commands.SetVolume(ctx, 0) if err != nil { return err } diff --git a/src/cmd/next.go b/src/cmd/next.go index 792d8d3..d5c9f72 100644 --- a/src/cmd/next.go +++ b/src/cmd/next.go @@ -3,8 +3,6 @@ package cmd import ( "strconv" - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -27,6 +25,6 @@ var nextCmd = &cobra.Command{ return err } } - return commands.Next(ctx, client, skipAmt) + return commands.Next(ctx, skipAmt) }, } diff --git a/src/cmd/nowplaying.go b/src/cmd/nowplaying.go index 85fb560..4974a39 100644 --- a/src/cmd/nowplaying.go +++ b/src/cmd/nowplaying.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -16,6 +14,6 @@ var nowPlayingCmd = &cobra.Command{ Short: "Shows song and artist of currently playing song", Long: `Shows song and artist of currently playing song, useful for scripting`, Run: func(cmd *cobra.Command, args []string) { - commands.NowPlaying(ctx, client) + commands.NowPlaying(ctx) }, } diff --git a/src/cmd/pause.go b/src/cmd/pause.go index 63ae064..a9c77c6 100644 --- a/src/cmd/pause.go +++ b/src/cmd/pause.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -16,6 +14,6 @@ var pauseCmd = &cobra.Command{ Aliases: []string{"pa"}, Long: `Pauses currently playing song on spotify`, Run: func(cmd *cobra.Command, args []string) { - commands.Pause(ctx, client) + commands.Pause(ctx) }, } diff --git a/src/cmd/play.go b/src/cmd/play.go index a3c1f3c..f3e69fa 100644 --- a/src/cmd/play.go +++ b/src/cmd/play.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -16,6 +14,6 @@ var playCmd = &cobra.Command{ Short: "Plays spotify", Long: `Plays queued song on spotify, uses last used device and activates it if needed`, Run: func(cmd *cobra.Command, args []string) { - commands.Play(ctx, client) + commands.Play(ctx) }, } diff --git a/src/cmd/playurl.go b/src/cmd/playurl.go index d573533..5307e15 100644 --- a/src/cmd/playurl.go +++ b/src/cmd/playurl.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -16,6 +14,6 @@ var playurlCmd = &cobra.Command{ Args: cobra.MatchAll(cobra.ExactArgs(1)), Long: `Plays song from provided url`, Run: func(cmd *cobra.Command, args []string) { - commands.PlayUrl(ctx, client, args) + commands.PlayUrl(ctx, args) }, } diff --git a/src/cmd/previous.go b/src/cmd/previous.go index 2756d05..503eba5 100644 --- a/src/cmd/previous.go +++ b/src/cmd/previous.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -16,6 +14,6 @@ var previousCmd = &cobra.Command{ Short: "goes to previous song", Long: `if song is playing it will start over, if close to begining of song it will go to previous song`, Run: func(cmd *cobra.Command, args []string) { - commands.Previous(ctx, client) + commands.Previous(ctx) }, } diff --git a/src/cmd/radio.go b/src/cmd/radio.go index e28cc50..c9d62ff 100644 --- a/src/cmd/radio.go +++ b/src/cmd/radio.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -16,6 +14,6 @@ var radioCmd = &cobra.Command{ Short: "Starts radio", Long: `Starts radio`, RunE: func(cmd *cobra.Command, args []string) error { - return commands.Radio(ctx, client) + return commands.Radio(ctx) }, } diff --git a/src/cmd/refillradio.go b/src/cmd/refillradio.go index e6bea38..c053126 100644 --- a/src/cmd/refillradio.go +++ b/src/cmd/refillradio.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -16,6 +14,6 @@ var refillRadioCmd = &cobra.Command{ Short: "Refills the radio", Long: `Deletes all songs up to your position in the radio and adds that many songs to the end of the radio`, RunE: func(cmd *cobra.Command, args []string) error { - return commands.RefillRadio(ctx, client) + return commands.RefillRadio(ctx) }, } diff --git a/src/cmd/repeat.go b/src/cmd/repeat.go index b9fd607..54fa9cc 100644 --- a/src/cmd/repeat.go +++ b/src/cmd/repeat.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -15,6 +13,6 @@ var repeatCmd = &cobra.Command{ Short: "Toggles repeat", Long: `Switches between repeating your current context or not, spotifyd does not support single track loops`, Run: func(cmd *cobra.Command, args []string) { - commands.Repeat(ctx, client) + commands.Repeat(ctx) }, } diff --git a/src/cmd/root.go b/src/cmd/root.go index 8185e58..bfe1e12 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -1,12 +1,15 @@ package cmd import ( + "context" "fmt" "os" "os/exec" "path/filepath" "strings" + cmds "gitea.asdf.cafe/abs3nt/gospt/src/commands" + "gitea.asdf.cafe/abs3nt/gospt/src/config" "gitea.asdf.cafe/abs3nt/gospt/src/gctx" "tuxpa.in/a/zlog" @@ -19,7 +22,7 @@ import ( var ( // Used for flags. ctx *gctx.Context - commands *commands.Commands + commands *cmds.Commands cfgFile string userLicense string verbose bool @@ -51,14 +54,14 @@ func init() { } } rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose logging") - cobra.OnInitialize(func() { if verbose { zlog.SetGlobalLevel(zlog.TraceLevel) } }) - cobra.OnInitialize(initConfig, initClient) - + ctx = gctx.NewContext(context.Background()) + commands = &cmds.Commands{Context: ctx} + cobra.OnInitialize(initConfig) } func initConfig() { diff --git a/src/cmd/seek.go b/src/cmd/seek.go index 0238ac5..f0bb931 100644 --- a/src/cmd/seek.go +++ b/src/cmd/seek.go @@ -3,8 +3,6 @@ package cmd import ( "strconv" - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -20,7 +18,7 @@ var seekCmd = &cobra.Command{ Long: `Seeks forward or backward, or seeks to a given position in seconds`, RunE: func(cmd *cobra.Command, args []string) error { if args[0] == "forward" || args[0] == "f" { - err := commands.Seek(ctx, client, true) + err := commands.Seek(ctx, true) if err != nil { return err } @@ -28,7 +26,7 @@ var seekCmd = &cobra.Command{ } if args[0] == "backward" || args[0] == "b" { - err := commands.Seek(ctx, client, false) + err := commands.Seek(ctx, false) if err != nil { return err } @@ -40,7 +38,7 @@ var seekCmd = &cobra.Command{ return err } pos = pos * 1000 - err = commands.SetPosition(ctx, client, pos) + err = commands.SetPosition(ctx, pos) if err != nil { return err } diff --git a/src/cmd/setdevice.go b/src/cmd/setdevice.go index 9a6fbe1..075a6c9 100644 --- a/src/cmd/setdevice.go +++ b/src/cmd/setdevice.go @@ -15,6 +15,6 @@ var setDeviceCmd = &cobra.Command{ Short: "Shows tui to pick active device", Long: `Allows setting or changing the active spotify device, shown in a tui`, Run: func(cmd *cobra.Command, args []string) { - tui.StartTea(ctx, client, "devices") + tui.StartTea(ctx, commands, "devices") }, } diff --git a/src/cmd/shuffle.go b/src/cmd/shuffle.go index 047106f..5272bb9 100644 --- a/src/cmd/shuffle.go +++ b/src/cmd/shuffle.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -15,6 +13,6 @@ var shuffleCmd = &cobra.Command{ Short: "Toggles shuffle", Long: `Enables shuffle if it is currently disabled or disables it if it is currently active`, Run: func(cmd *cobra.Command, args []string) { - commands.Shuffle(ctx, client) + commands.Shuffle(ctx) }, } diff --git a/src/cmd/status.go b/src/cmd/status.go index f3a3a43..a706565 100644 --- a/src/cmd/status.go +++ b/src/cmd/status.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -15,6 +13,6 @@ var statusCmd = &cobra.Command{ Short: "Returns player status in json", Long: `Returns all player status in json, useful for scripting`, Run: func(cmd *cobra.Command, args []string) { - commands.Status(ctx, client) + commands.Status(ctx) }, } diff --git a/src/cmd/toggleplay.go b/src/cmd/toggleplay.go index ada7d07..6b8d0f6 100644 --- a/src/cmd/toggleplay.go +++ b/src/cmd/toggleplay.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -16,6 +14,6 @@ var togglePlayCmd = &cobra.Command{ Short: "Toggles the play state of spotify", Long: `If you are playing a song it will pause and if a song is paused it will play`, Run: func(cmd *cobra.Command, args []string) { - commands.TogglePlay(ctx, client) + commands.TogglePlay(ctx) }, } diff --git a/src/cmd/tracks.go b/src/cmd/tracks.go index 63aee24..70aa187 100644 --- a/src/cmd/tracks.go +++ b/src/cmd/tracks.go @@ -4,7 +4,6 @@ import ( "os" "path/filepath" - "gitea.asdf.cafe/abs3nt/gospt/src/commands" "gitea.asdf.cafe/abs3nt/gospt/src/tui" "github.com/spf13/cobra" @@ -20,12 +19,12 @@ var tracksCmd = &cobra.Command{ Long: `Uses TUI to open a list of saved tracks`, RunE: func(cmd *cobra.Command, args []string) error { configDir, _ := os.UserConfigDir() - if commands.ActiveDeviceExists(ctx, client) { - return tui.StartTea(ctx, client, "tracks") + if commands.ActiveDeviceExists(ctx) { + return tui.StartTea(ctx, commands, "tracks") } if _, err := os.Stat(filepath.Join(configDir, "gospt/device.json")); err != nil { - return tui.StartTea(ctx, client, "devices") + return tui.StartTea(ctx, commands, "devices") } - return tui.StartTea(ctx, client, "tracks") + return tui.StartTea(ctx, commands, "tracks") }, } diff --git a/src/cmd/tui.go b/src/cmd/tui.go index cadb6dc..54673b9 100644 --- a/src/cmd/tui.go +++ b/src/cmd/tui.go @@ -4,7 +4,6 @@ import ( "os" "path/filepath" - "gitea.asdf.cafe/abs3nt/gospt/src/commands" "gitea.asdf.cafe/abs3nt/gospt/src/tui" "github.com/spf13/cobra" @@ -20,12 +19,12 @@ var tuiCmd = &cobra.Command{ Long: `Default command. this is what will run if no other commands are present. Shows the main menu.`, RunE: func(cmd *cobra.Command, args []string) error { configDir, _ := os.UserConfigDir() - if commands.ActiveDeviceExists(ctx, client) { - return tui.StartTea(ctx, client, "main") + if commands.ActiveDeviceExists(ctx) { + return tui.StartTea(ctx, commands, "main") } if _, err := os.Stat(filepath.Join(configDir, "gospt/device.json")); err != nil { - return tui.StartTea(ctx, client, "devices") + return tui.StartTea(ctx, commands, "devices") } - return tui.StartTea(ctx, client, "main") + return tui.StartTea(ctx, commands, "main") }, } diff --git a/src/cmd/unlike.go b/src/cmd/unlike.go index 97b6665..527c4f8 100644 --- a/src/cmd/unlike.go +++ b/src/cmd/unlike.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -16,6 +14,6 @@ var unlikeCmd = &cobra.Command{ Short: "unlikes song", Long: `unlikes song`, Run: func(cmd *cobra.Command, args []string) { - commands.Unlike(ctx, client) + commands.Unlike(ctx) }, } diff --git a/src/cmd/unmute.go b/src/cmd/unmute.go index 2188bf2..f977434 100644 --- a/src/cmd/unmute.go +++ b/src/cmd/unmute.go @@ -1,8 +1,6 @@ package cmd import ( - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -15,7 +13,7 @@ var unmuteCmd = &cobra.Command{ Short: "unmutes playback", Long: `unmutes the spotify device, playback will continue`, RunE: func(cmd *cobra.Command, args []string) error { - err := commands.SetVolume(ctx, client, 100) + err := commands.SetVolume(ctx, 100) if err != nil { return err } diff --git a/src/cmd/volume.go b/src/cmd/volume.go index bacdb69..8fbc4a4 100644 --- a/src/cmd/volume.go +++ b/src/cmd/volume.go @@ -3,8 +3,6 @@ package cmd import ( "strconv" - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/spf13/cobra" ) @@ -20,7 +18,7 @@ var volumeCmd = &cobra.Command{ Long: `Sets the volume to the given percent [0-100] or increases/decreases by 5 percent if you say up or down`, RunE: func(cmd *cobra.Command, args []string) error { if args[0] == "up" { - err := commands.ChangeVolume(ctx, client, 5) + err := commands.ChangeVolume(ctx, 5) if err != nil { return err } @@ -28,7 +26,7 @@ var volumeCmd = &cobra.Command{ } if args[0] == "down" { - err := commands.ChangeVolume(ctx, client, -5) + err := commands.ChangeVolume(ctx, -5) if err != nil { return err } @@ -39,7 +37,7 @@ var volumeCmd = &cobra.Command{ if err != nil { return err } - err = commands.SetVolume(ctx, client, vol) + err = commands.SetVolume(ctx, vol) if err != nil { return err } diff --git a/src/commands/commands.go b/src/commands/commands.go index 8335851..e2a1285 100644 --- a/src/commands/commands.go +++ b/src/commands/commands.go @@ -1,7 +1,6 @@ package commands import ( - "context" "database/sql" "encoding/json" "errors" @@ -25,8 +24,9 @@ import ( ) type Commands struct { - cl *spotify.Client - mu sync.RWMutex + Context *gctx.Context + cl *spotify.Client + mu sync.RWMutex user string } @@ -48,7 +48,7 @@ func (c *Commands) User() string { } func (c *Commands) connectClient() *spotify.Client { - ctx := gctx.NewContext(context.Background()) + ctx := c.Context client, err := auth.GetClient(ctx) if err != nil { panic(err) @@ -58,7 +58,7 @@ func (c *Commands) connectClient() *spotify.Client { panic(err) } c.user = currentUser.ID - return &spotify.Client{} + return client } func (c *Commands) SetVolume(ctx *gctx.Context, vol int) error { diff --git a/src/gctx/context.go b/src/gctx/context.go index 9d8f9eb..66ec1f9 100644 --- a/src/gctx/context.go +++ b/src/gctx/context.go @@ -2,15 +2,25 @@ package gctx import ( "context" + "fmt" "os" "tuxpa.in/a/zlog" ) type Context struct { - context.Context zlog.Logger Debug zlog.Logger + + context.Context +} + +func (c *Context) Err() error { + return c.Context.Err() +} + +func (c *Context) Println(args ...any) { + c.Info().Msg(fmt.Sprint(args...)) } func NewContext(ctx context.Context) *Context { diff --git a/src/tui/handlers.go b/src/tui/handlers.go index a10521c..8269b35 100644 --- a/src/tui/handlers.go +++ b/src/tui/handlers.go @@ -7,95 +7,95 @@ import ( "github.com/zmb3/spotify/v2" ) -func HandlePlayWithContext(ctx *gctx.Context, client *spotify.Client, uri *spotify.URI, pos int) { +func HandlePlayWithContext(ctx *gctx.Context, commands *commands.Commands, uri *spotify.URI, pos int) { var err error - err = commands.PlaySongInPlaylist(ctx, client, uri, pos) + err = commands.PlaySongInPlaylist(ctx, uri, pos) if err != nil { return } } -func HandleRadio(ctx *gctx.Context, client *spotify.Client, song spotify.SimpleTrack) { - err := commands.RadioGivenSong(ctx, client, song, 0) +func HandleRadio(ctx *gctx.Context, commands *commands.Commands, song spotify.SimpleTrack) { + err := commands.RadioGivenSong(ctx, song, 0) if err != nil { return } } -func HandleAlbumRadio(ctx *gctx.Context, client *spotify.Client, album spotify.SimpleAlbum) { - err := commands.RadioFromAlbum(ctx, client, album) +func HandleAlbumRadio(ctx *gctx.Context, commands *commands.Commands, album spotify.SimpleAlbum) { + err := commands.RadioFromAlbum(ctx, album) if err != nil { return } } -func HandleSeek(ctx *gctx.Context, client *spotify.Client, fwd bool) { - err := commands.Seek(ctx, client, fwd) +func HandleSeek(ctx *gctx.Context, commands *commands.Commands, fwd bool) { + err := commands.Seek(ctx, fwd) if err != nil { return } } -func HandleVolume(ctx *gctx.Context, client *spotify.Client, up bool) { +func HandleVolume(ctx *gctx.Context, commands *commands.Commands, up bool) { vol := 10 if !up { vol = -10 } - err := commands.ChangeVolume(ctx, client, vol) + err := commands.ChangeVolume(ctx, vol) if err != nil { return } } -func HandleArtistRadio(ctx *gctx.Context, client *spotify.Client, artist spotify.SimpleArtist) { - err := commands.RadioGivenArtist(ctx, client, artist) +func HandleArtistRadio(ctx *gctx.Context, commands *commands.Commands, artist spotify.SimpleArtist) { + err := commands.RadioGivenArtist(ctx, artist) if err != nil { return } } -func HandleAlbumArtist(ctx *gctx.Context, client *spotify.Client, artist spotify.SimpleArtist) { - err := commands.RadioGivenArtist(ctx, client, artist) +func HandleAlbumArtist(ctx *gctx.Context, commands *commands.Commands, artist spotify.SimpleArtist) { + err := commands.RadioGivenArtist(ctx, artist) if err != nil { return } } -func HandlePlaylistRadio(ctx *gctx.Context, client *spotify.Client, playlist spotify.SimplePlaylist) { - err := commands.RadioFromPlaylist(ctx, client, playlist) +func HandlePlaylistRadio(ctx *gctx.Context, commands *commands.Commands, playlist spotify.SimplePlaylist) { + err := commands.RadioFromPlaylist(ctx, playlist) if err != nil { return } } -func HandleLibraryRadio(ctx *gctx.Context, client *spotify.Client) { - err := commands.RadioFromSavedTracks(ctx, client) +func HandleLibraryRadio(ctx *gctx.Context, commands *commands.Commands) { + err := commands.RadioFromSavedTracks(ctx) if err != nil { return } } -func HandlePlayLikedSong(ctx *gctx.Context, client *spotify.Client, position int) { - err := commands.PlayLikedSongs(ctx, client, position) +func HandlePlayLikedSong(ctx *gctx.Context, commands *commands.Commands, position int) { + err := commands.PlayLikedSongs(ctx, position) if err != nil { return } } -func HandlePlayTrack(ctx *gctx.Context, client *spotify.Client, track spotify.ID) { - err := commands.QueueSong(ctx, client, track) +func HandlePlayTrack(ctx *gctx.Context, commands *commands.Commands, track spotify.ID) { + err := commands.QueueSong(ctx, track) if err != nil { return } - err = commands.Next(ctx, client, 1) + err = commands.Next(ctx, 1) if err != nil { return } } -func HandleSetDevice(ctx *gctx.Context, client *spotify.Client, player spotify.PlayerDevice) { +func HandleSetDevice(ctx *gctx.Context, commands *commands.Commands, player spotify.PlayerDevice) { var err error - err = commands.SetDevice(ctx, client, player) + err = commands.SetDevice(ctx, player) if err != nil { return } diff --git a/src/tui/loader.go b/src/tui/loader.go index d1127bb..f3768da 100644 --- a/src/tui/loader.go +++ b/src/tui/loader.go @@ -4,15 +4,13 @@ import ( "fmt" "time" - "gitea.asdf.cafe/abs3nt/gospt/src/commands" - "github.com/charmbracelet/bubbles/list" ) func (m *mainModel) LoadMoreItems() { switch m.mode { case "artist": - albums, err := commands.ArtistAlbums(m.ctx, m.client, m.artist.ID, (page + 1)) + albums, err := m.commands.ArtistAlbums(m.ctx, m.artist.ID, (page + 1)) page++ if err != nil { return @@ -32,7 +30,7 @@ func (m *mainModel) LoadMoreItems() { main_updates <- m return case "artists": - artists, err := commands.UserArtists(m.ctx, m.client, (page + 1)) + artists, err := m.commands.UserArtists(m.ctx, (page + 1)) page++ if err != nil { return @@ -52,7 +50,7 @@ func (m *mainModel) LoadMoreItems() { main_updates <- m return case "album": - tracks, err := commands.AlbumTracks(m.ctx, m.client, m.album.ID, (page + 1)) + tracks, err := m.commands.AlbumTracks(m.ctx, m.album.ID, (page + 1)) page++ if err != nil { return @@ -73,7 +71,7 @@ func (m *mainModel) LoadMoreItems() { main_updates <- m return case "albums": - albums, err := commands.UserAlbums(m.ctx, m.client, (page + 1)) + albums, err := m.commands.UserAlbums(m.ctx, (page + 1)) page++ if err != nil { return @@ -93,7 +91,7 @@ func (m *mainModel) LoadMoreItems() { main_updates <- m return case "main": - playlists, err := commands.Playlists(m.ctx, m.client, (page + 1)) + playlists, err := m.commands.Playlists(m.ctx, (page + 1)) page++ if err != nil { return @@ -112,7 +110,7 @@ func (m *mainModel) LoadMoreItems() { main_updates <- m return case "playlist": - tracks, err := commands.PlaylistTracks(m.ctx, m.client, m.playlist.ID, (page + 1)) + tracks, err := m.commands.PlaylistTracks(m.ctx, m.playlist.ID, (page + 1)) page++ if err != nil { return @@ -133,7 +131,7 @@ func (m *mainModel) LoadMoreItems() { main_updates <- m return case "tracks": - tracks, err := commands.TrackList(m.ctx, m.client, (page + 1)) + tracks, err := m.commands.TrackList(m.ctx, (page + 1)) page++ if err != nil { return diff --git a/src/tui/main.go b/src/tui/main.go index 753da2d..63e9f22 100644 --- a/src/tui/main.go +++ b/src/tui/main.go @@ -5,6 +5,7 @@ import ( "strings" "time" + "gitea.asdf.cafe/abs3nt/gospt/src/commands" "gitea.asdf.cafe/abs3nt/gospt/src/gctx" "github.com/atotto/clipboard" @@ -74,7 +75,7 @@ type mainModel struct { list list.Model input textinput.Model ctx *gctx.Context - client *spotify.Client + commands *commands.Commands mode Mode playlist spotify.SimplePlaylist artist spotify.SimpleArtist @@ -91,34 +92,34 @@ func (m *mainModel) PlayRadio() { selectedItem := m.list.SelectedItem().(mainItem).SpotifyItem switch selectedItem.(type) { case spotify.SimplePlaylist: - go HandlePlaylistRadio(m.ctx, m.client, selectedItem.(spotify.SimplePlaylist)) + go HandlePlaylistRadio(m.ctx, m.commands, selectedItem.(spotify.SimplePlaylist)) return case *spotify.SavedTrackPage: - go HandleLibraryRadio(m.ctx, m.client) + go HandleLibraryRadio(m.ctx, m.commands) return case spotify.SimpleAlbum: - go HandleAlbumRadio(m.ctx, m.client, selectedItem.(spotify.SimpleAlbum)) + go HandleAlbumRadio(m.ctx, m.commands, selectedItem.(spotify.SimpleAlbum)) return case spotify.FullAlbum: - go HandleAlbumRadio(m.ctx, m.client, selectedItem.(spotify.FullAlbum).SimpleAlbum) + go HandleAlbumRadio(m.ctx, m.commands, selectedItem.(spotify.FullAlbum).SimpleAlbum) return case spotify.SimpleArtist: - go HandleArtistRadio(m.ctx, m.client, selectedItem.(spotify.SimpleArtist)) + go HandleArtistRadio(m.ctx, m.commands, selectedItem.(spotify.SimpleArtist)) return case spotify.FullArtist: - go HandleArtistRadio(m.ctx, m.client, selectedItem.(spotify.FullArtist).SimpleArtist) + go HandleArtistRadio(m.ctx, m.commands, selectedItem.(spotify.FullArtist).SimpleArtist) return case spotify.SimpleTrack: - go HandleRadio(m.ctx, m.client, selectedItem.(spotify.SimpleTrack)) + go HandleRadio(m.ctx, m.commands, selectedItem.(spotify.SimpleTrack)) return case spotify.FullTrack: - go HandleRadio(m.ctx, m.client, selectedItem.(spotify.FullTrack).SimpleTrack) + go HandleRadio(m.ctx, m.commands, selectedItem.(spotify.FullTrack).SimpleTrack) return case spotify.PlaylistTrack: - go HandleRadio(m.ctx, m.client, selectedItem.(spotify.PlaylistTrack).Track.SimpleTrack) + go HandleRadio(m.ctx, m.commands, selectedItem.(spotify.PlaylistTrack).Track.SimpleTrack) return case spotify.SavedTrack: - go HandleRadio(m.ctx, m.client, selectedItem.(spotify.SavedTrack).SimpleTrack) + go HandleRadio(m.ctx, m.commands, selectedItem.(spotify.SavedTrack).SimpleTrack) return } } @@ -129,34 +130,34 @@ func (m *mainModel) GoBack() (tea.Cmd, error) { return tea.Quit, nil case Albums, Artists, Tracks, Playlist, Devices, Search: m.mode = Main - new_items, err := MainView(m.ctx, m.client) + new_items, err := MainView(m.ctx, m.commands) if err != nil { } m.list.SetItems(new_items) case Album: m.mode = Albums - new_items, err := AlbumsView(m.ctx, m.client) + new_items, err := AlbumsView(m.ctx, m.commands) if err != nil { return nil, err } m.list.SetItems(new_items) case Artist: m.mode = Artists - new_items, err := ArtistsView(m.ctx, m.client) + new_items, err := ArtistsView(m.ctx, m.commands) if err != nil { return nil, err } m.list.SetItems(new_items) case ArtistAlbum: m.mode = Artist - new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.client) + new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.commands) if err != nil { return nil, err } m.list.SetItems(new_items) case SearchArtists, SearchTracks, SearchAlbums, SearchPlaylists: m.mode = Search - items, result, err := SearchView(m.ctx, m.client, m.search) + items, result, err := SearchView(m.ctx, m.commands, m.search) if err != nil { return nil, err } @@ -164,28 +165,28 @@ func (m *mainModel) GoBack() (tea.Cmd, error) { m.list.SetItems(items) case SearchArtist: m.mode = SearchArtists - new_items, err := SearchArtistsView(m.ctx, m.client, m.searchResults.Artists) + new_items, err := SearchArtistsView(m.ctx, m.commands, m.searchResults.Artists) if err != nil { return nil, err } m.list.SetItems(new_items) case SearchArtistAlbum: m.mode = SearchArtist - new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.client) + new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.commands) if err != nil { return nil, err } m.list.SetItems(new_items) case SearchAlbum: m.mode = SearchAlbums - new_items, err := SearchAlbumsView(m.ctx, m.client, m.searchResults.Albums) + new_items, err := SearchAlbumsView(m.ctx, m.commands, m.searchResults.Albums) if err != nil { return nil, err } m.list.SetItems(new_items) case SearchPlaylist: m.mode = SearchPlaylists - new_items, err := SearchPlaylistsView(m.ctx, m.client, m.searchResults.Playlists) + new_items, err := SearchPlaylistsView(m.ctx, m.commands, m.searchResults.Playlists) if err != nil { return nil, err } @@ -243,7 +244,7 @@ func (m *mainModel) SelectItem() error { switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) { case *spotify.FullArtistPage: m.mode = SearchArtists - new_items, err := SearchArtistsView(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.FullArtistPage)) + new_items, err := SearchArtistsView(m.ctx, m.commands, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.FullArtistPage)) if err != nil { return err } @@ -251,7 +252,7 @@ func (m *mainModel) SelectItem() error { m.list.ResetSelected() case *spotify.SimpleAlbumPage: m.mode = SearchAlbums - new_items, err := SearchAlbumsView(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.SimpleAlbumPage)) + new_items, err := SearchAlbumsView(m.ctx, m.commands, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.SimpleAlbumPage)) if err != nil { return err } @@ -260,7 +261,7 @@ func (m *mainModel) SelectItem() error { case *spotify.SimplePlaylistPage: m.mode = SearchPlaylists playlists := m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.SimplePlaylistPage) - new_items, err := SearchPlaylistsView(m.ctx, m.client, playlists) + new_items, err := SearchPlaylistsView(m.ctx, m.commands, playlists) if err != nil { return err } @@ -268,7 +269,7 @@ func (m *mainModel) SelectItem() error { m.list.ResetSelected() case *spotify.FullTrackPage: m.mode = SearchTracks - new_items, err := SearchTracksView(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.FullTrackPage)) + new_items, err := SearchTracksView(m.ctx, m.commands, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.FullTrackPage)) if err != nil { return err } @@ -278,7 +279,7 @@ func (m *mainModel) SelectItem() error { case SearchArtists: m.mode = SearchArtist m.artist = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleArtist) - new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.client) + new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.commands) if err != nil { return err } @@ -287,7 +288,7 @@ func (m *mainModel) SelectItem() error { case SearchArtist: m.mode = SearchArtistAlbum m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum) - new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.client) + new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.commands) if err != nil { return err } @@ -296,7 +297,7 @@ func (m *mainModel) SelectItem() error { case SearchAlbums: m.mode = SearchAlbum m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum) - new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.client) + new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.commands) if err != nil { return err } @@ -306,7 +307,7 @@ func (m *mainModel) SelectItem() error { m.mode = SearchPlaylist playlist := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist) m.playlist = playlist - new_items, err := PlaylistView(m.ctx, m.client, playlist) + new_items, err := PlaylistView(m.ctx, m.commands, playlist) if err != nil { return err } @@ -316,7 +317,7 @@ func (m *mainModel) SelectItem() error { switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) { case *spotify.FullArtistCursorPage: m.mode = Artists - new_items, err := ArtistsView(m.ctx, m.client) + new_items, err := ArtistsView(m.ctx, m.commands) if err != nil { return err } @@ -324,7 +325,7 @@ func (m *mainModel) SelectItem() error { m.list.ResetSelected() case *spotify.SavedAlbumPage: m.mode = Albums - new_items, err := AlbumsView(m.ctx, m.client) + new_items, err := AlbumsView(m.ctx, m.commands) if err != nil { return err } @@ -334,7 +335,7 @@ func (m *mainModel) SelectItem() error { m.mode = Playlist playlist := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist) m.playlist = playlist - new_items, err := PlaylistView(m.ctx, m.client, playlist) + new_items, err := PlaylistView(m.ctx, m.commands, playlist) if err != nil { return err } @@ -342,7 +343,7 @@ func (m *mainModel) SelectItem() error { m.list.ResetSelected() case *spotify.SavedTrackPage: m.mode = Tracks - new_items, err := SavedTracksView(m.ctx, m.client) + new_items, err := SavedTracksView(m.ctx, m.commands) if err != nil { return err } @@ -352,7 +353,7 @@ func (m *mainModel) SelectItem() error { case Albums: m.mode = Album m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum) - new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.client) + new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.commands) if err != nil { return err } @@ -361,7 +362,7 @@ func (m *mainModel) SelectItem() error { case Artist: m.mode = ArtistAlbum m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum) - new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.client) + new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.commands) if err != nil { return err } @@ -370,26 +371,26 @@ func (m *mainModel) SelectItem() error { case Artists: m.mode = Artist m.artist = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleArtist) - new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.client) + new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.commands) if err != nil { return err } m.list.SetItems(new_items) m.list.ResetSelected() case Album, ArtistAlbum, SearchArtistAlbum, SearchAlbum: - go HandlePlayWithContext(m.ctx, m.client, &m.album.URI, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.TotalPages)) + go HandlePlayWithContext(m.ctx, m.commands, &m.album.URI, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.TotalPages)) case Playlist, SearchPlaylist: - go HandlePlayWithContext(m.ctx, m.client, &m.playlist.URI, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.PerPage)) + go HandlePlayWithContext(m.ctx, m.commands, &m.playlist.URI, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.PerPage)) case Tracks: - go HandlePlayLikedSong(m.ctx, m.client, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.PerPage)) + go HandlePlayLikedSong(m.ctx, m.commands, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.PerPage)) case SearchTracks: - go HandlePlayTrack(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.FullTrack).ID) + go HandlePlayTrack(m.ctx, m.commands, m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.FullTrack).ID) case Devices: - go HandleSetDevice(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.PlayerDevice)) + go HandleSetDevice(m.ctx, m.commands, m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.PlayerDevice)) m.list.NewStatusMessage("Setting device to " + m.list.SelectedItem().FilterValue()) m.mode = "main" m.list.NewStatusMessage("Setting view to main") - new_items, err := MainView(m.ctx, m.client) + new_items, err := MainView(m.ctx, m.commands) if err != nil { return err } @@ -412,7 +413,7 @@ func Tick() tea.Cmd { } func (m *mainModel) TickPlayback() { - playing, _ := m.client.PlayerCurrentlyPlaying(m.ctx) + playing, _ := m.commands.Client().PlayerCurrentlyPlaying(m.ctx) if playing != nil && playing.Playing && playing.Item != nil { currentlyPlaying = playing playbackContext, _ = m.getContext(playing) @@ -423,7 +424,7 @@ func (m *mainModel) TickPlayback() { for { select { case <-ticker.C: - playing, _ := m.client.PlayerCurrentlyPlaying(m.ctx) + playing, _ := m.commands.Client().PlayerCurrentlyPlaying(m.ctx) if playing != nil && playing.Playing && playing.Item != nil { currentlyPlaying = playing playbackContext, _ = m.getContext(playing) @@ -445,7 +446,7 @@ func (m mainModel) View() string { func (m *mainModel) Typing(msg tea.KeyMsg) (bool, tea.Cmd) { if msg.String() == "enter" { - items, result, err := SearchView(m.ctx, m.client, m.input.Value()) + items, result, err := SearchView(m.ctx, m.commands, m.input.Value()) if err != nil { return false, tea.Quit } @@ -475,19 +476,19 @@ func (m *mainModel) getContext(playing *spotify.CurrentlyPlaying) (string, error id := strings.Split(string(context.URI), ":")[2] switch context.Type { case "album": - album, err := m.client.GetAlbum(m.ctx, spotify.ID(id)) + album, err := m.commands.Client().GetAlbum(m.ctx, spotify.ID(id)) if err != nil { return "", err } return album.Name, nil case "playlist": - playlist, err := m.client.GetPlaylist(m.ctx, spotify.ID(id)) + playlist, err := m.commands.Client().GetPlaylist(m.ctx, spotify.ID(id)) if err != nil { return "", err } return playlist.Name, nil case "artist": - artist, err := m.client.GetArtist(m.ctx, spotify.ID(id)) + artist, err := m.commands.Client().GetArtist(m.ctx, spotify.ID(id)) if err != nil { return "", err } @@ -547,16 +548,16 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } } if msg.String() == ">" { - go HandleSeek(m.ctx, m.client, true) + go HandleSeek(m.ctx, m.commands, true) } if msg.String() == "<" { - go HandleSeek(m.ctx, m.client, false) + go HandleSeek(m.ctx, m.commands, false) } if msg.String() == "+" { - go HandleVolume(m.ctx, m.client, true) + go HandleVolume(m.ctx, m.commands, true) } if msg.String() == "-" { - go HandleVolume(m.ctx, m.client, false) + go HandleVolume(m.ctx, m.commands, false) } // search input if m.input.Focused() { @@ -573,7 +574,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // enter device selection if msg.String() == "d" { m.mode = Devices - new_items, err := DeviceView(m.ctx, m.client) + new_items, err := DeviceView(m.ctx, m.commands) if err != nil { return m, tea.Quit } @@ -624,24 +625,24 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd } -func InitMain(ctx *gctx.Context, client *spotify.Client, mode Mode) (tea.Model, error) { +func InitMain(ctx *gctx.Context, c *commands.Commands, mode Mode) (tea.Model, error) { prog := progress.New(progress.WithColorProfile(2), progress.WithoutPercentage()) var err error lipgloss.SetColorProfile(2) items := []list.Item{} switch mode { case Main: - items, err = MainView(ctx, client) + items, err = MainView(ctx, c) if err != nil { return nil, err } case Devices: - items, err = DeviceView(ctx, client) + items, err = DeviceView(ctx, c) if err != nil { return nil, err } case Tracks: - items, err = SavedTracksView(ctx, client) + items, err = SavedTracksView(ctx, c) if err != nil { return nil, err } @@ -649,7 +650,7 @@ func InitMain(ctx *gctx.Context, client *spotify.Client, mode Mode) (tea.Model, m := mainModel{ list: list.New(items, list.NewDefaultDelegate(), 0, 0), ctx: ctx, - client: client, + commands: c, mode: mode, progress: prog, } diff --git a/src/tui/tui.go b/src/tui/tui.go index fbce6e8..4770490 100644 --- a/src/tui/tui.go +++ b/src/tui/tui.go @@ -3,15 +3,15 @@ package tui import ( "fmt" + "gitea.asdf.cafe/abs3nt/gospt/src/commands" "gitea.asdf.cafe/abs3nt/gospt/src/gctx" tea "github.com/charmbracelet/bubbletea" - "github.com/zmb3/spotify/v2" ) // StartTea the entry point for the UI. Initializes the model. -func StartTea(ctx *gctx.Context, client *spotify.Client, mode string) error { - m, err := InitMain(ctx, client, Mode(mode)) +func StartTea(ctx *gctx.Context, cmd *commands.Commands, mode string) error { + m, err := InitMain(ctx, cmd, Mode(mode)) if err != nil { fmt.Println("UH OH") } diff --git a/src/tui/views.go b/src/tui/views.go index 7fd96b6..319d61e 100644 --- a/src/tui/views.go +++ b/src/tui/views.go @@ -12,9 +12,9 @@ import ( "github.com/zmb3/spotify/v2" ) -func DeviceView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) { +func DeviceView(ctx *gctx.Context, commands *commands.Commands) ([]list.Item, error) { items := []list.Item{} - devices, err := client.PlayerDevices(ctx) + devices, err := commands.Client().PlayerDevices(ctx) if err != nil { return nil, err } @@ -28,9 +28,9 @@ func DeviceView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) return items, nil } -func PlaylistView(ctx *gctx.Context, client *spotify.Client, playlist spotify.SimplePlaylist) ([]list.Item, error) { +func PlaylistView(ctx *gctx.Context, commands *commands.Commands, playlist spotify.SimplePlaylist) ([]list.Item, error) { items := []list.Item{} - tracks, err := commands.PlaylistTracks(ctx, client, playlist.ID, 1) + tracks, err := commands.PlaylistTracks(ctx, playlist.ID, 1) if err != nil { return nil, err } @@ -47,9 +47,9 @@ func PlaylistView(ctx *gctx.Context, client *spotify.Client, playlist spotify.Si return items, nil } -func ArtistsView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) { +func ArtistsView(ctx *gctx.Context, commands *commands.Commands) ([]list.Item, error) { items := []list.Item{} - artists, err := commands.UserArtists(ctx, client, 1) + artists, err := commands.UserArtists(ctx, 1) if err != nil { return nil, err } @@ -64,7 +64,7 @@ func ArtistsView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) return items, nil } -func SearchArtistsView(ctx *gctx.Context, client *spotify.Client, artists *spotify.FullArtistPage) ([]list.Item, error) { +func SearchArtistsView(ctx *gctx.Context, commands *commands.Commands, artists *spotify.FullArtistPage) ([]list.Item, error) { items := []list.Item{} for _, artist := range artists.Artists { items = append(items, mainItem{ @@ -77,10 +77,10 @@ func SearchArtistsView(ctx *gctx.Context, client *spotify.Client, artists *spoti return items, nil } -func SearchView(ctx *gctx.Context, client *spotify.Client, search string) ([]list.Item, *SearchResults, error) { +func SearchView(ctx *gctx.Context, commands *commands.Commands, search string) ([]list.Item, *SearchResults, error) { items := []list.Item{} - result, err := commands.Search(ctx, client, search, 1) + result, err := commands.Search(ctx, search, 1) if err != nil { return nil, nil, err } @@ -114,9 +114,9 @@ func SearchView(ctx *gctx.Context, client *spotify.Client, search string) ([]lis return items, results, nil } -func AlbumsView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) { +func AlbumsView(ctx *gctx.Context, commands *commands.Commands) ([]list.Item, error) { items := []list.Item{} - albums, err := commands.UserAlbums(ctx, client, 1) + albums, err := commands.UserAlbums(ctx, 1) if err != nil { return nil, err } @@ -131,7 +131,7 @@ func AlbumsView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) return items, nil } -func SearchPlaylistsView(ctx *gctx.Context, client *spotify.Client, playlists *spotify.SimplePlaylistPage) ([]list.Item, error) { +func SearchPlaylistsView(ctx *gctx.Context, commands *commands.Commands, playlists *spotify.SimplePlaylistPage) ([]list.Item, error) { items := []list.Item{} for _, playlist := range playlists.Playlists { items = append(items, mainItem{ @@ -143,7 +143,7 @@ func SearchPlaylistsView(ctx *gctx.Context, client *spotify.Client, playlists *s return items, nil } -func SearchAlbumsView(ctx *gctx.Context, client *spotify.Client, albums *spotify.SimpleAlbumPage) ([]list.Item, error) { +func SearchAlbumsView(ctx *gctx.Context, commands *commands.Commands, albums *spotify.SimpleAlbumPage) ([]list.Item, error) { items := []list.Item{} for _, album := range albums.Albums { items = append(items, mainItem{ @@ -156,9 +156,9 @@ func SearchAlbumsView(ctx *gctx.Context, client *spotify.Client, albums *spotify return items, nil } -func ArtistAlbumsView(ctx *gctx.Context, album spotify.ID, client *spotify.Client) ([]list.Item, error) { +func ArtistAlbumsView(ctx *gctx.Context, album spotify.ID, commands *commands.Commands) ([]list.Item, error) { items := []list.Item{} - albums, err := commands.ArtistAlbums(ctx, client, album, 1) + albums, err := commands.ArtistAlbums(ctx, album, 1) if err != nil { return nil, err } @@ -173,9 +173,9 @@ func ArtistAlbumsView(ctx *gctx.Context, album spotify.ID, client *spotify.Clien return items, err } -func AlbumTracksView(ctx *gctx.Context, album spotify.ID, client *spotify.Client) ([]list.Item, error) { +func AlbumTracksView(ctx *gctx.Context, album spotify.ID, commands *commands.Commands) ([]list.Item, error) { items := []list.Item{} - tracks, err := commands.AlbumTracks(ctx, client, album, 1) + tracks, err := commands.AlbumTracks(ctx, album, 1) if err != nil { return nil, err } @@ -192,7 +192,7 @@ func AlbumTracksView(ctx *gctx.Context, album spotify.ID, client *spotify.Client return items, err } -func SearchTracksView(ctx *gctx.Context, client *spotify.Client, tracks *spotify.FullTrackPage) ([]list.Item, error) { +func SearchTracksView(ctx *gctx.Context, commands *commands.Commands, tracks *spotify.FullTrackPage) ([]list.Item, error) { items := []list.Item{} for _, track := range tracks.Tracks { items = append(items, mainItem{ @@ -207,9 +207,9 @@ func SearchTracksView(ctx *gctx.Context, client *spotify.Client, tracks *spotify return items, nil } -func SavedTracksView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) { +func SavedTracksView(ctx *gctx.Context, commands *commands.Commands) ([]list.Item, error) { items := []list.Item{} - tracks, err := commands.TrackList(ctx, client, 1) + tracks, err := commands.TrackList(ctx, 1) if err != nil { return nil, err } @@ -226,7 +226,7 @@ func SavedTracksView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, er return items, err } -func MainView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) { +func MainView(ctx *gctx.Context, commands *commands.Commands) ([]list.Item, error) { var wg sync.WaitGroup var saved_items *spotify.SavedTrackPage var playlists *spotify.SimplePlaylistPage @@ -237,7 +237,7 @@ func MainView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) { go func() { defer wg.Done() var err error - saved_items, err = commands.TrackList(ctx, client, 1) + saved_items, err = commands.TrackList(ctx, 1) if err != nil { fmt.Println(err.Error()) return @@ -248,7 +248,7 @@ func MainView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) { go func() { defer wg.Done() var err error - playlists, err = commands.Playlists(ctx, client, 1) + playlists, err = commands.Playlists(ctx, 1) if err != nil { fmt.Println(err.Error()) return @@ -259,7 +259,7 @@ func MainView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) { go func() { defer wg.Done() var err error - artists, err = commands.UserArtists(ctx, client, 1) + artists, err = commands.UserArtists(ctx, 1) if err != nil { fmt.Println(err.Error()) return @@ -270,7 +270,7 @@ func MainView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) { go func() { defer wg.Done() var err error - albums, err = commands.UserAlbums(ctx, client, 1) + albums, err = commands.UserAlbums(ctx, 1) if err != nil { fmt.Println(err.Error()) return