From c3ebf8a792ab72a1f2282a0c0733d98836c189f8 Mon Sep 17 00:00:00 2001 From: abs3nt Date: Wed, 11 Jan 2023 18:12:29 -0800 Subject: [PATCH] no repeats on radio init --- internal/commands/commands.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/internal/commands/commands.go b/internal/commands/commands.go index 7c78e66..fad05d5 100644 --- a/internal/commands/commands.go +++ b/internal/commands/commands.go @@ -188,7 +188,12 @@ func RadioGivenSong(ctx *gctx.Context, client *spotify.Client, song_id spotify.I return err } queue := []spotify.ID{song_id} - queue = append(queue, recomendationIds...) + all_recs := map[spotify.ID]bool{} + all_recs[song_id] = true + for _, rec := range recomendationIds { + all_recs[rec] = true + queue = append(queue, rec) + } _, err = client.AddTracksToPlaylist(ctx, radioPlaylist.ID, queue...) if err != nil { return err @@ -607,7 +612,12 @@ func RadioGivenList(ctx *gctx.Context, client *spotify.Client, song_ids []spotif return err } queue := []spotify.ID{song_ids[0]} - queue = append(queue, recomendationIds...) + all_recs := map[spotify.ID]bool{} + all_recs[song_ids[0]] = true + for _, rec := range recomendationIds { + all_recs[rec] = true + queue = append(queue, rec) + } _, err = client.AddTracksToPlaylist(ctx, radioPlaylist.ID, queue...) if err != nil { return err @@ -633,7 +643,11 @@ func RadioGivenList(ctx *gctx.Context, client *spotify.Client, song_ids []spotif } additionalRecsIds := []spotify.ID{} for _, song := range additional_recs.Tracks { - additionalRecsIds = append(additionalRecsIds, song.ID) + if _, ok := all_recs[song.ID]; !ok { + all_recs[song.ID] = true + additionalRecsIds = append(additionalRecsIds, song.ID) + queue = append(queue, song.ID) + } } _, err = client.AddTracksToPlaylist(ctx, radioPlaylist.ID, additionalRecsIds...) if err != nil {