From 5b33ff29351228d0dad95fb8185a97efdd4076ff Mon Sep 17 00:00:00 2001 From: clapann Date: Tue, 16 Jul 2024 23:27:46 -0700 Subject: [PATCH 1/7] Add Spotify local file support and config option --- application.example.yml | 1 + .../lavasrc/spotify/SpotifySourceManager.java | 33 ++++++++++++++----- .../topi314/lavasrc/plugin/LavaSrcPlugin.java | 5 ++- .../topi314/lavasrc/plugin/SpotifyConfig.java | 8 +++++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/application.example.yml b/application.example.yml index f6fa10a9..76e04fc7 100644 --- a/application.example.yml +++ b/application.example.yml @@ -25,6 +25,7 @@ plugins: countryCode: "US" # the country code you want to use for filtering the artists top tracks. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 playlistLoadLimit: 6 # The number of pages at 100 tracks each albumLoadLimit: 6 # The number of pages at 50 tracks each + localFiles: false # Enable local files support with Spotify playlists applemusic: countryCode: "US" # the country code you want to use for filtering the artists top tracks and language. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 mediaAPIToken: "..." # apple music api token diff --git a/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java index fdd0ca19..f7029c3d 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java @@ -59,6 +59,7 @@ public class SpotifySourceManager extends MirroringAudioSourceManager implements private final String countryCode; private int playlistPageLimit = 6; private int albumPageLimit = 6; + private boolean localFiles; private String spToken; private Instant spTokenExpire; @@ -99,6 +100,10 @@ public void setAlbumPageLimit(int albumPageLimit) { this.albumPageLimit = albumPageLimit; } + public void setLocalFiles(boolean localFiles) { + this.localFiles = localFiles; + } + @NotNull @Override public String getSourceName() { @@ -422,10 +427,12 @@ public AudioItem getPlaylist(String id, boolean preview) throws IOException { for (var value : page.get("items").values()) { var track = value.get("track"); - if (track.isNull() || track.get("is_local").asBoolean(false) || track.get("type").text().equals("episode")) { + if(track.isNull() || + (this.localFiles ? track.get("type").text().equals("episode") : + track.get("is_local").asBoolean(false) || track.get("type").text().equals("episode"))) { continue; } - tracks.add(this.parseTrack(track, preview)); + tracks.add(this.parseTrack(track, preview, this.localFiles)); } } @@ -467,13 +474,13 @@ public AudioItem getTrack(String id, boolean preview) throws IOException { json.get("artists").index(0).put("images", artistJson.get("images")); } - return this.parseTrack(json, preview); + return this.parseTrack(json, preview, this.localFiles); } private List parseTracks(JsonBrowser json, boolean preview) { var tracks = new ArrayList(); for (var value : json.get("tracks").values()) { - tracks.add(this.parseTrack(value, preview)); + tracks.add(this.parseTrack(value, preview, this.localFiles)); } return tracks; } @@ -484,18 +491,26 @@ private List parseTrackItems(JsonBrowser json, boolean preview) { if (value.get("is_local").asBoolean(false)) { continue; } - tracks.add(this.parseTrack(value, preview)); + tracks.add(this.parseTrack(value, preview, this.localFiles)); } return tracks; } - private AudioTrack parseTrack(JsonBrowser json, boolean preview) { + private AudioTrack parseTrack(JsonBrowser json, boolean preview, boolean thisLocalFiles) { + if(thisLocalFiles && json.get("name").isNull()) { + return null; + } + + String name = json.get("name").text(); + String artist = thisLocalFiles ? (json.get("artists").index(0).get("name").text() != null ? json.get("artists").index(0).get("name").text() : "unknown") : json.get("artists").index(0).get("name").text(); + String id = thisLocalFiles ? (json.get("id").text() != null ? json.get("id").text() : "unknown") : json.get("id").text(); + return new SpotifyAudioTrack( new AudioTrackInfo( - json.get("name").text(), - json.get("artists").index(0).get("name").text(), + name, + artist, preview ? PREVIEW_LENGTH : json.get("duration_ms").asLong(0), - json.get("id").text(), + id, false, json.get("external_urls").get("spotify").text(), json.get("album").get("images").index(0).get("url").text(), diff --git a/plugin/src/main/java/com/github/topi314/lavasrc/plugin/LavaSrcPlugin.java b/plugin/src/main/java/com/github/topi314/lavasrc/plugin/LavaSrcPlugin.java index 04c88809..3cc28399 100644 --- a/plugin/src/main/java/com/github/topi314/lavasrc/plugin/LavaSrcPlugin.java +++ b/plugin/src/main/java/com/github/topi314/lavasrc/plugin/LavaSrcPlugin.java @@ -46,6 +46,9 @@ public LavaSrcPlugin(LavaSrcConfig pluginConfig, SourcesConfig sourcesConfig, Ly if (spotifyConfig.getAlbumLoadLimit() > 0) { this.spotify.setAlbumPageLimit(spotifyConfig.getAlbumLoadLimit()); } + if(spotifyConfig.isLocalFiles()) { + this.spotify.setLocalFiles(spotifyConfig.isLocalFiles()); + } } if (sourcesConfig.isAppleMusic()) { this.appleMusic = new AppleMusicSourceManager(pluginConfig.getProviders(), appleMusicConfig.getMediaAPIToken(), appleMusicConfig.getCountryCode(), unused -> manager); @@ -153,7 +156,7 @@ public SearchManager configure(@NotNull SearchManager manager) { } if (this.yandexMusic != null && this.sourcesConfig.isYandexMusic()) { log.info("Registering Yandex Music search manager..."); - manager.registerSearchManager(this.yandexMusic); + manager.registerSearchManager(this.yandexMusic); } return manager; } diff --git a/plugin/src/main/java/com/github/topi314/lavasrc/plugin/SpotifyConfig.java b/plugin/src/main/java/com/github/topi314/lavasrc/plugin/SpotifyConfig.java index aa012ca0..42b71080 100644 --- a/plugin/src/main/java/com/github/topi314/lavasrc/plugin/SpotifyConfig.java +++ b/plugin/src/main/java/com/github/topi314/lavasrc/plugin/SpotifyConfig.java @@ -13,6 +13,7 @@ public class SpotifyConfig { private String countryCode = "US"; private int playlistLoadLimit = 6; private int albumLoadLimit = 6; + private boolean localFiles = false; public String getClientId() { return this.clientId; @@ -62,4 +63,11 @@ public void setAlbumLoadLimit(int albumLoadLimit) { this.albumLoadLimit = albumLoadLimit; } + public boolean isLocalFiles() { + return this.localFiles; + } + + public void setLocalFiles(boolean localFiles) { + this.localFiles = localFiles; + } } From f8a6bb5664dab530e63b29f2fd66120654e8d9e8 Mon Sep 17 00:00:00 2001 From: clapann Date: Wed, 17 Jul 2024 02:22:03 -0700 Subject: [PATCH 2/7] Add isLocal option in README example config, add isLocal field to Spotify tracks, and change unknown fields to local --- README.md | 2 ++ application.example.yml | 2 +- .../lavasrc/spotify/SpotifyAudioTrack.java | 4 +++ .../lavasrc/spotify/SpotifySourceManager.java | 4 +-- .../LavaSrcAudioPluginInfoModifier.java | 35 +++++++++++-------- 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 80c5406b..c385fcb5 100644 --- a/README.md +++ b/README.md @@ -243,6 +243,7 @@ plugins: countryCode: "US" # the country code you want to use for filtering the artists top tracks. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 playlistLoadLimit: 6 # The number of pages at 100 tracks each albumLoadLimit: 6 # The number of pages at 50 tracks each + localFiles: false # Enable local files support with Spotify playlists. applemusic: countryCode: "US" # the country code you want to use for filtering the artists top tracks and language. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 mediaAPIToken: "your apple music api token" # apple music api token @@ -318,6 +319,7 @@ LavaSrc adds the following fields to tracks & playlists in Lavalink * https://open.spotify.com/album/7qemUq4n71awwVPOaX7jw4 * https://open.spotify.com/playlist/7HAO9R9v203gkaPAgknOMp * https://open.spotify.com/artist/3ZztVuWxHzNpl0THurTFCv +* Local files (URI and ISRC are null, and ID is set to "local" for all local files) (including new regional links like https://open.spotify.com/intl-de/track/0eG08cBeKk0mzykKjw4hcQ) diff --git a/application.example.yml b/application.example.yml index 76e04fc7..96a636d7 100644 --- a/application.example.yml +++ b/application.example.yml @@ -25,7 +25,7 @@ plugins: countryCode: "US" # the country code you want to use for filtering the artists top tracks. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 playlistLoadLimit: 6 # The number of pages at 100 tracks each albumLoadLimit: 6 # The number of pages at 50 tracks each - localFiles: false # Enable local files support with Spotify playlists + localFiles: false # Enable local files support with Spotify playlists. (URI and ISRC are null, and ID is set to "local" for all local files) applemusic: countryCode: "US" # the country code you want to use for filtering the artists top tracks and language. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 mediaAPIToken: "..." # apple music api token diff --git a/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifyAudioTrack.java b/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifyAudioTrack.java index 6ed0808f..b6323e48 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifyAudioTrack.java +++ b/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifyAudioTrack.java @@ -29,4 +29,8 @@ protected AudioTrack makeShallowClone() { return new SpotifyAudioTrack(this.trackInfo, (SpotifySourceManager) this.sourceManager); } + public boolean isLocal() { + return this.trackInfo.identifier.equals("local"); + } + } diff --git a/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java index f7029c3d..f96115d6 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java @@ -502,8 +502,8 @@ private AudioTrack parseTrack(JsonBrowser json, boolean preview, boolean thisLoc } String name = json.get("name").text(); - String artist = thisLocalFiles ? (json.get("artists").index(0).get("name").text() != null ? json.get("artists").index(0).get("name").text() : "unknown") : json.get("artists").index(0).get("name").text(); - String id = thisLocalFiles ? (json.get("id").text() != null ? json.get("id").text() : "unknown") : json.get("id").text(); + String artist = thisLocalFiles ? (json.get("artists").index(0).get("name").text() != null ? json.get("artists").index(0).get("name").text() : "local") : json.get("artists").index(0).get("name").text(); + String id = thisLocalFiles ? (json.get("id").text() != null ? json.get("id").text() : "local") : json.get("id").text(); return new SpotifyAudioTrack( new AudioTrackInfo( diff --git a/plugin/src/main/java/com/github/topi314/lavasrc/plugin/LavaSrcAudioPluginInfoModifier.java b/plugin/src/main/java/com/github/topi314/lavasrc/plugin/LavaSrcAudioPluginInfoModifier.java index bf9ce386..3a32aa88 100644 --- a/plugin/src/main/java/com/github/topi314/lavasrc/plugin/LavaSrcAudioPluginInfoModifier.java +++ b/plugin/src/main/java/com/github/topi314/lavasrc/plugin/LavaSrcAudioPluginInfoModifier.java @@ -2,6 +2,7 @@ import com.github.topi314.lavasrc.ExtendedAudioPlaylist; import com.github.topi314.lavasrc.ExtendedAudioTrack; +import com.github.topi314.lavasrc.spotify.SpotifyAudioTrack; import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import dev.arbjerg.lavalink.api.AudioPluginInfoModifier; @@ -12,6 +13,7 @@ import org.springframework.stereotype.Component; import java.util.Map; +import java.util.HashMap; @Component public class LavaSrcAudioPluginInfoModifier implements AudioPluginInfoModifier { @@ -31,19 +33,24 @@ public JsonObject modifyAudioPlaylistPluginInfo(@NotNull AudioPlaylist playlist) } @Nullable - @Override - public JsonObject modifyAudioTrackPluginInfo(@NotNull AudioTrack track) { - if (track instanceof ExtendedAudioTrack extendedTrack) { - return new JsonObject(Map.of( - "albumName", JsonElementKt.JsonPrimitive(extendedTrack.getAlbumName()), - "albumUrl", JsonElementKt.JsonPrimitive(extendedTrack.getAlbumUrl()), - "artistUrl", JsonElementKt.JsonPrimitive(extendedTrack.getArtistUrl()), - "artistArtworkUrl", JsonElementKt.JsonPrimitive(extendedTrack.getArtistArtworkUrl()), - "previewUrl", JsonElementKt.JsonPrimitive(extendedTrack.getPreviewUrl()), - "isPreview", JsonElementKt.JsonPrimitive(extendedTrack.isPreview()) + @Override + public JsonObject modifyAudioTrackPluginInfo(@NotNull AudioTrack track) { + if (track instanceof ExtendedAudioTrack extendedTrack) { + var json = new HashMap<>(Map.of( + "albumName", JsonElementKt.JsonPrimitive(extendedTrack.getAlbumName()), + "albumUrl", JsonElementKt.JsonPrimitive(extendedTrack.getAlbumUrl()), + "artistUrl", JsonElementKt.JsonPrimitive(extendedTrack.getArtistUrl()), + "artistArtworkUrl", JsonElementKt.JsonPrimitive(extendedTrack.getArtistArtworkUrl()), + "previewUrl", JsonElementKt.JsonPrimitive(extendedTrack.getPreviewUrl()), + "isPreview", JsonElementKt.JsonPrimitive(extendedTrack.isPreview()) + )); - )); - } - return null; - } + if (track instanceof SpotifyAudioTrack spotifyTrack) { + json.put("isLocal", JsonElementKt.JsonPrimitive(spotifyTrack.isLocal())); + } + + return new JsonObject(json); + } + return null; + } } From 1e31694d1566b877333e0ddbf587966cfc4061d4 Mon Sep 17 00:00:00 2001 From: steven <56710853+clapann@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:51:27 -0700 Subject: [PATCH 3/7] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Toπ --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c385fcb5..809ff2e2 100644 --- a/README.md +++ b/README.md @@ -317,7 +317,7 @@ LavaSrc adds the following fields to tracks & playlists in Lavalink (check out [Spotify Recommendations Docs](https://developer.spotify.com/documentation/web-api/reference/get-recommendations) for the full query parameter list) * https://open.spotify.com/track/0eG08cBeKk0mzykKjw4hcQ * https://open.spotify.com/album/7qemUq4n71awwVPOaX7jw4 -* https://open.spotify.com/playlist/7HAO9R9v203gkaPAgknOMp +* https://open.spotify.com/playlist/7HAO9R9v203gkaPAgknOMp (playlists can include local files if you enabled this via: `plugins.lavasrc.spotify.localFiles: true`. Please note `uri` & `iscr` will be `null` & `identifier` will be `"local"` * https://open.spotify.com/artist/3ZztVuWxHzNpl0THurTFCv * Local files (URI and ISRC are null, and ID is set to "local" for all local files) From af54dac3ffc91752af4c4bd18a4071544c43ba14 Mon Sep 17 00:00:00 2001 From: steven <56710853+clapann@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:51:39 -0700 Subject: [PATCH 4/7] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Toπ --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 809ff2e2..d1c95a0a 100644 --- a/README.md +++ b/README.md @@ -319,7 +319,6 @@ LavaSrc adds the following fields to tracks & playlists in Lavalink * https://open.spotify.com/album/7qemUq4n71awwVPOaX7jw4 * https://open.spotify.com/playlist/7HAO9R9v203gkaPAgknOMp (playlists can include local files if you enabled this via: `plugins.lavasrc.spotify.localFiles: true`. Please note `uri` & `iscr` will be `null` & `identifier` will be `"local"` * https://open.spotify.com/artist/3ZztVuWxHzNpl0THurTFCv -* Local files (URI and ISRC are null, and ID is set to "local" for all local files) (including new regional links like https://open.spotify.com/intl-de/track/0eG08cBeKk0mzykKjw4hcQ) From 31fdbecf1a6c4b681df2879103e51e47c1a82b19 Mon Sep 17 00:00:00 2001 From: clapann Date: Fri, 19 Jul 2024 23:45:24 -0700 Subject: [PATCH 5/7] Implement Requested Changes --- README.md | 4 ++-- application.example.yml | 2 +- .../lavasrc/spotify/SpotifySourceManager.java | 21 +++++++++---------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d1c95a0a..cef7f06c 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,7 @@ plugins: countryCode: "US" # the country code you want to use for filtering the artists top tracks. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 playlistLoadLimit: 6 # The number of pages at 100 tracks each albumLoadLimit: 6 # The number of pages at 50 tracks each - localFiles: false # Enable local files support with Spotify playlists. + localFiles: false # Enable local files support with Spotify playlists. Please note `uri` & `iscr` will be `null` & `identifier` will be `"local"` applemusic: countryCode: "US" # the country code you want to use for filtering the artists top tracks and language. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 mediaAPIToken: "your apple music api token" # apple music api token @@ -317,7 +317,7 @@ LavaSrc adds the following fields to tracks & playlists in Lavalink (check out [Spotify Recommendations Docs](https://developer.spotify.com/documentation/web-api/reference/get-recommendations) for the full query parameter list) * https://open.spotify.com/track/0eG08cBeKk0mzykKjw4hcQ * https://open.spotify.com/album/7qemUq4n71awwVPOaX7jw4 -* https://open.spotify.com/playlist/7HAO9R9v203gkaPAgknOMp (playlists can include local files if you enabled this via: `plugins.lavasrc.spotify.localFiles: true`. Please note `uri` & `iscr` will be `null` & `identifier` will be `"local"` +* https://open.spotify.com/playlist/7HAO9R9v203gkaPAgknOMp (playlists can include local files if you enabled this via: `plugins.lavasrc.spotify.localFiles: true`. Please note `uri` & `iscr` will be `null` & `identifier` will be `"local"`) * https://open.spotify.com/artist/3ZztVuWxHzNpl0THurTFCv (including new regional links like https://open.spotify.com/intl-de/track/0eG08cBeKk0mzykKjw4hcQ) diff --git a/application.example.yml b/application.example.yml index 96a636d7..dd416b0d 100644 --- a/application.example.yml +++ b/application.example.yml @@ -25,7 +25,7 @@ plugins: countryCode: "US" # the country code you want to use for filtering the artists top tracks. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 playlistLoadLimit: 6 # The number of pages at 100 tracks each albumLoadLimit: 6 # The number of pages at 50 tracks each - localFiles: false # Enable local files support with Spotify playlists. (URI and ISRC are null, and ID is set to "local" for all local files) + localFiles: false # Enable local files support with Spotify playlists. Please note `uri` & `iscr` will be `null` & `identifier` will be `"local"` applemusic: countryCode: "US" # the country code you want to use for filtering the artists top tracks and language. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 mediaAPIToken: "..." # apple music api token diff --git a/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java index f96115d6..bf659066 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java @@ -427,12 +427,11 @@ public AudioItem getPlaylist(String id, boolean preview) throws IOException { for (var value : page.get("items").values()) { var track = value.get("track"); - if(track.isNull() || - (this.localFiles ? track.get("type").text().equals("episode") : - track.get("is_local").asBoolean(false) || track.get("type").text().equals("episode"))) { + if (track.isNull() || track.get("type").text().equals("episode") || (!this.localFiles && track.get("is_local").asBoolean(false))) { continue; } - tracks.add(this.parseTrack(track, preview, this.localFiles)); + + tracks.add(this.parseTrack(track, preview)); } } @@ -474,13 +473,13 @@ public AudioItem getTrack(String id, boolean preview) throws IOException { json.get("artists").index(0).put("images", artistJson.get("images")); } - return this.parseTrack(json, preview, this.localFiles); + return this.parseTrack(json, preview); } private List parseTracks(JsonBrowser json, boolean preview) { var tracks = new ArrayList(); for (var value : json.get("tracks").values()) { - tracks.add(this.parseTrack(value, preview, this.localFiles)); + tracks.add(this.parseTrack(value, preview)); } return tracks; } @@ -491,19 +490,19 @@ private List parseTrackItems(JsonBrowser json, boolean preview) { if (value.get("is_local").asBoolean(false)) { continue; } - tracks.add(this.parseTrack(value, preview, this.localFiles)); + tracks.add(this.parseTrack(value, preview)); } return tracks; } - private AudioTrack parseTrack(JsonBrowser json, boolean preview, boolean thisLocalFiles) { - if(thisLocalFiles && json.get("name").isNull()) { + private AudioTrack parseTrack(JsonBrowser json, boolean preview) { + if(json.get("name").isNull()) { return null; } String name = json.get("name").text(); - String artist = thisLocalFiles ? (json.get("artists").index(0).get("name").text() != null ? json.get("artists").index(0).get("name").text() : "local") : json.get("artists").index(0).get("name").text(); - String id = thisLocalFiles ? (json.get("id").text() != null ? json.get("id").text() : "local") : json.get("id").text(); + String artist = Optional.ofNullable(json.get("artists").index(0).get("name").text()).orElse("local"); + String id = Optional.ofNullable(json.get("id").text()).orElse("local"); return new SpotifyAudioTrack( new AudioTrackInfo( From 1e800cb858fb31bcdab0c1186ddffd21c6427f24 Mon Sep 17 00:00:00 2001 From: clapann Date: Sat, 20 Jul 2024 13:03:14 -0700 Subject: [PATCH 6/7] Implement Requested Changes --- .../topi314/lavasrc/spotify/SpotifySourceManager.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java index bf659066..1fceea72 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java @@ -496,17 +496,12 @@ private List parseTrackItems(JsonBrowser json, boolean preview) { } private AudioTrack parseTrack(JsonBrowser json, boolean preview) { - if(json.get("name").isNull()) { - return null; - } - - String name = json.get("name").text(); - String artist = Optional.ofNullable(json.get("artists").index(0).get("name").text()).orElse("local"); - String id = Optional.ofNullable(json.get("id").text()).orElse("local"); + String artist = json.get("artists").index(0).get("name").text() != null ? json.get("artists").index(0).get("name").text() : "local"; + String id = json.get("id").text() != null ? json.get("id").text() : "local"; return new SpotifyAudioTrack( new AudioTrackInfo( - name, + json.get("name").text(), artist, preview ? PREVIEW_LENGTH : json.get("duration_ms").asLong(0), id, From 1f5cafd1b718197e6fdde2ddbfee3bd8337df119 Mon Sep 17 00:00:00 2001 From: clapann Date: Sun, 21 Jul 2024 12:41:49 -0700 Subject: [PATCH 7/7] Implement Requested Changes --- .../topi314/lavasrc/spotify/SpotifySourceManager.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java index 1fceea72..f7b20a59 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/spotify/SpotifySourceManager.java @@ -496,15 +496,12 @@ private List parseTrackItems(JsonBrowser json, boolean preview) { } private AudioTrack parseTrack(JsonBrowser json, boolean preview) { - String artist = json.get("artists").index(0).get("name").text() != null ? json.get("artists").index(0).get("name").text() : "local"; - String id = json.get("id").text() != null ? json.get("id").text() : "local"; - return new SpotifyAudioTrack( new AudioTrackInfo( json.get("name").text(), - artist, + json.get("artists").index(0).get("name").text().isEmpty() ? "Unknown" : json.get("artists").index(0).get("name").text(), preview ? PREVIEW_LENGTH : json.get("duration_ms").asLong(0), - id, + json.get("id").text() != null ? json.get("id").text() : "local", false, json.get("external_urls").get("spotify").text(), json.get("album").get("images").index(0).get("url").text(),