diff --git a/internal/auth/auth.go b/internal/auth/auth.go index bcdf6f9..bacd474 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -10,7 +10,7 @@ import ( "path/filepath" "gospt/internal/config" - "gospt/internal/ctx" + "gospt/internal/gctx" "github.com/zmb3/spotify/v2" spotifyauth "github.com/zmb3/spotify/v2/auth" @@ -23,7 +23,7 @@ var ( state = "abc123" ) -func GetClient(ctx *ctx.Context) (*spotify.Client, error) { +func GetClient(ctx *gctx.Context) (*spotify.Client, error) { auth = spotifyauth.New( spotifyauth.WithClientID(config.Values.ClientId), spotifyauth.WithClientSecret(config.Values.ClientSecret), diff --git a/internal/commands/commands.go b/internal/commands/commands.go index 187ff67..fb36407 100644 --- a/internal/commands/commands.go +++ b/internal/commands/commands.go @@ -11,12 +11,12 @@ import ( "strings" "time" - "gospt/internal/ctx" + "gospt/internal/gctx" "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) if err != nil { if isNoActiveError(err) { @@ -28,7 +28,7 @@ func Play(ctx *ctx.Context, client *spotify.Client) error { 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 { return fmt.Errorf("Please provide a url") } @@ -49,7 +49,7 @@ func PlayUrl(ctx *ctx.Context, client *spotify.Client, args []string) error { 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()) current_song, err := client.PlayerCurrentlyPlaying(ctx) if err != nil { @@ -83,7 +83,7 @@ func Radio(ctx *ctx.Context, client *spotify.Client) error { 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) if err != nil { return err @@ -91,7 +91,7 @@ func Devices(ctx *ctx.Context, client *spotify.Client) error { 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) if err != nil { return err @@ -100,7 +100,7 @@ func Pause(ctx *ctx.Context, client *spotify.Client) error { return nil } -func Skip(ctx *ctx.Context, client *spotify.Client) error { +func Skip(ctx *gctx.Context, client *spotify.Client) error { err := client.Next(ctx) if err != nil { return err @@ -109,7 +109,7 @@ func Skip(ctx *ctx.Context, client *spotify.Client) error { 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) if err != nil { return err @@ -117,7 +117,7 @@ func Status(ctx *ctx.Context, client *spotify.Client) error { 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) if err != nil { return fmt.Errorf("Failed to get current playstate") @@ -130,7 +130,7 @@ func Shuffle(ctx *ctx.Context, client *spotify.Client) error { 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)) } @@ -154,7 +154,7 @@ func PrintDevices(devices []spotify.PlayerDevice) error { 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 { 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") } -func playWithTransfer(ctx *ctx.Context, client *spotify.Client) error { +func playWithTransfer(ctx *gctx.Context, client *spotify.Client) error { configDir, _ := os.UserConfigDir() deviceFile, err := os.Open(filepath.Join(configDir, "gospt/device.json")) if err != nil { @@ -210,7 +210,7 @@ func playWithTransfer(ctx *ctx.Context, client *spotify.Client) error { 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() deviceFile, err := os.Open(filepath.Join(configDir, "gospt/device.json")) if err != nil { diff --git a/internal/ctx/context.go b/internal/gctx/context.go similarity index 95% rename from internal/ctx/context.go rename to internal/gctx/context.go index 1adbcbc..92c675a 100644 --- a/internal/ctx/context.go +++ b/internal/gctx/context.go @@ -1,4 +1,4 @@ -package ctx +package gctx import ( "context" diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 48f2540..410fbfa 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -4,13 +4,13 @@ import ( "fmt" "gospt/internal/commands" - "gospt/internal/ctx" + "gospt/internal/gctx" "gospt/internal/tui" "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 { user, err := client.CurrentUser(ctx) if err != nil { diff --git a/internal/tui/list.go b/internal/tui/list.go index 9dbc054..5e1a2fe 100644 --- a/internal/tui/list.go +++ b/internal/tui/list.go @@ -6,7 +6,7 @@ import ( "time" "gospt/internal/commands" - "gospt/internal/ctx" + "gospt/internal/gctx" "github.com/charmbracelet/bubbles/list" tea "github.com/charmbracelet/bubbletea" @@ -33,7 +33,7 @@ func (i item) FilterValue() string { return i.Title() + i.Artist.Name } type model struct { list list.Model page int - ctx *ctx.Context + ctx *gctx.Context client *spotify.Client } @@ -93,7 +93,7 @@ func (m model) View() string { 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{} tracks, err := commands.TrackList(ctx, client, 1) if err != nil { diff --git a/main.go b/main.go index 00a86a9..cec2b26 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,7 @@ import ( "gospt/internal/auth" "gospt/internal/config" - "gospt/internal/ctx" + "gospt/internal/gctx" "gospt/internal/runner" ) @@ -22,7 +22,7 @@ func init() { func main() { var err error log.New(os.Stdout, "LOG:", 0) - ctx := ctx.NewContext(context.Background()) + ctx := gctx.NewContext(context.Background()) client, err := auth.GetClient(ctx) if err != nil { panic(err.Error())