Skip to content

Commit

Permalink
feat: remove album art hash from each song
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Gleich <[email protected]>
  • Loading branch information
gleich committed Dec 6, 2024
1 parent 31aaf85 commit dbb47dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
32 changes: 7 additions & 25 deletions internal/apis/applemusic/song.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package applemusic

import (
"bytes"
"fmt"
"image/jpeg"
"net/http"
"net/url"
"regexp"
"strconv"
"strings"

"github.com/gleich/lcp-v2/internal/images"
"github.com/gleich/lumber/v3"
)

Expand All @@ -22,7 +18,6 @@ type song struct {
ReleaseDate string `json:"release_date"`
DurationInMillis int `json:"duration_in_millis"`
AlbumArtURL string `json:"album_art_url"`
AlbumArtBlur string `json:"album_art_blur"`
URL string `json:"url"`
ID string `json:"id"`
}
Expand Down Expand Up @@ -69,32 +64,19 @@ func songFromSongResponse(s songResponse) song {
s.Attributes.URL = u
}

albumArtURL := strings.ReplaceAll(strings.ReplaceAll(
s.Attributes.Artwork.URL,
"{w}",
strconv.Itoa(s.Attributes.Artwork.Width),
), "{h}", strconv.Itoa(s.Attributes.Artwork.Height))

resp, err := http.Get(albumArtURL)
if err != nil {
lumber.Error(err, "failed to fetch song album art", s.Attributes.Name)
}
var b bytes.Buffer
_, err = b.ReadFrom(resp.Body)
if err != nil {
lumber.Error(err, "failed to read data from request")
}

return song{
Track: s.Attributes.Name,
Artist: s.Attributes.ArtistName,
Album: s.Attributes.AlbumName,
Genres: s.Attributes.GenreNames,
ReleaseDate: s.Attributes.ReleaseDate,
DurationInMillis: s.Attributes.DurationInMillis,
AlbumArtURL: albumArtURL,
AlbumArtBlur: images.BlurDataURI(images.BlurImage(b.Bytes(), jpeg.Decode)),
URL: s.Attributes.URL,
ID: s.ID,
AlbumArtURL: strings.ReplaceAll(strings.ReplaceAll(
s.Attributes.Artwork.URL,
"{w}",
strconv.Itoa(s.Attributes.Artwork.Width),
), "{h}", strconv.Itoa(s.Attributes.Artwork.Height)),
URL: s.Attributes.URL,
ID: s.ID,
}
}
2 changes: 1 addition & 1 deletion internal/images/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func BlurImage(data []byte, decoder func(r io.Reader) (image.Image, error)) []by
reader := bytes.NewReader(data)
parsedImage, err := decoder(reader)
if err != nil {
lumber.Error(err, "decoding PNG failed")
lumber.Error(err, "decoding image failed")
return nil
}

Expand Down

0 comments on commit dbb47dd

Please sign in to comment.