Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'de.labystudio'
version '1.1.11'
version '1.1.12'

compileJava {
sourceCompatibility = '1.8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
Expand Down Expand Up @@ -288,7 +289,11 @@ public <T> T request(String url, Class<?> clazz, boolean canGenerateNewAccessTok
}

// Read response
JsonReader reader = new JsonReader(new InputStreamReader(connection.getInputStream()));
JsonReader reader = new JsonReader(new InputStreamReader(
connection.getInputStream(),
StandardCharsets.UTF_8
));

return GSON.fromJson(reader, clazz);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

package de.labystudio.spotifyapi.open.model.track;

import com.google.gson.annotations.SerializedName;
import de.labystudio.spotifyapi.model.Track;

import java.util.List;

Expand Down Expand Up @@ -49,4 +49,47 @@ public class OpenTrack {

public String uri;

private transient String joinedArtists;

/**
* Joins the artists to a single string.
*
* @return the artists name, split with comma
*/
public String getArtists() {
if (this.joinedArtists == null) {
this.joinedArtists = this.getArtists(", ");
}

return this.joinedArtists;
}

/**
* Joins the artists to a single string.
*
* @param delimiter The delimiter to split the artists with
* @return the artists name, split the provided delimiter
*/
public String getArtists(String delimiter) {
if (this.artists == null || this.artists.isEmpty()) {
return null;
}

StringBuilder builder = new StringBuilder();
for (Artist artist : this.artists) {
builder.append(delimiter);
builder.append(artist.name);
}

return builder.substring(delimiter.length());
}

/**
* Create a new {@link Track} based on the current object.
*
* @return The new {@link Track} object
*/
public Track toTrack() {
return new Track(this.id, this.name, this.getArtists(), this.durationMs);
}
}