From 8f5c4bffb83cacf4effe4f8cfb14dec7d3880719 Mon Sep 17 00:00:00 2001 From: jjohnstondev Date: Sun, 8 Jan 2023 08:44:54 -0800 Subject: [PATCH] if no status --- internal/commands/commands.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/internal/commands/commands.go b/internal/commands/commands.go index 285c140..16e0365 100644 --- a/internal/commands/commands.go +++ b/internal/commands/commands.go @@ -84,14 +84,31 @@ func Radio(ctx *gctx.Context, client *spotify.Client) error { if err != nil { return err } - seed_song := current_song.Item.SimpleTrack - if !current_song.Playing { + var seed_song spotify.SimpleTrack + + if current_song.Item != nil { + seed_song = current_song.Item.SimpleTrack + } + if current_song.Item == nil { + err := activateDevice(ctx, client) + if err != nil { + return err + } tracks, err := client.CurrentUsersTracks(ctx, spotify.Limit(10)) if err != nil { return err } seed_song = tracks.Tracks[rand.Intn(len(tracks.Tracks))].SimpleTrack + } else { + if !current_song.Playing { + tracks, err := client.CurrentUsersTracks(ctx, spotify.Limit(10)) + if err != nil { + return err + } + seed_song = tracks.Tracks[rand.Intn(len(tracks.Tracks))].SimpleTrack + } } + seed := spotify.Seeds{ Tracks: []spotify.ID{seed_song.ID}, } @@ -418,7 +435,7 @@ func activateDevice(ctx *gctx.Context, client *spotify.Client) error { if err != nil { return err } - err = client.TransferPlayback(ctx, device.ID, true) + err = client.TransferPlayback(ctx, device.ID, false) if err != nil { return err }