From cb1b8841d1a4a0c0500ee3c246949bb9e952c369 Mon Sep 17 00:00:00 2001 From: nansess Date: Fri, 10 May 2024 01:21:20 +0000 Subject: [PATCH] whats luv --- .../deezer/DeezerAudioSourceManager.java | 24 +++- .../lavasrc/spotify/SpotifySourceManager.java | 136 +++++------------- .../topi314/lavasrc/plugin/DeezerConfig.java | 16 +-- .../topi314/lavasrc/plugin/LavaSrcPlugin.java | 12 +- .../topi314/lavasrc/plugin/PandoraConfig.java | 19 +++ 5 files changed, 88 insertions(+), 119 deletions(-) create mode 100644 plugin/src/main/java/com/github/topi314/lavasrc/plugin/PandoraConfig.java diff --git a/main/src/main/java/com/github/topi314/lavasrc/deezer/DeezerAudioSourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/deezer/DeezerAudioSourceManager.java index 303bac9b..6f613048 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/deezer/DeezerAudioSourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/deezer/DeezerAudioSourceManager.java @@ -284,11 +284,18 @@ private AudioItem getAlbum(String id, boolean preview) throws IOException { var artworkUrl = json.get("cover_xl").text(); var author = json.get("contributors").values().get(0).get("name").text(); - for (var track : json.get("tracks").get("data").values()) { - track.get("artist").put("picture_xl", json.get("artist").get("picture_xl")); + var tracks = this.getJson(PUBLIC_API_BASE + "/album/" + id + "/tracks?limit=10000"); + for (var track : tracks.get("data").values()) { + track.get("artist").put("picture_xl", json.get("artist").get("picture_xl")); } - return new DeezerAudioPlaylist(json.get("title").text(), this.parseTracks(json.get("tracks"), preview), DeezerAudioPlaylist.Type.ALBUM, json.get("link").text(), artworkUrl, author, (int) json.get("nb_tracks").asLong(0)); + return new DeezerAudioPlaylist(json.get("title").text(), + this.parseTracks(tracks, preview), + DeezerAudioPlaylist.Type.ALBUM, + json.get("link").text(), + artworkUrl, + author, + (int) json.get("nb_tracks").asLong(0)); // changes made from https://github.com/topi314/LavaSrc/commit/1ebc9ea05fc7d4affcb8730a5aafd8c29357b0fa } private AudioItem getTrack(String id, boolean preview) throws IOException { @@ -308,9 +315,16 @@ private AudioItem getPlaylist(String id, boolean preview) throws IOException { var artworkUrl = json.get("picture_xl").text(); var author = json.get("creator").get("name").text(); - var tracks = this.getJson(PUBLIC_API_BASE + "/playlist/" + id + "/tracks"); + // This endpoint returns tracks with ISRC, unlike the other REST call + var tracks = this.getJson(PUBLIC_API_BASE + "/playlist/" + id + "/tracks?limit=10000"); - return new DeezerAudioPlaylist(json.get("title").text(), this.parseTracks(tracks, preview), DeezerAudioPlaylist.Type.PLAYLIST, json.get("link").text(), artworkUrl, author, (int) json.get("nb_tracks").asLong(0)); + return new DeezerAudioPlaylist(json.get("title").text(), + this.parseTracks(tracks, preview), + DeezerAudioPlaylist.Type.PLAYLIST, + json.get("link").text(), + artworkUrl, + author, + (int) json.get("nb_tracks").asLong(0)); // another change made via https://github.com/topi314/LavaSrc/commit/a7dfa2957a0d8331c1f14692e726c46d9d697012 } private AudioItem getArtist(String id, boolean preview) throws IOException { 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 9ccb2db5..0656fd7f 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 @@ -235,123 +235,65 @@ public AudioItem loadItem(String identifier, boolean preview) { return null; } - public void obtainAccessToken() throws IOException { - var accessTokenUrl = - "https://open.spotify.com/get_access_token?reason=transport&productType=embed"; - var request = new HttpGet(accessTokenUrl); +public void obtainAccessToken() throws IOException { var json = HttpClientTools.fetchResponseAsJson( - this.httpInterfaceManager.getInterface(), - request + this.httpInterfaceManager.getInterface(), + new HttpGet("https://open.spotify.com/get_access_token?reason=transport&productType=embed") ); - this.token = json.get("accessToken").text(); - var expirationTimestampMs = json - .get("accessTokenExpirationTimestampMs") - .asLong(0); - this.tokenExpire = Instant.ofEpochMilli(expirationTimestampMs); - } + this.tokenExpire = Instant.ofEpochMilli(json.get("accessTokenExpirationTimestampMs").asLong(0)); +} - public String getToken() throws IOException { - if ( - this.token == null || - this.tokenExpire == null || - this.tokenExpire.isBefore(Instant.now()) - ) { - this.obtainAccessToken(); +public String getToken() throws IOException { + if (this.token == null || this.tokenExpire == null || this.tokenExpire.isBefore(Instant.now())) { + obtainAccessToken(); } return this.token; - } +} - public JsonBrowser getJson(String uri) throws IOException { +public JsonBrowser getJson(String uri) throws IOException { var request = new HttpGet(uri); - request.addHeader("Authorization", "Bearer " + this.getToken()); - return LavaSrcTools.fetchResponseAsJson( - this.httpInterfaceManager.getInterface(), - request - ); - } + request.addHeader("Authorization", "Bearer " + getToken()); + return LavaSrcTools.fetchResponseAsJson(this.httpInterfaceManager.getInterface(), request); +} - private AudioSearchResult getAutocomplete( - String query, - Set types - ) throws IOException { +private AudioSearchResult getAutocomplete(String query, Set types) throws IOException { if (types.contains(AudioSearchResult.Type.TEXT)) { - throw new IllegalArgumentException( - "text is not a valid search type for Spotify" - ); + throw new IllegalArgumentException("text is not a valid search type for Spotify"); } if (types.isEmpty()) { - types = SEARCH_TYPES; + types = SEARCH_TYPES; } - var url = - API_BASE + - "search?q=" + - URLEncoder.encode(query, StandardCharsets.UTF_8) + - "&type=" + - types - .stream() - .map(AudioSearchResult.Type::getName) - .collect(Collectors.joining(",")); - var json = this.getJson(url); + var url = API_BASE + "search?q=" + URLEncoder.encode(query, StandardCharsets.UTF_8) + "&type=" + + types.stream().map(AudioSearchResult.Type::getName).collect(Collectors.joining(",")); + var json = getJson(url); if (json == null) { - return AudioSearchResult.EMPTY; + return AudioSearchResult.EMPTY; } - var albums = new ArrayList(); - for (var album : json.get("albums").get("items").values()) { - albums.add( - new SpotifyAudioPlaylist( - album.get("name").text(), - Collections.emptyList(), - ExtendedAudioPlaylist.Type.ALBUM, - album.get("external_urls").get("spotify").text(), - album.get("images").index(0).get("url").text(), - album.get("artists").index(0).get("name").text(), - (int) album.get("total_tracks").asLong(0) - ) - ); - } + var tracks = parseTrackItems(json.get("tracks"), false); + var albums = parsePlaylistItems(json.get("albums"), ExtendedAudioPlaylist.Type.ALBUM); + var artists = parsePlaylistItems(json.get("artists"), ExtendedAudioPlaylist.Type.ARTIST); + var playlists = parsePlaylistItems(json.get("playlists"), ExtendedAudioPlaylist.Type.PLAYLIST); - var artists = new ArrayList(); - for (var artist : json.get("artists").get("items").values()) { - artists.add( - new SpotifyAudioPlaylist( - artist.get("name").text() + "'s Top Tracks", - Collections.emptyList(), - ExtendedAudioPlaylist.Type.ARTIST, - artist.get("external_urls").get("spotify").text(), - artist.get("images").index(0).get("url").text(), - artist.get("name").text(), - null - ) - ); - } + return new BasicAudioSearchResult(tracks, albums, artists, playlists, new ArrayList<>()); +} +private List parsePlaylistItems(JsonBrowser items, ExtendedAudioPlaylist.Type type) { var playlists = new ArrayList(); - for (var playlist : json.get("playlists").get("items").values()) { - playlists.add( - new SpotifyAudioPlaylist( - playlist.get("name").text(), - Collections.emptyList(), - ExtendedAudioPlaylist.Type.PLAYLIST, - playlist.get("external_urls").get("spotify").text(), - playlist.get("images").index(0).get("url").text(), - playlist.get("owner").get("display_name").text(), - (int) playlist.get("tracks").get("total").asLong(0) - ) - ); + for (var playlist : items.get("items").values()) { + playlists.add(new SpotifyAudioPlaylist( + playlist.get("name").text(), + Collections.emptyList(), + type, + playlist.get("external_urls").get("spotify").text(), + playlist.get("images").index(0).get("url").text(), + playlist.get("owner").get("display_name").text(), + type == ExtendedAudioPlaylist.Type.PLAYLIST ? (int) playlist.get("tracks").get("total").asLong(0) : null + )); } - - var tracks = this.parseTrackItems(json.get("tracks"), false); - - return new BasicAudioSearchResult( - tracks, - albums, - artists, - playlists, - new ArrayList<>() - ); - } + return playlists; +} public AudioItem getSearch(String query, boolean preview) throws IOException { var json = diff --git a/plugin/src/main/java/com/github/topi314/lavasrc/plugin/DeezerConfig.java b/plugin/src/main/java/com/github/topi314/lavasrc/plugin/DeezerConfig.java index c5568c65..98979ba0 100644 --- a/plugin/src/main/java/com/github/topi314/lavasrc/plugin/DeezerConfig.java +++ b/plugin/src/main/java/com/github/topi314/lavasrc/plugin/DeezerConfig.java @@ -8,21 +8,21 @@ public class DeezerConfig { private String masterDecryptionKey; - private String format; - - public String getFormat() { - return this.format; - } + private String arl; public String getMasterDecryptionKey() { return this.masterDecryptionKey; } + public String getArl() { + return this.arl; + } + public void setMasterDecryptionKey(String masterDecryptionKey) { this.masterDecryptionKey = masterDecryptionKey; } - public void setFormat(String format) { - this.format = format; + public void setArl(String arl) { + this.arl = arl; } -} +} \ No newline at end of file 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 1bcec965..d0925092 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 @@ -7,7 +7,6 @@ import com.github.topi314.lavasrc.flowerytts.FloweryTTSSourceManager; import com.github.topi314.lavasrc.spotify.SpotifySourceManager; import com.github.topi314.lavasrc.tidal.TidalSourceManager; -import com.github.topi314.lavasrc.pandora.PandoraSourceManager; import com.github.topi314.lavasrc.yandexmusic.YandexMusicSourceManager; import com.github.topi314.lavasrc.youtube.YoutubeSearchManager; import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; @@ -35,7 +34,6 @@ public class LavaSrcPlugin private FloweryTTSSourceManager flowerytts; private YoutubeSearchManager youtube; private TidalSourceManager tidal; - private PandoraSourceManager pandora; public LavaSrcPlugin( LavaSrcConfig pluginConfig, @@ -91,9 +89,9 @@ public LavaSrcPlugin( appleMusic.setAlbumPageLimit(appleMusicConfig.getAlbumLoadLimit()); } } - if (sourcesConfig.isDeezer()) { - this.deezer = new DeezerAudioSourceManager(deezerConfig.getArl()); - } + if (sourcesConfig.isDeezer()) { + this.deezer = new DeezerAudioSourceManager(); + } if (sourcesConfig.isYandexMusic()) { this.yandexMusic = new YandexMusicSourceManager(yandexMusicConfig.getAccessToken()); @@ -131,10 +129,6 @@ public AudioPlayerManager configure(@NotNull AudioPlayerManager manager) { log.info("Registering Apple Music audio source manager..."); manager.registerSourceManager(this.appleMusic); } - if (this.pandora != null) { - log.info("Registering Pandora audio source manager..."); - manager.registerSourceManager(this.pandora); - } if (this.deezer != null) { log.info("Registering Deezer audio source manager..."); manager.registerSourceManager(this.deezer); diff --git a/plugin/src/main/java/com/github/topi314/lavasrc/plugin/PandoraConfig.java b/plugin/src/main/java/com/github/topi314/lavasrc/plugin/PandoraConfig.java new file mode 100644 index 00000000..a07e59a2 --- /dev/null +++ b/plugin/src/main/java/com/github/topi314/lavasrc/plugin/PandoraConfig.java @@ -0,0 +1,19 @@ +package com.github.topi314.lavasrc.plugin; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@ConfigurationProperties(prefix = "plugins.lavasrc.pandora") +@Component +public class PandoraConfig { + + private static String countryCode; + + public static String getCountryCode() { + return countryCode; + } + + public void setCountryCode(String countryCode) { + this.countryCode = countryCode; + } +}