From 8c84e623daaa02e62f47c0e921cf458be3d97289 Mon Sep 17 00:00:00 2001 From: abs3nt Date: Mon, 16 Jan 2023 21:06:20 -0800 Subject: [PATCH] fancy next --- src/commands/commands.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/commands/commands.go b/src/commands/commands.go index de0de78..555e682 100644 --- a/src/commands/commands.go +++ b/src/commands/commands.go @@ -578,15 +578,40 @@ func Next(ctx *gctx.Context, client *spotify.Client, amt int) error { } page++ } - fmt.Println(currentTrackIndex) client.PlayOpt(ctx, &spotify.PlayOptions{ PlaybackContext: ¤t.PlaybackContext.URI, PlaybackOffset: &spotify.PlaybackOffset{ Position: currentTrackIndex + amt, }, }) + return nil + case "album": + found := false + currentTrackIndex := 0 + for !found { + page := 1 + playlist, err := client.GetAlbumTracks(ctx, spotify.ID(strings.Split(string(current.PlaybackContext.URI), ":")[2]), spotify.Limit(50), spotify.Offset((page-1)*50)) + if err != nil { + return err + } + for idx, track := range playlist.Tracks { + if track.ID == current.Item.ID { + currentTrackIndex = idx + (50 * (page - 1)) + found = true + break + } + } + page++ + } + client.PlayOpt(ctx, &spotify.PlayOptions{ + PlaybackContext: ¤t.PlaybackContext.URI, + PlaybackOffset: &spotify.PlaybackOffset{ + Position: currentTrackIndex + amt, + }, + }) + return nil default: - for i := 0; i <= amt; i++ { + for i := 0; i < amt; i++ { client.Next(ctx) } }