resturcture3

This commit is contained in:
jjohnstondev 2023-01-07 21:34:31 -08:00
parent 4fab5338b2
commit 01d3958de0
4 changed files with 35 additions and 10 deletions

View File

@ -1,4 +1,4 @@
package runner package api
import ( import (
"fmt" "fmt"

View File

@ -40,15 +40,44 @@ func PlayUrl(ctx *gctx.Context, client *spotify.Client, args []string) error {
err = client.QueueSong(ctx, spotify.ID(track_id)) err = client.QueueSong(ctx, spotify.ID(track_id))
if err != nil { if err != nil {
if isNoActiveError(err) { 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 return err
} }
err = client.Next(ctx) err = client.Next(ctx)
if err != nil {
return err
}
ctx.Println("Playing!") ctx.Println("Playing!")
return nil 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 { func Radio(ctx *gctx.Context, client *spotify.Client) error {
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().Unix())
current_song, err := client.PlayerCurrentlyPlaying(ctx) current_song, err := client.PlayerCurrentlyPlaying(ctx)
@ -234,10 +263,6 @@ func queueWithTransfer(ctx *gctx.Context, client *spotify.Client, track_id spoti
if err != nil { if err != nil {
return err return err
} }
err = client.Next(ctx)
if err != nil {
return err
}
ctx.Println("Playing!") ctx.Println("Playing!")
return nil return nil
} }

View File

@ -69,11 +69,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg.String() == "enter" { if msg.String() == "enter" {
track := m.list.SelectedItem() track := m.list.SelectedItem()
var err error 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 { if err != nil {
m.ctx.Printf(err.Error()) m.ctx.Printf(err.Error())
} }
err = m.client.Next(m.ctx) err = commands.Skip(m.ctx, m.client)
if err != nil { if err != nil {
m.ctx.Printf(err.Error()) m.ctx.Printf(err.Error())
} }

View File

@ -7,10 +7,10 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"gospt/internal/api"
"gospt/internal/auth" "gospt/internal/auth"
"gospt/internal/config" "gospt/internal/config"
"gospt/internal/gctx" "gospt/internal/gctx"
"gospt/internal/runner"
) )
func init() { func init() {
@ -27,7 +27,7 @@ func main() {
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error())
} }
err = runner.Run(ctx, client, os.Args[1:]) err = api.Run(ctx, client, os.Args[1:])
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }