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
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ public Track createModelObject(JsonObject jsonObject) {
: null)
.setDurationMs(
hasAndNotNull(jsonObject, "duration_ms")
? getDurationMsFixed(jsonObject) // TODO: use `jsonObject.get("duration_ms").getAsInt()` when Spotify has fixed their API / API description, see method documentation below
? jsonObject.get("duration_ms").getAsInt()
: null)
.setExplicit(
hasAndNotNull(jsonObject, "explicit")
Expand Down Expand Up @@ -627,22 +627,6 @@ public Track createModelObject(JsonObject jsonObject) {
: null)
.build();
}

/**
* @see <a href="https://community.spotify.com/t5/Spotify-for-Developers/duration-ms-includes-nonsense-JSON/m-p/5753768">Bug report on Spotify forums</a>
* @deprecated This is a temporary workaround to handle an edge-case involving local files,
* which for some reason have their duration_ms field contain an additional field called totalMilliseconds.
* Once Spotify fixes their API, this workaround should be removed.
*/
@Deprecated
private static int getDurationMsFixed(JsonObject jsonObject) {
JsonElement durationMs = jsonObject.get("duration_ms");
if (durationMs.isJsonPrimitive()) {
return durationMs.getAsInt();
} else {
return durationMs.getAsJsonObject().get("totalMilliseconds").getAsInt();
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@
"UY"
],
"disc_number": 1,
"duration_ms": {
"totalMilliseconds": 222200
},
"duration_ms": 222200,
"explicit": false,
"external_ids": {
"isrc": "GBFFP0300052"
Expand Down
Loading