Skip to content

Commit

Permalink
feat: filter out duplicate songs
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Gleich <[email protected]>
  • Loading branch information
gleich committed Nov 29, 2024
1 parent 613d78d commit a796740
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/apis/applemusic/recent.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,16 @@ func fetchRecentlyPlayed() ([]song, error) {
for _, s := range response.Data {
songs = append(songs, songFromSongResponse(s))
}
return songs[:10], nil

// filter out duplicate songs
seen := make(map[string]bool)
uniqueSongs := []song{}
for _, song := range songs {
if !seen[song.ID] {
seen[song.ID] = true
uniqueSongs = append(uniqueSongs, song)
}
}

return uniqueSongs[:10], nil
}

0 comments on commit a796740

Please sign in to comment.