Skip to content

Commit

Permalink
fix apple music album loading
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Dec 17, 2023
1 parent 8913f5e commit f05b1fe
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,11 @@ public AudioItem getAlbum(String id, String countryCode, boolean preview) throws
page = this.getJson(API_BASE + "catalog/" + countryCode + "/albums/" + id + "/tracks?limit=" + MAX_PAGE_ITEMS + "&offset=" + offset);
offset += MAX_PAGE_ITEMS;

page.values().forEach(tracksRaw::add);
page.get("data").values().forEach(tracksRaw::add);
}
while (page.get("next").text() != null && ++pages < albumPageLimit);

var tracks = parseTracks(tracksRaw, preview);
var tracks = parseTrackList(tracksRaw, preview);
if (tracks.isEmpty()) {
return AudioReference.NO_TRACK;
}
Expand Down Expand Up @@ -363,9 +363,7 @@ public AudioItem getPlaylist(String id, String countryCode, boolean preview) thr
}
while (page.get("next").text() != null && ++pages < playlistPageLimit);

var dataRaw = JsonBrowser.newMap();
dataRaw.put("data", tracksRaw);
var tracks = parseTracks(dataRaw, preview);
var tracks = parseTrackList(tracksRaw, preview);
if (tracks.isEmpty()) {
return AudioReference.NO_TRACK;
}
Expand Down Expand Up @@ -421,6 +419,12 @@ private List<AudioTrack> parseTracks(JsonBrowser json, boolean preview, Map<Stri
return tracks;
}

private List<AudioTrack> parseTrackList(JsonBrowser json, boolean preview) throws IOException {
var jsonData = JsonBrowser.newMap();
jsonData.put("data", json);
return parseTracks(jsonData, preview);
}

private List<AudioTrack> parseTracks(JsonBrowser json, boolean preview) throws IOException {
var ids = json.get("data").values().stream().map(this::parseArtistId).filter(Predicate.not(Objects::isNull)).collect(Collectors.toList());
return parseTracks(json, preview, getArtistCover(ids));
Expand Down

0 comments on commit f05b1fe

Please sign in to comment.