This commit is contained in:
parent
052bf1cef6
commit
78ab7fe95d
@ -2,6 +2,8 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"gospt/internal/commands"
|
"gospt/internal/commands"
|
||||||
"gospt/internal/gctx"
|
"gospt/internal/gctx"
|
||||||
@ -12,9 +14,15 @@ import (
|
|||||||
|
|
||||||
func Run(ctx *gctx.Context, client *spotify.Client, args []string) error {
|
func Run(ctx *gctx.Context, client *spotify.Client, args []string) error {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
|
configDir, _ := os.UserConfigDir()
|
||||||
|
if _, err := os.Stat(filepath.Join(configDir, "gospt/device.json")); err != nil {
|
||||||
|
return tui.DisplayDevices(ctx, client)
|
||||||
|
}
|
||||||
return tui.DisplayMain(ctx, client)
|
return tui.DisplayMain(ctx, client)
|
||||||
}
|
}
|
||||||
switch args[0] {
|
switch args[0] {
|
||||||
|
case "help", "--help":
|
||||||
|
return commands.PrintHelp(ctx)
|
||||||
case "play":
|
case "play":
|
||||||
return commands.Play(ctx, client)
|
return commands.Play(ctx, client)
|
||||||
case "pause":
|
case "pause":
|
||||||
|
@ -16,6 +16,14 @@ import (
|
|||||||
"github.com/zmb3/spotify/v2"
|
"github.com/zmb3/spotify/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func PrintHelp(ctx *gctx.Context) error {
|
||||||
|
fmt.Println("Usage: gospt [command]")
|
||||||
|
fmt.Println("if no command is provided then TUI will open")
|
||||||
|
fmt.Println("\ncurrently available commands:")
|
||||||
|
fmt.Println("help, play, pause, toggleplay, \nnext, previous, playurl, like, unlike, shuffle, \nrepeat, radio, clearradio, refillradio, tracks, \nclearradio, playlists, status, devices, nowplaying, setdevice")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func Play(ctx *gctx.Context, client *spotify.Client) error {
|
func Play(ctx *gctx.Context, client *spotify.Client) error {
|
||||||
err := client.Play(ctx)
|
err := client.Play(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -43,14 +43,16 @@ func (m deviceModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
if msg.String() == "enter" {
|
if msg.String() == "enter" {
|
||||||
fmt.Println("SELECTING")
|
|
||||||
device := m.list.SelectedItem()
|
device := m.list.SelectedItem()
|
||||||
var err error
|
var err error
|
||||||
err = commands.SetDevice(m.ctx, m.client, device.(deviceItem).PlayerDevice)
|
err = commands.SetDevice(m.ctx, m.client, device.(deviceItem).PlayerDevice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.ctx.Printf(err.Error())
|
m.ctx.Printf(err.Error())
|
||||||
}
|
}
|
||||||
fmt.Println("DEVICE SET")
|
err = DisplayMain(m.ctx, m.client)
|
||||||
|
if err != nil {
|
||||||
|
return m, tea.Quit
|
||||||
|
}
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
case tea.MouseMsg:
|
case tea.MouseMsg:
|
||||||
|
@ -118,7 +118,7 @@ func DisplayMain(ctx *gctx.Context, client *spotify.Client) error {
|
|||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
client: client,
|
client: client,
|
||||||
}
|
}
|
||||||
m.list.Title = "Saved Tracks"
|
m.list.Title = "GOSPT"
|
||||||
|
|
||||||
p := tea.NewProgram(m, tea.WithAltScreen(), tea.WithMouseCellMotion())
|
p := tea.NewProgram(m, tea.WithAltScreen(), tea.WithMouseCellMotion())
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ func PlaylistTracks(ctx *gctx.Context, client *spotify.Client, playlist spotify.
|
|||||||
client: client,
|
client: client,
|
||||||
playlist: playlist,
|
playlist: playlist,
|
||||||
}
|
}
|
||||||
m.list.Title = "Saved Tracks"
|
m.list.Title = playlist.Name
|
||||||
|
|
||||||
p := tea.NewProgram(m, tea.WithAltScreen(), tea.WithMouseCellMotion())
|
p := tea.NewProgram(m, tea.WithAltScreen(), tea.WithMouseCellMotion())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user