From 01d3958de0faaea75cc77ded3aab30c7ce046d32 Mon Sep 17 00:00:00 2001 From: jjohnstondev Date: Sat, 7 Jan 2023 21:34:31 -0800 Subject: [PATCH] resturcture3 --- internal/{runner/runner.go => api/api.go} | 2 +- internal/commands/commands.go | 35 +++++++++++++++++++---- internal/tui/list.go | 4 +-- main.go | 4 +-- 4 files changed, 35 insertions(+), 10 deletions(-) rename internal/{runner/runner.go => api/api.go} (98%) diff --git a/internal/runner/runner.go b/internal/api/api.go similarity index 98% rename from internal/runner/runner.go rename to internal/api/api.go index 410fbfa..226239a 100644 --- a/internal/runner/runner.go +++ b/internal/api/api.go @@ -1,4 +1,4 @@ -package runner +package api import ( "fmt" diff --git a/internal/commands/commands.go b/internal/commands/commands.go index fb36407..bea3927 100644 --- a/internal/commands/commands.go +++ b/internal/commands/commands.go @@ -40,15 +40,44 @@ func PlayUrl(ctx *gctx.Context, client *spotify.Client, args []string) error { err = client.QueueSong(ctx, spotify.ID(track_id)) if err != nil { if isNoActiveError(err) { - return queueWithTransfer(ctx, client, spotify.ID(track_id)) + err = queueWithTransfer(ctx, client, spotify.ID(track_id)) + if err != nil { + return err + } + err = client.Next(ctx) + if err != nil { + return err + } + ctx.Println("Playing!") + return nil } return err } err = client.Next(ctx) + if err != nil { + return err + } ctx.Println("Playing!") return nil } +func QueueSong(ctx *gctx.Context, client *spotify.Client, id spotify.ID) error { + err := client.QueueSong(ctx, id) + if err != nil { + if isNoActiveError(err) { + err := queueWithTransfer(ctx, client, id) + if err != nil { + return err + } + ctx.Println("Queued!") + return nil + } + return err + } + ctx.Println("Queued!") + return nil +} + func Radio(ctx *gctx.Context, client *spotify.Client) error { rand.Seed(time.Now().Unix()) current_song, err := client.PlayerCurrentlyPlaying(ctx) @@ -234,10 +263,6 @@ func queueWithTransfer(ctx *gctx.Context, client *spotify.Client, track_id spoti if err != nil { return err } - err = client.Next(ctx) - if err != nil { - return err - } ctx.Println("Playing!") return nil } diff --git a/internal/tui/list.go b/internal/tui/list.go index 5e1a2fe..1d6307a 100644 --- a/internal/tui/list.go +++ b/internal/tui/list.go @@ -69,11 +69,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if msg.String() == "enter" { track := m.list.SelectedItem() var err error - err = m.client.QueueSong(m.ctx, track.(item).ID) + err = commands.QueueSong(m.ctx, m.client, track.(item).ID) if err != nil { m.ctx.Printf(err.Error()) } - err = m.client.Next(m.ctx) + err = commands.Skip(m.ctx, m.client) if err != nil { m.ctx.Printf(err.Error()) } diff --git a/main.go b/main.go index cec2b26..8b180e1 100644 --- a/main.go +++ b/main.go @@ -7,10 +7,10 @@ import ( "os" "path/filepath" + "gospt/internal/api" "gospt/internal/auth" "gospt/internal/config" "gospt/internal/gctx" - "gospt/internal/runner" ) func init() { @@ -27,7 +27,7 @@ func main() { if err != nil { panic(err.Error()) } - err = runner.Run(ctx, client, os.Args[1:]) + err = api.Run(ctx, client, os.Args[1:]) if err != nil { fmt.Println(err) }