works maybe
This commit is contained in:
parent
6abd74ea1c
commit
8a4ac17743
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,6 +13,6 @@ var clearRadioCmd = &cobra.Command{
|
|||||||
Short: "Wipes the radio playlist and creates an empty one",
|
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`,
|
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) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
commands.ClearRadio(ctx, client)
|
commands.ClearRadio(ctx)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,6 +13,6 @@ var devicesCmd = &cobra.Command{
|
|||||||
Short: "Prints out devices",
|
Short: "Prints out devices",
|
||||||
Long: `Prints out devices`,
|
Long: `Prints out devices`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
commands.Devices(ctx, client)
|
commands.Devices(ctx)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,6 +14,6 @@ var likeCmd = &cobra.Command{
|
|||||||
Short: "Likes song",
|
Short: "Likes song",
|
||||||
Long: `Likes song`,
|
Long: `Likes song`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
commands.Like(ctx, client)
|
commands.Like(ctx)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,7 +14,7 @@ var linkCmd = &cobra.Command{
|
|||||||
Short: "Print link to currently playing song",
|
Short: "Print link to currently playing song",
|
||||||
Long: `Print link to currently playing song`,
|
Long: `Print link to currently playing song`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
link, err := commands.Link(ctx, client)
|
link, err := commands.Link(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -4,8 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,7 +14,7 @@ var linkContextCmd = &cobra.Command{
|
|||||||
Short: "Get url to current context(album, playlist)",
|
Short: "Get url to current context(album, playlist)",
|
||||||
Long: `Get url to current context(album, playlist)`,
|
Long: `Get url to current context(album, playlist)`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
link, err := commands.LinkContext(ctx, client)
|
link, err := commands.LinkContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,7 +13,7 @@ var muteCmd = &cobra.Command{
|
|||||||
Short: "mutes playback",
|
Short: "mutes playback",
|
||||||
Long: `Mutes the spotify device, playback will continue`,
|
Long: `Mutes the spotify device, playback will continue`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
err := commands.SetVolume(ctx, client, 0)
|
err := commands.SetVolume(ctx, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,6 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,6 +25,6 @@ var nextCmd = &cobra.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return commands.Next(ctx, client, skipAmt)
|
return commands.Next(ctx, skipAmt)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,6 +14,6 @@ var nowPlayingCmd = &cobra.Command{
|
|||||||
Short: "Shows song and artist of currently playing song",
|
Short: "Shows song and artist of currently playing song",
|
||||||
Long: `Shows song and artist of currently playing song, useful for scripting`,
|
Long: `Shows song and artist of currently playing song, useful for scripting`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
commands.NowPlaying(ctx, client)
|
commands.NowPlaying(ctx)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,6 +14,6 @@ var pauseCmd = &cobra.Command{
|
|||||||
Aliases: []string{"pa"},
|
Aliases: []string{"pa"},
|
||||||
Long: `Pauses currently playing song on spotify`,
|
Long: `Pauses currently playing song on spotify`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
commands.Pause(ctx, client)
|
commands.Pause(ctx)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,6 +14,6 @@ var playCmd = &cobra.Command{
|
|||||||
Short: "Plays spotify",
|
Short: "Plays spotify",
|
||||||
Long: `Plays queued song on spotify, uses last used device and activates it if needed`,
|
Long: `Plays queued song on spotify, uses last used device and activates it if needed`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
commands.Play(ctx, client)
|
commands.Play(ctx)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,6 +14,6 @@ var playurlCmd = &cobra.Command{
|
|||||||
Args: cobra.MatchAll(cobra.ExactArgs(1)),
|
Args: cobra.MatchAll(cobra.ExactArgs(1)),
|
||||||
Long: `Plays song from provided url`,
|
Long: `Plays song from provided url`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
commands.PlayUrl(ctx, client, args)
|
commands.PlayUrl(ctx, args)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,6 +14,6 @@ var previousCmd = &cobra.Command{
|
|||||||
Short: "goes to previous song",
|
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`,
|
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) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
commands.Previous(ctx, client)
|
commands.Previous(ctx)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,6 +14,6 @@ var radioCmd = &cobra.Command{
|
|||||||
Short: "Starts radio",
|
Short: "Starts radio",
|
||||||
Long: `Starts radio`,
|
Long: `Starts radio`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return commands.Radio(ctx, client)
|
return commands.Radio(ctx)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,6 +14,6 @@ var refillRadioCmd = &cobra.Command{
|
|||||||
Short: "Refills the radio",
|
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`,
|
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 {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return commands.RefillRadio(ctx, client)
|
return commands.RefillRadio(ctx)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,6 +13,6 @@ var repeatCmd = &cobra.Command{
|
|||||||
Short: "Toggles repeat",
|
Short: "Toggles repeat",
|
||||||
Long: `Switches between repeating your current context or not, spotifyd does not support single track loops`,
|
Long: `Switches between repeating your current context or not, spotifyd does not support single track loops`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
commands.Repeat(ctx, client)
|
commands.Repeat(ctx)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
cmds "gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
||||||
|
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/config"
|
"gitea.asdf.cafe/abs3nt/gospt/src/config"
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/gctx"
|
"gitea.asdf.cafe/abs3nt/gospt/src/gctx"
|
||||||
"tuxpa.in/a/zlog"
|
"tuxpa.in/a/zlog"
|
||||||
@ -19,7 +22,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
// Used for flags.
|
// Used for flags.
|
||||||
ctx *gctx.Context
|
ctx *gctx.Context
|
||||||
commands *commands.Commands
|
commands *cmds.Commands
|
||||||
cfgFile string
|
cfgFile string
|
||||||
userLicense string
|
userLicense string
|
||||||
verbose bool
|
verbose bool
|
||||||
@ -51,14 +54,14 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose logging")
|
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose logging")
|
||||||
|
|
||||||
cobra.OnInitialize(func() {
|
cobra.OnInitialize(func() {
|
||||||
if verbose {
|
if verbose {
|
||||||
zlog.SetGlobalLevel(zlog.TraceLevel)
|
zlog.SetGlobalLevel(zlog.TraceLevel)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
cobra.OnInitialize(initConfig, initClient)
|
ctx = gctx.NewContext(context.Background())
|
||||||
|
commands = &cmds.Commands{Context: ctx}
|
||||||
|
cobra.OnInitialize(initConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initConfig() {
|
func initConfig() {
|
||||||
|
@ -3,8 +3,6 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"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`,
|
Long: `Seeks forward or backward, or seeks to a given position in seconds`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if args[0] == "forward" || args[0] == "f" {
|
if args[0] == "forward" || args[0] == "f" {
|
||||||
err := commands.Seek(ctx, client, true)
|
err := commands.Seek(ctx, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -28,7 +26,7 @@ var seekCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if args[0] == "backward" || args[0] == "b" {
|
if args[0] == "backward" || args[0] == "b" {
|
||||||
err := commands.Seek(ctx, client, false)
|
err := commands.Seek(ctx, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -40,7 +38,7 @@ var seekCmd = &cobra.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
pos = pos * 1000
|
pos = pos * 1000
|
||||||
err = commands.SetPosition(ctx, client, pos)
|
err = commands.SetPosition(ctx, pos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,6 @@ var setDeviceCmd = &cobra.Command{
|
|||||||
Short: "Shows tui to pick active device",
|
Short: "Shows tui to pick active device",
|
||||||
Long: `Allows setting or changing the active spotify device, shown in a tui`,
|
Long: `Allows setting or changing the active spotify device, shown in a tui`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
tui.StartTea(ctx, client, "devices")
|
tui.StartTea(ctx, commands, "devices")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,6 +13,6 @@ var shuffleCmd = &cobra.Command{
|
|||||||
Short: "Toggles shuffle",
|
Short: "Toggles shuffle",
|
||||||
Long: `Enables shuffle if it is currently disabled or disables it if it is currently active`,
|
Long: `Enables shuffle if it is currently disabled or disables it if it is currently active`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
commands.Shuffle(ctx, client)
|
commands.Shuffle(ctx)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,6 +13,6 @@ var statusCmd = &cobra.Command{
|
|||||||
Short: "Returns player status in json",
|
Short: "Returns player status in json",
|
||||||
Long: `Returns all player status in json, useful for scripting`,
|
Long: `Returns all player status in json, useful for scripting`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
commands.Status(ctx, client)
|
commands.Status(ctx)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,6 +14,6 @@ var togglePlayCmd = &cobra.Command{
|
|||||||
Short: "Toggles the play state of spotify",
|
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`,
|
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) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
commands.TogglePlay(ctx, client)
|
commands.TogglePlay(ctx)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/tui"
|
"gitea.asdf.cafe/abs3nt/gospt/src/tui"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -20,12 +19,12 @@ var tracksCmd = &cobra.Command{
|
|||||||
Long: `Uses TUI to open a list of saved tracks`,
|
Long: `Uses TUI to open a list of saved tracks`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
configDir, _ := os.UserConfigDir()
|
configDir, _ := os.UserConfigDir()
|
||||||
if commands.ActiveDeviceExists(ctx, client) {
|
if commands.ActiveDeviceExists(ctx) {
|
||||||
return tui.StartTea(ctx, client, "tracks")
|
return tui.StartTea(ctx, commands, "tracks")
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(filepath.Join(configDir, "gospt/device.json")); err != nil {
|
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")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/tui"
|
"gitea.asdf.cafe/abs3nt/gospt/src/tui"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"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.`,
|
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 {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
configDir, _ := os.UserConfigDir()
|
configDir, _ := os.UserConfigDir()
|
||||||
if commands.ActiveDeviceExists(ctx, client) {
|
if commands.ActiveDeviceExists(ctx) {
|
||||||
return tui.StartTea(ctx, client, "main")
|
return tui.StartTea(ctx, commands, "main")
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(filepath.Join(configDir, "gospt/device.json")); err != nil {
|
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")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,6 +14,6 @@ var unlikeCmd = &cobra.Command{
|
|||||||
Short: "unlikes song",
|
Short: "unlikes song",
|
||||||
Long: `unlikes song`,
|
Long: `unlikes song`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
commands.Unlike(ctx, client)
|
commands.Unlike(ctx)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,7 +13,7 @@ var unmuteCmd = &cobra.Command{
|
|||||||
Short: "unmutes playback",
|
Short: "unmutes playback",
|
||||||
Long: `unmutes the spotify device, playback will continue`,
|
Long: `unmutes the spotify device, playback will continue`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
err := commands.SetVolume(ctx, client, 100)
|
err := commands.SetVolume(ctx, 100)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,6 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"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`,
|
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 {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if args[0] == "up" {
|
if args[0] == "up" {
|
||||||
err := commands.ChangeVolume(ctx, client, 5)
|
err := commands.ChangeVolume(ctx, 5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -28,7 +26,7 @@ var volumeCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if args[0] == "down" {
|
if args[0] == "down" {
|
||||||
err := commands.ChangeVolume(ctx, client, -5)
|
err := commands.ChangeVolume(ctx, -5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -39,7 +37,7 @@ var volumeCmd = &cobra.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = commands.SetVolume(ctx, client, vol)
|
err = commands.SetVolume(ctx, vol)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
@ -25,8 +24,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Commands struct {
|
type Commands struct {
|
||||||
cl *spotify.Client
|
Context *gctx.Context
|
||||||
mu sync.RWMutex
|
cl *spotify.Client
|
||||||
|
mu sync.RWMutex
|
||||||
|
|
||||||
user string
|
user string
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ func (c *Commands) User() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commands) connectClient() *spotify.Client {
|
func (c *Commands) connectClient() *spotify.Client {
|
||||||
ctx := gctx.NewContext(context.Background())
|
ctx := c.Context
|
||||||
client, err := auth.GetClient(ctx)
|
client, err := auth.GetClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -58,7 +58,7 @@ func (c *Commands) connectClient() *spotify.Client {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
c.user = currentUser.ID
|
c.user = currentUser.ID
|
||||||
return &spotify.Client{}
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commands) SetVolume(ctx *gctx.Context, vol int) error {
|
func (c *Commands) SetVolume(ctx *gctx.Context, vol int) error {
|
||||||
|
@ -2,15 +2,25 @@ package gctx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"tuxpa.in/a/zlog"
|
"tuxpa.in/a/zlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Context struct {
|
type Context struct {
|
||||||
context.Context
|
|
||||||
zlog.Logger
|
zlog.Logger
|
||||||
Debug 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 {
|
func NewContext(ctx context.Context) *Context {
|
||||||
|
@ -7,95 +7,95 @@ import (
|
|||||||
"github.com/zmb3/spotify/v2"
|
"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
|
var err error
|
||||||
err = commands.PlaySongInPlaylist(ctx, client, uri, pos)
|
err = commands.PlaySongInPlaylist(ctx, uri, pos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleRadio(ctx *gctx.Context, client *spotify.Client, song spotify.SimpleTrack) {
|
func HandleRadio(ctx *gctx.Context, commands *commands.Commands, song spotify.SimpleTrack) {
|
||||||
err := commands.RadioGivenSong(ctx, client, song, 0)
|
err := commands.RadioGivenSong(ctx, song, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleAlbumRadio(ctx *gctx.Context, client *spotify.Client, album spotify.SimpleAlbum) {
|
func HandleAlbumRadio(ctx *gctx.Context, commands *commands.Commands, album spotify.SimpleAlbum) {
|
||||||
err := commands.RadioFromAlbum(ctx, client, album)
|
err := commands.RadioFromAlbum(ctx, album)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleSeek(ctx *gctx.Context, client *spotify.Client, fwd bool) {
|
func HandleSeek(ctx *gctx.Context, commands *commands.Commands, fwd bool) {
|
||||||
err := commands.Seek(ctx, client, fwd)
|
err := commands.Seek(ctx, fwd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleVolume(ctx *gctx.Context, client *spotify.Client, up bool) {
|
func HandleVolume(ctx *gctx.Context, commands *commands.Commands, up bool) {
|
||||||
vol := 10
|
vol := 10
|
||||||
if !up {
|
if !up {
|
||||||
vol = -10
|
vol = -10
|
||||||
}
|
}
|
||||||
err := commands.ChangeVolume(ctx, client, vol)
|
err := commands.ChangeVolume(ctx, vol)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleArtistRadio(ctx *gctx.Context, client *spotify.Client, artist spotify.SimpleArtist) {
|
func HandleArtistRadio(ctx *gctx.Context, commands *commands.Commands, artist spotify.SimpleArtist) {
|
||||||
err := commands.RadioGivenArtist(ctx, client, artist)
|
err := commands.RadioGivenArtist(ctx, artist)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleAlbumArtist(ctx *gctx.Context, client *spotify.Client, artist spotify.SimpleArtist) {
|
func HandleAlbumArtist(ctx *gctx.Context, commands *commands.Commands, artist spotify.SimpleArtist) {
|
||||||
err := commands.RadioGivenArtist(ctx, client, artist)
|
err := commands.RadioGivenArtist(ctx, artist)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandlePlaylistRadio(ctx *gctx.Context, client *spotify.Client, playlist spotify.SimplePlaylist) {
|
func HandlePlaylistRadio(ctx *gctx.Context, commands *commands.Commands, playlist spotify.SimplePlaylist) {
|
||||||
err := commands.RadioFromPlaylist(ctx, client, playlist)
|
err := commands.RadioFromPlaylist(ctx, playlist)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleLibraryRadio(ctx *gctx.Context, client *spotify.Client) {
|
func HandleLibraryRadio(ctx *gctx.Context, commands *commands.Commands) {
|
||||||
err := commands.RadioFromSavedTracks(ctx, client)
|
err := commands.RadioFromSavedTracks(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandlePlayLikedSong(ctx *gctx.Context, client *spotify.Client, position int) {
|
func HandlePlayLikedSong(ctx *gctx.Context, commands *commands.Commands, position int) {
|
||||||
err := commands.PlayLikedSongs(ctx, client, position)
|
err := commands.PlayLikedSongs(ctx, position)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandlePlayTrack(ctx *gctx.Context, client *spotify.Client, track spotify.ID) {
|
func HandlePlayTrack(ctx *gctx.Context, commands *commands.Commands, track spotify.ID) {
|
||||||
err := commands.QueueSong(ctx, client, track)
|
err := commands.QueueSong(ctx, track)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = commands.Next(ctx, client, 1)
|
err = commands.Next(ctx, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
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
|
var err error
|
||||||
err = commands.SetDevice(ctx, client, player)
|
err = commands.SetDevice(ctx, player)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/list"
|
"github.com/charmbracelet/bubbles/list"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m *mainModel) LoadMoreItems() {
|
func (m *mainModel) LoadMoreItems() {
|
||||||
switch m.mode {
|
switch m.mode {
|
||||||
case "artist":
|
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++
|
page++
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -32,7 +30,7 @@ func (m *mainModel) LoadMoreItems() {
|
|||||||
main_updates <- m
|
main_updates <- m
|
||||||
return
|
return
|
||||||
case "artists":
|
case "artists":
|
||||||
artists, err := commands.UserArtists(m.ctx, m.client, (page + 1))
|
artists, err := m.commands.UserArtists(m.ctx, (page + 1))
|
||||||
page++
|
page++
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -52,7 +50,7 @@ func (m *mainModel) LoadMoreItems() {
|
|||||||
main_updates <- m
|
main_updates <- m
|
||||||
return
|
return
|
||||||
case "album":
|
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++
|
page++
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -73,7 +71,7 @@ func (m *mainModel) LoadMoreItems() {
|
|||||||
main_updates <- m
|
main_updates <- m
|
||||||
return
|
return
|
||||||
case "albums":
|
case "albums":
|
||||||
albums, err := commands.UserAlbums(m.ctx, m.client, (page + 1))
|
albums, err := m.commands.UserAlbums(m.ctx, (page + 1))
|
||||||
page++
|
page++
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -93,7 +91,7 @@ func (m *mainModel) LoadMoreItems() {
|
|||||||
main_updates <- m
|
main_updates <- m
|
||||||
return
|
return
|
||||||
case "main":
|
case "main":
|
||||||
playlists, err := commands.Playlists(m.ctx, m.client, (page + 1))
|
playlists, err := m.commands.Playlists(m.ctx, (page + 1))
|
||||||
page++
|
page++
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -112,7 +110,7 @@ func (m *mainModel) LoadMoreItems() {
|
|||||||
main_updates <- m
|
main_updates <- m
|
||||||
return
|
return
|
||||||
case "playlist":
|
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++
|
page++
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -133,7 +131,7 @@ func (m *mainModel) LoadMoreItems() {
|
|||||||
main_updates <- m
|
main_updates <- m
|
||||||
return
|
return
|
||||||
case "tracks":
|
case "tracks":
|
||||||
tracks, err := commands.TrackList(m.ctx, m.client, (page + 1))
|
tracks, err := m.commands.TrackList(m.ctx, (page + 1))
|
||||||
page++
|
page++
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
115
src/tui/main.go
115
src/tui/main.go
@ -5,6 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/gctx"
|
"gitea.asdf.cafe/abs3nt/gospt/src/gctx"
|
||||||
|
|
||||||
"github.com/atotto/clipboard"
|
"github.com/atotto/clipboard"
|
||||||
@ -74,7 +75,7 @@ type mainModel struct {
|
|||||||
list list.Model
|
list list.Model
|
||||||
input textinput.Model
|
input textinput.Model
|
||||||
ctx *gctx.Context
|
ctx *gctx.Context
|
||||||
client *spotify.Client
|
commands *commands.Commands
|
||||||
mode Mode
|
mode Mode
|
||||||
playlist spotify.SimplePlaylist
|
playlist spotify.SimplePlaylist
|
||||||
artist spotify.SimpleArtist
|
artist spotify.SimpleArtist
|
||||||
@ -91,34 +92,34 @@ func (m *mainModel) PlayRadio() {
|
|||||||
selectedItem := m.list.SelectedItem().(mainItem).SpotifyItem
|
selectedItem := m.list.SelectedItem().(mainItem).SpotifyItem
|
||||||
switch selectedItem.(type) {
|
switch selectedItem.(type) {
|
||||||
case spotify.SimplePlaylist:
|
case spotify.SimplePlaylist:
|
||||||
go HandlePlaylistRadio(m.ctx, m.client, selectedItem.(spotify.SimplePlaylist))
|
go HandlePlaylistRadio(m.ctx, m.commands, selectedItem.(spotify.SimplePlaylist))
|
||||||
return
|
return
|
||||||
case *spotify.SavedTrackPage:
|
case *spotify.SavedTrackPage:
|
||||||
go HandleLibraryRadio(m.ctx, m.client)
|
go HandleLibraryRadio(m.ctx, m.commands)
|
||||||
return
|
return
|
||||||
case spotify.SimpleAlbum:
|
case spotify.SimpleAlbum:
|
||||||
go HandleAlbumRadio(m.ctx, m.client, selectedItem.(spotify.SimpleAlbum))
|
go HandleAlbumRadio(m.ctx, m.commands, selectedItem.(spotify.SimpleAlbum))
|
||||||
return
|
return
|
||||||
case spotify.FullAlbum:
|
case spotify.FullAlbum:
|
||||||
go HandleAlbumRadio(m.ctx, m.client, selectedItem.(spotify.FullAlbum).SimpleAlbum)
|
go HandleAlbumRadio(m.ctx, m.commands, selectedItem.(spotify.FullAlbum).SimpleAlbum)
|
||||||
return
|
return
|
||||||
case spotify.SimpleArtist:
|
case spotify.SimpleArtist:
|
||||||
go HandleArtistRadio(m.ctx, m.client, selectedItem.(spotify.SimpleArtist))
|
go HandleArtistRadio(m.ctx, m.commands, selectedItem.(spotify.SimpleArtist))
|
||||||
return
|
return
|
||||||
case spotify.FullArtist:
|
case spotify.FullArtist:
|
||||||
go HandleArtistRadio(m.ctx, m.client, selectedItem.(spotify.FullArtist).SimpleArtist)
|
go HandleArtistRadio(m.ctx, m.commands, selectedItem.(spotify.FullArtist).SimpleArtist)
|
||||||
return
|
return
|
||||||
case spotify.SimpleTrack:
|
case spotify.SimpleTrack:
|
||||||
go HandleRadio(m.ctx, m.client, selectedItem.(spotify.SimpleTrack))
|
go HandleRadio(m.ctx, m.commands, selectedItem.(spotify.SimpleTrack))
|
||||||
return
|
return
|
||||||
case spotify.FullTrack:
|
case spotify.FullTrack:
|
||||||
go HandleRadio(m.ctx, m.client, selectedItem.(spotify.FullTrack).SimpleTrack)
|
go HandleRadio(m.ctx, m.commands, selectedItem.(spotify.FullTrack).SimpleTrack)
|
||||||
return
|
return
|
||||||
case spotify.PlaylistTrack:
|
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
|
return
|
||||||
case spotify.SavedTrack:
|
case spotify.SavedTrack:
|
||||||
go HandleRadio(m.ctx, m.client, selectedItem.(spotify.SavedTrack).SimpleTrack)
|
go HandleRadio(m.ctx, m.commands, selectedItem.(spotify.SavedTrack).SimpleTrack)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,34 +130,34 @@ func (m *mainModel) GoBack() (tea.Cmd, error) {
|
|||||||
return tea.Quit, nil
|
return tea.Quit, nil
|
||||||
case Albums, Artists, Tracks, Playlist, Devices, Search:
|
case Albums, Artists, Tracks, Playlist, Devices, Search:
|
||||||
m.mode = Main
|
m.mode = Main
|
||||||
new_items, err := MainView(m.ctx, m.client)
|
new_items, err := MainView(m.ctx, m.commands)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
}
|
}
|
||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
case Album:
|
case Album:
|
||||||
m.mode = Albums
|
m.mode = Albums
|
||||||
new_items, err := AlbumsView(m.ctx, m.client)
|
new_items, err := AlbumsView(m.ctx, m.commands)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
case Artist:
|
case Artist:
|
||||||
m.mode = Artists
|
m.mode = Artists
|
||||||
new_items, err := ArtistsView(m.ctx, m.client)
|
new_items, err := ArtistsView(m.ctx, m.commands)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
case ArtistAlbum:
|
case ArtistAlbum:
|
||||||
m.mode = Artist
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
case SearchArtists, SearchTracks, SearchAlbums, SearchPlaylists:
|
case SearchArtists, SearchTracks, SearchAlbums, SearchPlaylists:
|
||||||
m.mode = Search
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -164,28 +165,28 @@ func (m *mainModel) GoBack() (tea.Cmd, error) {
|
|||||||
m.list.SetItems(items)
|
m.list.SetItems(items)
|
||||||
case SearchArtist:
|
case SearchArtist:
|
||||||
m.mode = SearchArtists
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
case SearchArtistAlbum:
|
case SearchArtistAlbum:
|
||||||
m.mode = SearchArtist
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
case SearchAlbum:
|
case SearchAlbum:
|
||||||
m.mode = SearchAlbums
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
case SearchPlaylist:
|
case SearchPlaylist:
|
||||||
m.mode = SearchPlaylists
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -243,7 +244,7 @@ func (m *mainModel) SelectItem() error {
|
|||||||
switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) {
|
switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) {
|
||||||
case *spotify.FullArtistPage:
|
case *spotify.FullArtistPage:
|
||||||
m.mode = SearchArtists
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -251,7 +252,7 @@ func (m *mainModel) SelectItem() error {
|
|||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case *spotify.SimpleAlbumPage:
|
case *spotify.SimpleAlbumPage:
|
||||||
m.mode = SearchAlbums
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -260,7 +261,7 @@ func (m *mainModel) SelectItem() error {
|
|||||||
case *spotify.SimplePlaylistPage:
|
case *spotify.SimplePlaylistPage:
|
||||||
m.mode = SearchPlaylists
|
m.mode = SearchPlaylists
|
||||||
playlists := m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.SimplePlaylistPage)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -268,7 +269,7 @@ func (m *mainModel) SelectItem() error {
|
|||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case *spotify.FullTrackPage:
|
case *spotify.FullTrackPage:
|
||||||
m.mode = SearchTracks
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -278,7 +279,7 @@ func (m *mainModel) SelectItem() error {
|
|||||||
case SearchArtists:
|
case SearchArtists:
|
||||||
m.mode = SearchArtist
|
m.mode = SearchArtist
|
||||||
m.artist = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleArtist)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -287,7 +288,7 @@ func (m *mainModel) SelectItem() error {
|
|||||||
case SearchArtist:
|
case SearchArtist:
|
||||||
m.mode = SearchArtistAlbum
|
m.mode = SearchArtistAlbum
|
||||||
m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -296,7 +297,7 @@ func (m *mainModel) SelectItem() error {
|
|||||||
case SearchAlbums:
|
case SearchAlbums:
|
||||||
m.mode = SearchAlbum
|
m.mode = SearchAlbum
|
||||||
m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -306,7 +307,7 @@ func (m *mainModel) SelectItem() error {
|
|||||||
m.mode = SearchPlaylist
|
m.mode = SearchPlaylist
|
||||||
playlist := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist)
|
playlist := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist)
|
||||||
m.playlist = playlist
|
m.playlist = playlist
|
||||||
new_items, err := PlaylistView(m.ctx, m.client, playlist)
|
new_items, err := PlaylistView(m.ctx, m.commands, playlist)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -316,7 +317,7 @@ func (m *mainModel) SelectItem() error {
|
|||||||
switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) {
|
switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) {
|
||||||
case *spotify.FullArtistCursorPage:
|
case *spotify.FullArtistCursorPage:
|
||||||
m.mode = Artists
|
m.mode = Artists
|
||||||
new_items, err := ArtistsView(m.ctx, m.client)
|
new_items, err := ArtistsView(m.ctx, m.commands)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -324,7 +325,7 @@ func (m *mainModel) SelectItem() error {
|
|||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case *spotify.SavedAlbumPage:
|
case *spotify.SavedAlbumPage:
|
||||||
m.mode = Albums
|
m.mode = Albums
|
||||||
new_items, err := AlbumsView(m.ctx, m.client)
|
new_items, err := AlbumsView(m.ctx, m.commands)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -334,7 +335,7 @@ func (m *mainModel) SelectItem() error {
|
|||||||
m.mode = Playlist
|
m.mode = Playlist
|
||||||
playlist := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist)
|
playlist := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist)
|
||||||
m.playlist = playlist
|
m.playlist = playlist
|
||||||
new_items, err := PlaylistView(m.ctx, m.client, playlist)
|
new_items, err := PlaylistView(m.ctx, m.commands, playlist)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -342,7 +343,7 @@ func (m *mainModel) SelectItem() error {
|
|||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case *spotify.SavedTrackPage:
|
case *spotify.SavedTrackPage:
|
||||||
m.mode = Tracks
|
m.mode = Tracks
|
||||||
new_items, err := SavedTracksView(m.ctx, m.client)
|
new_items, err := SavedTracksView(m.ctx, m.commands)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -352,7 +353,7 @@ func (m *mainModel) SelectItem() error {
|
|||||||
case Albums:
|
case Albums:
|
||||||
m.mode = Album
|
m.mode = Album
|
||||||
m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -361,7 +362,7 @@ func (m *mainModel) SelectItem() error {
|
|||||||
case Artist:
|
case Artist:
|
||||||
m.mode = ArtistAlbum
|
m.mode = ArtistAlbum
|
||||||
m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -370,26 +371,26 @@ func (m *mainModel) SelectItem() error {
|
|||||||
case Artists:
|
case Artists:
|
||||||
m.mode = Artist
|
m.mode = Artist
|
||||||
m.artist = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleArtist)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case Album, ArtistAlbum, SearchArtistAlbum, SearchAlbum:
|
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:
|
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:
|
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:
|
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:
|
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.list.NewStatusMessage("Setting device to " + m.list.SelectedItem().FilterValue())
|
||||||
m.mode = "main"
|
m.mode = "main"
|
||||||
m.list.NewStatusMessage("Setting view to 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -412,7 +413,7 @@ func Tick() tea.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mainModel) TickPlayback() {
|
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 {
|
if playing != nil && playing.Playing && playing.Item != nil {
|
||||||
currentlyPlaying = playing
|
currentlyPlaying = playing
|
||||||
playbackContext, _ = m.getContext(playing)
|
playbackContext, _ = m.getContext(playing)
|
||||||
@ -423,7 +424,7 @@ func (m *mainModel) TickPlayback() {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
playing, _ := m.client.PlayerCurrentlyPlaying(m.ctx)
|
playing, _ := m.commands.Client().PlayerCurrentlyPlaying(m.ctx)
|
||||||
if playing != nil && playing.Playing && playing.Item != nil {
|
if playing != nil && playing.Playing && playing.Item != nil {
|
||||||
currentlyPlaying = playing
|
currentlyPlaying = playing
|
||||||
playbackContext, _ = m.getContext(playing)
|
playbackContext, _ = m.getContext(playing)
|
||||||
@ -445,7 +446,7 @@ func (m mainModel) View() string {
|
|||||||
|
|
||||||
func (m *mainModel) Typing(msg tea.KeyMsg) (bool, tea.Cmd) {
|
func (m *mainModel) Typing(msg tea.KeyMsg) (bool, tea.Cmd) {
|
||||||
if msg.String() == "enter" {
|
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 {
|
if err != nil {
|
||||||
return false, tea.Quit
|
return false, tea.Quit
|
||||||
}
|
}
|
||||||
@ -475,19 +476,19 @@ func (m *mainModel) getContext(playing *spotify.CurrentlyPlaying) (string, error
|
|||||||
id := strings.Split(string(context.URI), ":")[2]
|
id := strings.Split(string(context.URI), ":")[2]
|
||||||
switch context.Type {
|
switch context.Type {
|
||||||
case "album":
|
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 {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return album.Name, nil
|
return album.Name, nil
|
||||||
case "playlist":
|
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 {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return playlist.Name, nil
|
return playlist.Name, nil
|
||||||
case "artist":
|
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 {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -547,16 +548,16 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if msg.String() == ">" {
|
if msg.String() == ">" {
|
||||||
go HandleSeek(m.ctx, m.client, true)
|
go HandleSeek(m.ctx, m.commands, true)
|
||||||
}
|
}
|
||||||
if msg.String() == "<" {
|
if msg.String() == "<" {
|
||||||
go HandleSeek(m.ctx, m.client, false)
|
go HandleSeek(m.ctx, m.commands, false)
|
||||||
}
|
}
|
||||||
if msg.String() == "+" {
|
if msg.String() == "+" {
|
||||||
go HandleVolume(m.ctx, m.client, true)
|
go HandleVolume(m.ctx, m.commands, true)
|
||||||
}
|
}
|
||||||
if msg.String() == "-" {
|
if msg.String() == "-" {
|
||||||
go HandleVolume(m.ctx, m.client, false)
|
go HandleVolume(m.ctx, m.commands, false)
|
||||||
}
|
}
|
||||||
// search input
|
// search input
|
||||||
if m.input.Focused() {
|
if m.input.Focused() {
|
||||||
@ -573,7 +574,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
// enter device selection
|
// enter device selection
|
||||||
if msg.String() == "d" {
|
if msg.String() == "d" {
|
||||||
m.mode = Devices
|
m.mode = Devices
|
||||||
new_items, err := DeviceView(m.ctx, m.client)
|
new_items, err := DeviceView(m.ctx, m.commands)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
@ -624,24 +625,24 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return m, 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())
|
prog := progress.New(progress.WithColorProfile(2), progress.WithoutPercentage())
|
||||||
var err error
|
var err error
|
||||||
lipgloss.SetColorProfile(2)
|
lipgloss.SetColorProfile(2)
|
||||||
items := []list.Item{}
|
items := []list.Item{}
|
||||||
switch mode {
|
switch mode {
|
||||||
case Main:
|
case Main:
|
||||||
items, err = MainView(ctx, client)
|
items, err = MainView(ctx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case Devices:
|
case Devices:
|
||||||
items, err = DeviceView(ctx, client)
|
items, err = DeviceView(ctx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case Tracks:
|
case Tracks:
|
||||||
items, err = SavedTracksView(ctx, client)
|
items, err = SavedTracksView(ctx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -649,7 +650,7 @@ func InitMain(ctx *gctx.Context, client *spotify.Client, mode Mode) (tea.Model,
|
|||||||
m := mainModel{
|
m := mainModel{
|
||||||
list: list.New(items, list.NewDefaultDelegate(), 0, 0),
|
list: list.New(items, list.NewDefaultDelegate(), 0, 0),
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
client: client,
|
commands: c,
|
||||||
mode: mode,
|
mode: mode,
|
||||||
progress: prog,
|
progress: prog,
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,15 @@ package tui
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
|
||||||
"gitea.asdf.cafe/abs3nt/gospt/src/gctx"
|
"gitea.asdf.cafe/abs3nt/gospt/src/gctx"
|
||||||
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/zmb3/spotify/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// StartTea the entry point for the UI. Initializes the model.
|
// StartTea the entry point for the UI. Initializes the model.
|
||||||
func StartTea(ctx *gctx.Context, client *spotify.Client, mode string) error {
|
func StartTea(ctx *gctx.Context, cmd *commands.Commands, mode string) error {
|
||||||
m, err := InitMain(ctx, client, Mode(mode))
|
m, err := InitMain(ctx, cmd, Mode(mode))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("UH OH")
|
fmt.Println("UH OH")
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,9 @@ import (
|
|||||||
"github.com/zmb3/spotify/v2"
|
"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{}
|
items := []list.Item{}
|
||||||
devices, err := client.PlayerDevices(ctx)
|
devices, err := commands.Client().PlayerDevices(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -28,9 +28,9 @@ func DeviceView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error)
|
|||||||
return items, nil
|
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{}
|
items := []list.Item{}
|
||||||
tracks, err := commands.PlaylistTracks(ctx, client, playlist.ID, 1)
|
tracks, err := commands.PlaylistTracks(ctx, playlist.ID, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -47,9 +47,9 @@ func PlaylistView(ctx *gctx.Context, client *spotify.Client, playlist spotify.Si
|
|||||||
return items, nil
|
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{}
|
items := []list.Item{}
|
||||||
artists, err := commands.UserArtists(ctx, client, 1)
|
artists, err := commands.UserArtists(ctx, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ func ArtistsView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error)
|
|||||||
return items, nil
|
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{}
|
items := []list.Item{}
|
||||||
for _, artist := range artists.Artists {
|
for _, artist := range artists.Artists {
|
||||||
items = append(items, mainItem{
|
items = append(items, mainItem{
|
||||||
@ -77,10 +77,10 @@ func SearchArtistsView(ctx *gctx.Context, client *spotify.Client, artists *spoti
|
|||||||
return items, nil
|
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{}
|
items := []list.Item{}
|
||||||
|
|
||||||
result, err := commands.Search(ctx, client, search, 1)
|
result, err := commands.Search(ctx, search, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -114,9 +114,9 @@ func SearchView(ctx *gctx.Context, client *spotify.Client, search string) ([]lis
|
|||||||
return items, results, nil
|
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{}
|
items := []list.Item{}
|
||||||
albums, err := commands.UserAlbums(ctx, client, 1)
|
albums, err := commands.UserAlbums(ctx, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ func AlbumsView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error)
|
|||||||
return items, nil
|
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{}
|
items := []list.Item{}
|
||||||
for _, playlist := range playlists.Playlists {
|
for _, playlist := range playlists.Playlists {
|
||||||
items = append(items, mainItem{
|
items = append(items, mainItem{
|
||||||
@ -143,7 +143,7 @@ func SearchPlaylistsView(ctx *gctx.Context, client *spotify.Client, playlists *s
|
|||||||
return items, nil
|
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{}
|
items := []list.Item{}
|
||||||
for _, album := range albums.Albums {
|
for _, album := range albums.Albums {
|
||||||
items = append(items, mainItem{
|
items = append(items, mainItem{
|
||||||
@ -156,9 +156,9 @@ func SearchAlbumsView(ctx *gctx.Context, client *spotify.Client, albums *spotify
|
|||||||
return items, nil
|
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{}
|
items := []list.Item{}
|
||||||
albums, err := commands.ArtistAlbums(ctx, client, album, 1)
|
albums, err := commands.ArtistAlbums(ctx, album, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -173,9 +173,9 @@ func ArtistAlbumsView(ctx *gctx.Context, album spotify.ID, client *spotify.Clien
|
|||||||
return items, err
|
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{}
|
items := []list.Item{}
|
||||||
tracks, err := commands.AlbumTracks(ctx, client, album, 1)
|
tracks, err := commands.AlbumTracks(ctx, album, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -192,7 +192,7 @@ func AlbumTracksView(ctx *gctx.Context, album spotify.ID, client *spotify.Client
|
|||||||
return items, err
|
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{}
|
items := []list.Item{}
|
||||||
for _, track := range tracks.Tracks {
|
for _, track := range tracks.Tracks {
|
||||||
items = append(items, mainItem{
|
items = append(items, mainItem{
|
||||||
@ -207,9 +207,9 @@ func SearchTracksView(ctx *gctx.Context, client *spotify.Client, tracks *spotify
|
|||||||
return items, nil
|
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{}
|
items := []list.Item{}
|
||||||
tracks, err := commands.TrackList(ctx, client, 1)
|
tracks, err := commands.TrackList(ctx, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -226,7 +226,7 @@ func SavedTracksView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, er
|
|||||||
return items, err
|
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 wg sync.WaitGroup
|
||||||
var saved_items *spotify.SavedTrackPage
|
var saved_items *spotify.SavedTrackPage
|
||||||
var playlists *spotify.SimplePlaylistPage
|
var playlists *spotify.SimplePlaylistPage
|
||||||
@ -237,7 +237,7 @@ func MainView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) {
|
|||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
var err error
|
var err error
|
||||||
saved_items, err = commands.TrackList(ctx, client, 1)
|
saved_items, err = commands.TrackList(ctx, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
return
|
return
|
||||||
@ -248,7 +248,7 @@ func MainView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) {
|
|||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
var err error
|
var err error
|
||||||
playlists, err = commands.Playlists(ctx, client, 1)
|
playlists, err = commands.Playlists(ctx, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
return
|
return
|
||||||
@ -259,7 +259,7 @@ func MainView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) {
|
|||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
var err error
|
var err error
|
||||||
artists, err = commands.UserArtists(ctx, client, 1)
|
artists, err = commands.UserArtists(ctx, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
return
|
return
|
||||||
@ -270,7 +270,7 @@ func MainView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) {
|
|||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
var err error
|
var err error
|
||||||
albums, err = commands.UserAlbums(ctx, client, 1)
|
albums, err = commands.UserAlbums(ctx, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user