Skip to content

Commit

Permalink
feat: first four tracks as a part of summary
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Gleich <[email protected]>
  • Loading branch information
gleich committed Jan 3, 2025
1 parent dfa4aba commit 4500445
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 12 additions & 1 deletion internal/apis/applemusic/applemusic.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,20 @@ func serveHTTP(c *cache.Cache[cacheData]) http.HandlerFunc {
RecentlyPlayed []song `json:"recently_played"`
}{}
for _, p := range c.Data.Playlists {
firstFourTracks := []song{}
for _, track := range p.Tracks {
if len(firstFourTracks) < 4 {
firstFourTracks = append(firstFourTracks, track)
}
}
data.PlaylistSummaries = append(
data.PlaylistSummaries,
playlistSummary{Name: p.Name, ID: p.ID, TrackCount: len(p.Tracks)},
playlistSummary{
Name: p.Name,
ID: p.ID,
TrackCount: len(p.Tracks),
FirstFourTracks: firstFourTracks,
},
)
}

Expand Down
7 changes: 4 additions & 3 deletions internal/apis/applemusic/playlists.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import (
)

type playlistSummary struct {
Name string `json:"name"`
TrackCount int `json:"track_count"`
ID string `json:"id"`
Name string `json:"name"`
TrackCount int `json:"track_count"`
FirstFourTracks []song `json:"first_four_tracks"`
ID string `json:"id"`
}

type playlist struct {
Expand Down

0 comments on commit 4500445

Please sign in to comment.