Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes for yandex music which led to an error when loading a track or playlist #31

Merged
merged 3 commits into from
Nov 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,29 @@ public String getDownloadStrings(String uri) throws IOException {
private List<AudioTrack> parseTracks(JsonBrowser json) {
var tracks = new ArrayList<AudioTrack>();
for (var track : json.values()) {
tracks.add(this.parseTrack(track));
var parsedTrack = this.parseTrack(track);
if (parsedTrack != null) {
tracks.add(parsedTrack);
}
}
return tracks;
}

private AudioTrack parseTrack(JsonBrowser json) {
if (!json.get("available").asBoolean(false) || json.get("albums").values().isEmpty()) {
return null;
}
var id = json.get("id").text();
var artist = json.get("major").get("name").text().equals("PODCASTS") ? json.get("albums").values().get(0).get("title").text() : json.get("artists").values().get(0).get("name").text();
var coverUri = json.get("albums").values().get(0).get("coverUri").text();
return new YandexMusicAudioTrack(new AudioTrackInfo(
json.get("title").text(),
artist,
json.get("durationMs").as(Long.class),
id,
false,
"https://music.yandex.ru/album/" + json.get("albums").values().get(0).get("id").text() + "/track/" + id),
"https://" + json.get("albums").values().get(0).get("coverUri").text().replace("%%", "400x400"),
coverUri != null ? "https://" + coverUri.replace("%%", "400x400") : null,
this
);
}
Expand Down