From ba0830c6f4441a21db024e17382fd9841225c04f Mon Sep 17 00:00:00 2001 From: jjohnstondev Date: Sat, 7 Jan 2023 20:58:18 -0800 Subject: [PATCH] gitea --- commands/commands.go | 36 ++++++++++++++++++++++++++++++++++++ runner/runner.go | 2 ++ 2 files changed, 38 insertions(+) diff --git a/commands/commands.go b/commands/commands.go index d98b888..7f877d3 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -4,10 +4,12 @@ import ( "encoding/json" "fmt" "io/ioutil" + "math/rand" "net/url" "os" "path/filepath" "strings" + "time" "gospt/ctx" @@ -47,6 +49,40 @@ func PlayUrl(ctx *ctx.Context, client *spotify.Client, args []string) error { return nil } +func Radio(ctx *ctx.Context, client *spotify.Client) error { + rand.Seed(time.Now().Unix()) + current_song, err := client.PlayerCurrentlyPlaying(ctx) + if err != nil { + return err + } + seed := spotify.Seeds{ + Tracks: []spotify.ID{current_song.Item.ID}, + } + recomendations, err := client.GetRecommendations(ctx, seed, &spotify.TrackAttributes{}, spotify.Limit(100)) + if err != nil { + return err + } + for _, song := range recomendations.Tracks { + fmt.Println(song.Name) + } + fmt.Println("QUEUED") + for i := 0; i < 4; i++ { + seed_track := recomendations.Tracks[3] + seed := spotify.Seeds{ + Tracks: []spotify.ID{seed_track.ID}, + } + recomendations, err = client.GetRecommendations(ctx, seed, &spotify.TrackAttributes{}, spotify.Limit(100)) + if err != nil { + return err + } + for _, song := range recomendations.Tracks { + fmt.Println(song.Name) + } + fmt.Println("QUEUED") + } + return nil +} + func Devices(ctx *ctx.Context, client *spotify.Client) error { devices, err := client.PlayerDevices(ctx) if err != nil { diff --git a/runner/runner.go b/runner/runner.go index 394dd38..25a2a44 100644 --- a/runner/runner.go +++ b/runner/runner.go @@ -30,6 +30,8 @@ func Run(ctx *ctx.Context, client *spotify.Client, args []string) error { return commands.Skip(ctx, client) case "shuffle": return commands.Shuffle(ctx, client) + case "radio": + return commands.Radio(ctx, client) case "tracks": return tui.DisplayList(ctx, client) case "status":