Skip to content

Commit

Permalink
reformat, log warn message & throw exception if deezer track is unreable
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Jul 10, 2023
1 parent cc6f3f7 commit 64784ac
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManager;
import com.sedmelluq.discord.lavaplayer.tools.DataFormatTools;
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
import com.sedmelluq.discord.lavaplayer.tools.JsonBrowser;
import com.sedmelluq.discord.lavaplayer.tools.io.HttpClientTools;
import com.sedmelluq.discord.lavaplayer.tools.io.HttpConfigurable;
Expand Down Expand Up @@ -120,7 +121,11 @@ public JsonBrowser getJson(String uri) throws IOException {
private List<AudioTrack> parseTracks(JsonBrowser json) {
var tracks = new ArrayList<AudioTrack>();
for (var track : json.get("data").values()) {
if (!track.get("type").text().equals("track") || !track.get("readable").as(Boolean.class)) {
if (!track.get("type").text().equals("track")) {
continue;
}
if (!track.get("readable").as(Boolean.class)) {
log.warn("Skipping track {} by {} because it is not readable. Available countries: {}", track.get("title").text(), track.get("artist").get("name").text(), track.get("available_countries").text());
continue;
}
tracks.add(this.parseTrack(track));
Expand All @@ -129,6 +134,9 @@ private List<AudioTrack> parseTracks(JsonBrowser json) {
}

private AudioTrack parseTrack(JsonBrowser json) {
if (!json.get("readable").as(Boolean.class)) {
throw new FriendlyException("This track is not readable. Available countries: " + json.get("available_countries").text(), FriendlyException.Severity.COMMON, null);
}
var id = json.get("id").text();
return new DeezerAudioTrack(new AudioTrackInfo(
json.get("title").text(),
Expand Down

0 comments on commit 64784ac

Please sign in to comment.