resturcture2

This commit is contained in:
jjohnstondev 2023-01-07 21:26:06 -08:00
parent 22b8b18c4c
commit 4fab5338b2
6 changed files with 23 additions and 23 deletions

View File

@ -10,7 +10,7 @@ import (
"path/filepath" "path/filepath"
"gospt/internal/config" "gospt/internal/config"
"gospt/internal/ctx" "gospt/internal/gctx"
"github.com/zmb3/spotify/v2" "github.com/zmb3/spotify/v2"
spotifyauth "github.com/zmb3/spotify/v2/auth" spotifyauth "github.com/zmb3/spotify/v2/auth"
@ -23,7 +23,7 @@ var (
state = "abc123" state = "abc123"
) )
func GetClient(ctx *ctx.Context) (*spotify.Client, error) { func GetClient(ctx *gctx.Context) (*spotify.Client, error) {
auth = spotifyauth.New( auth = spotifyauth.New(
spotifyauth.WithClientID(config.Values.ClientId), spotifyauth.WithClientID(config.Values.ClientId),
spotifyauth.WithClientSecret(config.Values.ClientSecret), spotifyauth.WithClientSecret(config.Values.ClientSecret),

View File

@ -11,12 +11,12 @@ import (
"strings" "strings"
"time" "time"
"gospt/internal/ctx" "gospt/internal/gctx"
"github.com/zmb3/spotify/v2" "github.com/zmb3/spotify/v2"
) )
func Play(ctx *ctx.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 {
if isNoActiveError(err) { if isNoActiveError(err) {
@ -28,7 +28,7 @@ func Play(ctx *ctx.Context, client *spotify.Client) error {
return nil return nil
} }
func PlayUrl(ctx *ctx.Context, client *spotify.Client, args []string) error { func PlayUrl(ctx *gctx.Context, client *spotify.Client, args []string) error {
if len(args) < 2 { if len(args) < 2 {
return fmt.Errorf("Please provide a url") return fmt.Errorf("Please provide a url")
} }
@ -49,7 +49,7 @@ func PlayUrl(ctx *ctx.Context, client *spotify.Client, args []string) error {
return nil return nil
} }
func Radio(ctx *ctx.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)
if err != nil { if err != nil {
@ -83,7 +83,7 @@ func Radio(ctx *ctx.Context, client *spotify.Client) error {
return nil return nil
} }
func Devices(ctx *ctx.Context, client *spotify.Client) error { func Devices(ctx *gctx.Context, client *spotify.Client) error {
devices, err := client.PlayerDevices(ctx) devices, err := client.PlayerDevices(ctx)
if err != nil { if err != nil {
return err return err
@ -91,7 +91,7 @@ func Devices(ctx *ctx.Context, client *spotify.Client) error {
return PrintDevices(devices) return PrintDevices(devices)
} }
func Pause(ctx *ctx.Context, client *spotify.Client) error { func Pause(ctx *gctx.Context, client *spotify.Client) error {
err := client.Pause(ctx) err := client.Pause(ctx)
if err != nil { if err != nil {
return err return err
@ -100,7 +100,7 @@ func Pause(ctx *ctx.Context, client *spotify.Client) error {
return nil return nil
} }
func Skip(ctx *ctx.Context, client *spotify.Client) error { func Skip(ctx *gctx.Context, client *spotify.Client) error {
err := client.Next(ctx) err := client.Next(ctx)
if err != nil { if err != nil {
return err return err
@ -109,7 +109,7 @@ func Skip(ctx *ctx.Context, client *spotify.Client) error {
return nil return nil
} }
func Status(ctx *ctx.Context, client *spotify.Client) error { func Status(ctx *gctx.Context, client *spotify.Client) error {
state, err := client.PlayerState(ctx) state, err := client.PlayerState(ctx)
if err != nil { if err != nil {
return err return err
@ -117,7 +117,7 @@ func Status(ctx *ctx.Context, client *spotify.Client) error {
return PrintState(state) return PrintState(state)
} }
func Shuffle(ctx *ctx.Context, client *spotify.Client) error { func Shuffle(ctx *gctx.Context, client *spotify.Client) error {
state, err := client.PlayerState(ctx) state, err := client.PlayerState(ctx)
if err != nil { if err != nil {
return fmt.Errorf("Failed to get current playstate") return fmt.Errorf("Failed to get current playstate")
@ -130,7 +130,7 @@ func Shuffle(ctx *ctx.Context, client *spotify.Client) error {
return nil return nil
} }
func TrackList(ctx *ctx.Context, client *spotify.Client, page int) (*spotify.SavedTrackPage, error) { func TrackList(ctx *gctx.Context, client *spotify.Client, page int) (*spotify.SavedTrackPage, error) {
return client.CurrentUsersTracks(ctx, spotify.Limit(50), spotify.Offset((page-1)*50)) return client.CurrentUsersTracks(ctx, spotify.Limit(50), spotify.Offset((page-1)*50))
} }
@ -154,7 +154,7 @@ func PrintDevices(devices []spotify.PlayerDevice) error {
return nil return nil
} }
func SetDevice(ctx *ctx.Context, client *spotify.Client, args []string) error { func SetDevice(ctx *gctx.Context, client *spotify.Client, args []string) error {
if len(args) < 2 { if len(args) < 2 {
return fmt.Errorf("Please provide your device ID") return fmt.Errorf("Please provide your device ID")
} }
@ -186,7 +186,7 @@ func isNoActiveError(err error) bool {
return strings.Contains(err.Error(), "No active device found") return strings.Contains(err.Error(), "No active device found")
} }
func playWithTransfer(ctx *ctx.Context, client *spotify.Client) error { func playWithTransfer(ctx *gctx.Context, client *spotify.Client) error {
configDir, _ := os.UserConfigDir() configDir, _ := os.UserConfigDir()
deviceFile, err := os.Open(filepath.Join(configDir, "gospt/device.json")) deviceFile, err := os.Open(filepath.Join(configDir, "gospt/device.json"))
if err != nil { if err != nil {
@ -210,7 +210,7 @@ func playWithTransfer(ctx *ctx.Context, client *spotify.Client) error {
return nil return nil
} }
func queueWithTransfer(ctx *ctx.Context, client *spotify.Client, track_id spotify.ID) error { func queueWithTransfer(ctx *gctx.Context, client *spotify.Client, track_id spotify.ID) error {
configDir, _ := os.UserConfigDir() configDir, _ := os.UserConfigDir()
deviceFile, err := os.Open(filepath.Join(configDir, "gospt/device.json")) deviceFile, err := os.Open(filepath.Join(configDir, "gospt/device.json"))
if err != nil { if err != nil {

View File

@ -1,4 +1,4 @@
package ctx package gctx
import ( import (
"context" "context"

View File

@ -4,13 +4,13 @@ import (
"fmt" "fmt"
"gospt/internal/commands" "gospt/internal/commands"
"gospt/internal/ctx" "gospt/internal/gctx"
"gospt/internal/tui" "gospt/internal/tui"
"github.com/zmb3/spotify/v2" "github.com/zmb3/spotify/v2"
) )
func Run(ctx *ctx.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 {
user, err := client.CurrentUser(ctx) user, err := client.CurrentUser(ctx)
if err != nil { if err != nil {

View File

@ -6,7 +6,7 @@ import (
"time" "time"
"gospt/internal/commands" "gospt/internal/commands"
"gospt/internal/ctx" "gospt/internal/gctx"
"github.com/charmbracelet/bubbles/list" "github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
@ -33,7 +33,7 @@ func (i item) FilterValue() string { return i.Title() + i.Artist.Name }
type model struct { type model struct {
list list.Model list list.Model
page int page int
ctx *ctx.Context ctx *gctx.Context
client *spotify.Client client *spotify.Client
} }
@ -93,7 +93,7 @@ func (m model) View() string {
return docStyle.Render(m.list.View()) return docStyle.Render(m.list.View())
} }
func DisplayList(ctx *ctx.Context, client *spotify.Client) error { func DisplayList(ctx *gctx.Context, client *spotify.Client) error {
items := []list.Item{} items := []list.Item{}
tracks, err := commands.TrackList(ctx, client, 1) tracks, err := commands.TrackList(ctx, client, 1)
if err != nil { if err != nil {

View File

@ -9,7 +9,7 @@ import (
"gospt/internal/auth" "gospt/internal/auth"
"gospt/internal/config" "gospt/internal/config"
"gospt/internal/ctx" "gospt/internal/gctx"
"gospt/internal/runner" "gospt/internal/runner"
) )
@ -22,7 +22,7 @@ func init() {
func main() { func main() {
var err error var err error
log.New(os.Stdout, "LOG:", 0) log.New(os.Stdout, "LOG:", 0)
ctx := ctx.NewContext(context.Background()) ctx := gctx.NewContext(context.Background())
client, err := auth.GetClient(ctx) client, err := auth.GetClient(ctx)
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error())