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 (
"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))
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
}

View File

@ -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())
}

View File

@ -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)
}