From 26f0033ebb5f8e7c204a042709e3dfa885eac868 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sat, 22 Jul 2023 15:15:47 +0200 Subject: fix applyTimeBonus by always using Song pointers Storing song objects in the Songs slice and using pointers to the underlying array slots breaks if the underlying array must be grown. When the array is grown the objects are copied to the new array and the pointers used in queue point to the old objects. This causes that Playlist.applyTimeBonus may not correctly apply to the most recent list of songs. This is fixed by always using Song pointers. --- spotify.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spotify.go') diff --git a/spotify.go b/spotify.go index 324f645..e15501a 100644 --- a/spotify.go +++ b/spotify.go @@ -96,7 +96,7 @@ func (spotify *SpotifyBackend) Play(song *Song, player Player) { player.PlayData(audioFile) } -func (spotify *SpotifyBackend) Search(patterns map[string]string) []Song { +func (spotify *SpotifyBackend) Search(patterns map[string]string) []*Song { session := spotify.session keyword := "" for _, p := range []string{"pattern", "title", "artist", "album"} { @@ -110,7 +110,7 @@ func (spotify *SpotifyBackend) Search(patterns map[string]string) []Song { if err != nil { llog.Error("Failed to search: %s", err) - return []Song{} + return nil } res := resp.Results @@ -124,7 +124,7 @@ func (spotify *SpotifyBackend) Search(patterns map[string]string) []Song { llog.Debug("\nTracks: %d (total %d)\n", len(res.Tracks.Hits), res.Tracks.Total) - results := []Song{} + results := []*Song{} for _, track := range res.Tracks.Hits { uriParts := strings.Split(track.Uri, ":") s := NewSong(track.Name, track.Artists[0].Name, "spotify", uriParts[len(uriParts)-1]) -- cgit v1.2.3