From fbdb3e0a70fb1a6f000b0d0ed2d5a44ffe7d690f Mon Sep 17 00:00:00 2001 From: BrokenFG Date: Tue, 24 Oct 2023 23:08:38 +0300 Subject: [PATCH 01/12] Added support for manually uploaded tracks (only those uploaded by the token owner available) Implemented recognition of track links without specifying the album, e.g., https://music.yandex.ru/track/75370207 Now, if a track has multiple artists, all of them will be listed in the author field instead of just one. --- .../yandexmusic/YandexMusicSourceManager.java | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java index 402eb164..49ffccd7 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java @@ -26,9 +26,11 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.regex.Pattern; +import java.util.stream.Collectors; public class YandexMusicSourceManager implements AudioSourceManager, HttpConfigurable { public static final Pattern URL_PATTERN = Pattern.compile("(https?://)?music\\.yandex\\.(ru|com)/(?artist|album)/(?[0-9]+)/?((?track/)(?[0-9]+)/?)?"); + public static final Pattern URL_TRACK_PATTERN = Pattern.compile("(https?://)?music\\.yandex\\.(ru|com)/(?track)/(?[0-9]+)"); public static final Pattern URL_PLAYLIST_PATTERN = Pattern.compile("(https?://)?music\\.yandex\\.(ru|com)/users/(?[0-9A-Za-z@.-]+)/playlists/(?[0-9]+)/?"); public static final String SEARCH_PREFIX = "ymsearch:"; public static final String PUBLIC_API_BASE = "https://api.music.yandex.net"; @@ -75,6 +77,11 @@ public AudioItem loadItem(AudioPlayerManager manager, AudioReference reference) } return null; } + matcher = URL_TRACK_PATTERN.matcher(reference.identifier); + if (matcher.find()) { + var trackId = matcher.group("identifier"); + return this.getTrack(trackId); + } matcher = URL_PLAYLIST_PATTERN.matcher(reference.identifier); if (matcher.find()) { var userId = matcher.group("identifier"); @@ -193,12 +200,12 @@ private List parseTracks(JsonBrowser json) { } private AudioTrack parseTrack(JsonBrowser json) { - if (!json.get("available").asBoolean(false) || json.get("albums").values().isEmpty()) { + if (!json.get("available").asBoolean(false)) { return null; } var id = json.get("id").text(); - var artist = json.get("major").get("name").text().equals("PODCASTS") ? json.get("albums").values().get(0).get("title").text() : json.get("artists").values().get(0).get("name").text(); - var coverUri = json.get("albums").values().get(0).get("coverUri").text(); + var artist = parseArtist(json); + var coverUri = json.get("coverUri").text(); return new YandexMusicAudioTrack( new AudioTrackInfo( json.get("title").text(), @@ -206,14 +213,36 @@ private AudioTrack parseTrack(JsonBrowser json) { json.get("durationMs").as(Long.class), id, false, - "https://music.yandex.ru/album/" + json.get("albums").values().get(0).get("id").text() + "/track/" + id, - this.formatCoverUri(coverUri), + "https://music.yandex.ru/track/" + id, + this.formatCoverUri(coverUri), null ), this ); } + private String parseArtist(JsonBrowser json) { + if (!json.get("major").isNull() && json.get("major").get("name").text().equals("PODCASTS")) { + return json.get("albums").values().get(0).get("title").text(); + } + + if (!json.get("artists").values().isEmpty()) { + return extractArtists(json.get("artists")); + } + + if (!json.get("matchedTrack").isNull()) { + return extractArtists(json.get("matchedTrack").get("artists")); + } + + return "Unknown"; + } + + private String extractArtists(JsonBrowser artistNode) { + return artistNode.values().stream() + .map(node -> node.get("name").text()) + .collect(Collectors.joining(", ")); + } + private String formatCoverUri(String coverUri) { return coverUri != null ? "https://" + coverUri.replace("%%", "400x400") : null; } From 5a2db420d9740df1b41968243ec4f8eb135a3439 Mon Sep 17 00:00:00 2001 From: BrokenFG Date: Tue, 24 Oct 2023 23:11:03 +0300 Subject: [PATCH 02/12] Added support for manually uploaded tracks (only those uploaded by the token owner available) Implemented recognition of track links without specifying the album, e.g., https://music.yandex.ru/track/75370207 Now, if a track has multiple artists, all of them will be listed in the author field instead of just one. --- .../topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java index 49ffccd7..40178a0a 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java @@ -214,7 +214,7 @@ private AudioTrack parseTrack(JsonBrowser json) { id, false, "https://music.yandex.ru/track/" + id, - this.formatCoverUri(coverUri), + this.formatCoverUri(coverUri), null ), this From 37ab96b2e953e4e833e4609aa85fee0b665354b2 Mon Sep 17 00:00:00 2001 From: BrokenFG <41708268+BrokenFG@users.noreply.github.com> Date: Wed, 25 Oct 2023 21:04:37 +0300 Subject: [PATCH 03/12] Combine patterns --- .../yandexmusic/YandexMusicSourceManager.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java index 40178a0a..415a46c4 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java @@ -29,8 +29,7 @@ import java.util.stream.Collectors; public class YandexMusicSourceManager implements AudioSourceManager, HttpConfigurable { - public static final Pattern URL_PATTERN = Pattern.compile("(https?://)?music\\.yandex\\.(ru|com)/(?artist|album)/(?[0-9]+)/?((?track/)(?[0-9]+)/?)?"); - public static final Pattern URL_TRACK_PATTERN = Pattern.compile("(https?://)?music\\.yandex\\.(ru|com)/(?track)/(?[0-9]+)"); + public static final Pattern URL_PATTERN = Pattern.compile("(https?://)?music\\.yandex\\.(ru|com)/(?artist|album|track)/(?[0-9]+)(/(?track)/(?[0-9]+))?/?"); public static final Pattern URL_PLAYLIST_PATTERN = Pattern.compile("(https?://)?music\\.yandex\\.(ru|com)/users/(?[0-9A-Za-z@.-]+)/playlists/(?[0-9]+)/?"); public static final String SEARCH_PREFIX = "ymsearch:"; public static final String PUBLIC_API_BASE = "https://api.music.yandex.net"; @@ -74,14 +73,12 @@ public AudioItem loadItem(AudioPlayerManager manager, AudioReference reference) case "artist": var artistId = matcher.group("identifier"); return this.getArtist(artistId); + case "track": + var trackId = matcher.group("identifier"); + return this.getTrack(trackId); } return null; } - matcher = URL_TRACK_PATTERN.matcher(reference.identifier); - if (matcher.find()) { - var trackId = matcher.group("identifier"); - return this.getTrack(trackId); - } matcher = URL_PLAYLIST_PATTERN.matcher(reference.identifier); if (matcher.find()) { var userId = matcher.group("identifier"); @@ -283,4 +280,4 @@ public void shutdown() { public HttpInterface getHttpInterface() { return this.httpInterfaceManager.getInterface(); } -} \ No newline at end of file +} From 98fb9700c540b5c71250eac35fbc8632eb30f98a Mon Sep 17 00:00:00 2001 From: BrokenFG Date: Fri, 27 Oct 2023 13:50:44 +0300 Subject: [PATCH 04/12] fix issue when some playlists don't provide track info --- .../yandexmusic/YandexMusicSourceManager.java | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java index 402eb164..2ff080cb 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java @@ -10,15 +10,20 @@ import com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface; import com.sedmelluq.discord.lavaplayer.tools.io.HttpInterfaceManager; import com.sedmelluq.discord.lavaplayer.track.*; +import org.apache.http.NameValuePair; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.utils.URIBuilder; import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.message.BasicNameValuePair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -26,6 +31,7 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.regex.Pattern; +import java.util.stream.Collectors; public class YandexMusicSourceManager implements AudioSourceManager, HttpConfigurable { public static final Pattern URL_PATTERN = Pattern.compile("(https?://)?music\\.yandex\\.(ru|com)/(?artist|album)/(?[0-9]+)/?((?track/)(?[0-9]+)/?)?"); @@ -81,10 +87,10 @@ public AudioItem loadItem(AudioPlayerManager manager, AudioReference reference) var playlistId = matcher.group("identifier2"); return this.getPlaylist(userId, playlistId); } - } catch (IOException e) { + } catch (IOException | URISyntaxException e) { throw new RuntimeException(e); } - return null; + return null; } private AudioItem getSearch(String query) throws IOException { @@ -146,14 +152,18 @@ private AudioItem getArtist(String id) throws IOException { return new YandexMusicAudioPlaylist(author + "'s Top Tracks", tracks, ExtendedAudioPlaylist.Type.ARTIST, json.get("result").get("url").text(), this.formatCoverUri(coverUri), author); } - private AudioItem getPlaylist(String userString, String id) throws IOException { + private AudioItem getPlaylist(String userString, String id) throws IOException, URISyntaxException { var json = this.getJson(PUBLIC_API_BASE + "/users/" + userString + "/playlists/" + id); if (json.isNull() || json.get("result").isNull() || json.get("result").get("tracks").values().isEmpty()) { return AudioReference.NO_TRACK; } var tracks = new ArrayList(); - for (var track : json.get("result").get("tracks").values()) { - var parsedTrack = this.parseTrack(track.get("track")); + var tracksToParse = json.get("result").get("tracks").values(); + if (tracksToParse.get(0).get("track").isNull()) { + tracksToParse = getTracks(getTrackIds(tracksToParse)); + } + for (var track : tracksToParse) { + var parsedTrack = track.get("track").isNull() ? this.parseTrack(track) : this.parseTrack(track.get("track")); if (parsedTrack != null) { tracks.add(parsedTrack); } @@ -167,13 +177,37 @@ private AudioItem getPlaylist(String userString, String id) throws IOException { return new YandexMusicAudioPlaylist(playlistTitle, tracks, ExtendedAudioPlaylist.Type.PLAYLIST, json.get("result").get("url").text(), this.formatCoverUri(coverUri), author); } + private List getTracks(String trackIds) throws URISyntaxException, IOException { + return getJson(PUBLIC_API_BASE + "/tracks", new ArrayList<>() {{ + add(new BasicNameValuePair("track-ids", trackIds)); + }}).get("result").values(); + } + + private String getTrackIds(List tracksToParse) { + return tracksToParse.stream() + .map(node -> node.get("id").text()) + .collect(Collectors.joining(",")); + } + public JsonBrowser getJson(String uri) throws IOException { + return getJson(URI.create(uri)); + } + + public JsonBrowser getJson(String uri, List params) throws URISyntaxException, IOException { + return getJson(buildUriWithParams(uri, params)); + } + + public JsonBrowser getJson(URI uri) throws IOException { var request = new HttpGet(uri); request.setHeader("Accept", "application/json"); request.setHeader("Authorization", "OAuth " + this.accessToken); return LavaSrcTools.fetchResponseAsJson(this.httpInterfaceManager.getInterface(), request); } + private URI buildUriWithParams(String uri, List params) throws URISyntaxException { + return new URIBuilder(uri).addParameters(params).build(); + } + public String getDownloadStrings(String uri) throws IOException { var request = new HttpGet(uri); request.setHeader("Accept", "application/json"); From 4107908344fb4462a7f56a8c212ad72c2f30cdbe Mon Sep 17 00:00:00 2001 From: BrokenFG <41708268+BrokenFG@users.noreply.github.com> Date: Fri, 9 Feb 2024 00:47:50 +0300 Subject: [PATCH 05/12] Update main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Toπ --- .../lavasrc/yandexmusic/YandexMusicSourceManager.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java index f11f9c10..4057cf64 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java @@ -180,10 +180,8 @@ private AudioItem getPlaylist(String userString, String id) throws IOException, return new YandexMusicAudioPlaylist(playlistTitle, tracks, ExtendedAudioPlaylist.Type.PLAYLIST, json.get("result").get("url").text(), this.formatCoverUri(coverUri), author); } - private List getTracks(String trackIds) throws URISyntaxException, IOException { - return getJson(PUBLIC_API_BASE + "/tracks", new ArrayList<>() {{ - add(new BasicNameValuePair("track-ids", trackIds)); - }}).get("result").values(); + private List getTracks(String trackIds) throws IOException { + return getJson(PUBLIC_API_BASE + "/tracks?track-ids=" + URLEncoder.encode(trackIds, StandardCharsets.UTF_8)).get("result").values(); } private String getTrackIds(List tracksToParse) { From 4f1259da03ac9a7e497b2bcfe2434492838adf9b Mon Sep 17 00:00:00 2001 From: BrokenFG Date: Fri, 9 Feb 2024 00:50:30 +0300 Subject: [PATCH 06/12] add new supported link --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b1e64204..5ed463ad 100644 --- a/README.md +++ b/README.md @@ -315,6 +315,7 @@ LavaSrc adds the following fields to tracks & playlists in Lavalink * `ymsearch:animals architects` * https://music.yandex.ru/album/13886032/track/71663565 * https://music.yandex.ru/album/13886032 +* https://music.yandex.ru/track/71663565 * https://music.yandex.ru/users/yamusic-bestsongs/playlists/701626 * https://music.yandex.ru/artist/701626 From 7de5eedcf4fce344bf2d8838b1d909fa3ac11578 Mon Sep 17 00:00:00 2001 From: BrokenFG <41708268+BrokenFG@users.noreply.github.com> Date: Thu, 22 Feb 2024 21:09:32 +0300 Subject: [PATCH 07/12] Update main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Toπ --- .../topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java index 4057cf64..1a5cc8ac 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java @@ -93,7 +93,7 @@ public AudioItem loadItem(AudioPlayerManager manager, AudioReference reference) } catch (IOException | URISyntaxException e) { throw new RuntimeException(e); } - return null; + return null; } private AudioItem getSearch(String query) throws IOException { From e5cbeb1dd189f58231da076b42c89a68caf6cb79 Mon Sep 17 00:00:00 2001 From: BrokenFG <41708268+BrokenFG@users.noreply.github.com> Date: Thu, 22 Feb 2024 21:09:36 +0300 Subject: [PATCH 08/12] Update main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Toπ --- .../topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java index 1a5cc8ac..97bb34b4 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java @@ -90,7 +90,7 @@ public AudioItem loadItem(AudioPlayerManager manager, AudioReference reference) var playlistId = matcher.group("identifier2"); return this.getPlaylist(userId, playlistId); } - } catch (IOException | URISyntaxException e) { + } catch (IOException e) { throw new RuntimeException(e); } return null; From 42c2873db7dd2fc6e922d8dc3fd951561a788f72 Mon Sep 17 00:00:00 2001 From: BrokenFG <41708268+BrokenFG@users.noreply.github.com> Date: Thu, 22 Feb 2024 21:09:44 +0300 Subject: [PATCH 09/12] Update main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Toπ --- .../topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java index 97bb34b4..09b7171a 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java @@ -205,10 +205,6 @@ public JsonBrowser getJson(URI uri) throws IOException { return LavaSrcTools.fetchResponseAsJson(this.httpInterfaceManager.getInterface(), request); } - private URI buildUriWithParams(String uri, List params) throws URISyntaxException { - return new URIBuilder(uri).addParameters(params).build(); - } - public String getDownloadStrings(String uri) throws IOException { var request = new HttpGet(uri); request.setHeader("Accept", "application/json"); From a946d2c990fab28269468d20790e2d43a4cdf775 Mon Sep 17 00:00:00 2001 From: BrokenFG <41708268+BrokenFG@users.noreply.github.com> Date: Thu, 22 Feb 2024 21:09:49 +0300 Subject: [PATCH 10/12] Update main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Toπ --- .../topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java index 09b7171a..c89dedab 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java @@ -194,10 +194,6 @@ public JsonBrowser getJson(String uri) throws IOException { return getJson(URI.create(uri)); } - public JsonBrowser getJson(String uri, List params) throws URISyntaxException, IOException { - return getJson(buildUriWithParams(uri, params)); - } - public JsonBrowser getJson(URI uri) throws IOException { var request = new HttpGet(uri); request.setHeader("Accept", "application/json"); From a3b0d18b5a08c197b9f90f4e07a43dfe45a2b359 Mon Sep 17 00:00:00 2001 From: BrokenFG <41708268+BrokenFG@users.noreply.github.com> Date: Thu, 22 Feb 2024 21:18:02 +0300 Subject: [PATCH 11/12] Update YandexMusicSourceManager.java --- .../topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java index c89dedab..06d95003 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java @@ -191,10 +191,6 @@ private String getTrackIds(List tracksToParse) { } public JsonBrowser getJson(String uri) throws IOException { - return getJson(URI.create(uri)); - } - - public JsonBrowser getJson(URI uri) throws IOException { var request = new HttpGet(uri); request.setHeader("Accept", "application/json"); request.setHeader("Authorization", "OAuth " + this.accessToken); From dadd8a28d4f331d39a9788605d942fc7755c4597 Mon Sep 17 00:00:00 2001 From: topi314 Date: Tue, 5 Mar 2024 09:49:56 +0100 Subject: [PATCH 12/12] cleanup last issues --- .../yandexmusic/YandexMusicSourceManager.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java index 06d95003..7e2ed2fa 100644 --- a/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java +++ b/main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java @@ -10,20 +10,15 @@ import com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface; import com.sedmelluq.discord.lavaplayer.tools.io.HttpInterfaceManager; import com.sedmelluq.discord.lavaplayer.track.*; -import org.apache.http.NameValuePair; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.utils.URIBuilder; import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.message.BasicNameValuePair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -79,8 +74,8 @@ public AudioItem loadItem(AudioPlayerManager manager, AudioReference reference) var artistId = matcher.group("identifier"); return this.getArtist(artistId); case "track": - var trackId = matcher.group("identifier"); - return this.getTrack(trackId); + var trackId = matcher.group("identifier"); + return this.getTrack(trackId); } return null; } @@ -155,7 +150,7 @@ private AudioItem getArtist(String id) throws IOException { return new YandexMusicAudioPlaylist(author + "'s Top Tracks", tracks, ExtendedAudioPlaylist.Type.ARTIST, json.get("result").get("url").text(), this.formatCoverUri(coverUri), author); } - private AudioItem getPlaylist(String userString, String id) throws IOException, URISyntaxException { + private AudioItem getPlaylist(String userString, String id) throws IOException { var json = this.getJson(PUBLIC_API_BASE + "/users/" + userString + "/playlists/" + id); if (json.isNull() || json.get("result").isNull() || json.get("result").get("tracks").values().isEmpty()) { return AudioReference.NO_TRACK; @@ -186,8 +181,8 @@ private List getTracks(String trackIds) throws IOException { private String getTrackIds(List tracksToParse) { return tracksToParse.stream() - .map(node -> node.get("id").text()) - .collect(Collectors.joining(",")); + .map(node -> node.get("id").text()) + .collect(Collectors.joining(",")); } public JsonBrowser getJson(String uri) throws IOException { @@ -255,8 +250,8 @@ private String parseArtist(JsonBrowser json) { private String extractArtists(JsonBrowser artistNode) { return artistNode.values().stream() - .map(node -> node.get("name").text()) - .collect(Collectors.joining(", ")); + .map(node -> node.get("name").text()) + .collect(Collectors.joining(", ")); } private String formatCoverUri(String coverUri) {