-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LavaSrc fix Yandex Music playlist and artist's track limit #155
Conversation
List<String> trackIds = playlistTracks.subList(i, endIndex); | ||
var trackIdsStr = String.join("%2C", trackIds); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please properly url encode this instead of simply joining with %2C
You can also do this using a stream
playlistTracks.add(track.get("id").text()); | ||
|
||
} | ||
if (playlistTracks.size() != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use early returns, avoid if else
if possible
if (playlistTracks.size() == 0) {
return AudioReference.NO_TRACK;
}
you can also already return by checking the length of json.get("result").get("tracks").values()
|
||
} | ||
if (playlistTracks.size() != 0) { | ||
int chunkSize = 300; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this a constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the lavaplayer api does not support returning playlists, albums or artists in search results, so it makes no sense to return them here
that being said, LavaSearch does support this so please implement this for LavaSearch instead if you want this feature
You can checkout Deezer, Spotify, YT or Apple Music for an example implementation
main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java
Outdated
Show resolved
Hide resolved
main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java
Outdated
Show resolved
Hide resolved
main/src/main/java/com/github/topi314/lavasrc/yandexmusic/YandexMusicSourceManager.java
Outdated
Show resolved
Hide resolved
I rolled back the solutions with the search for more than just tracks. Since I did not understand how to implement it correctly in order to transmit it in the correct format. My solution works and searches for the best match for a text query. But as I understand it, you need to get a track list from the best result, if it is a playlist/album/artist, and pass it to return new BasicAudioPlaylist("Yandex Music Search: " + query, tracks, null, true); But, alas. It is not yet clear how to do this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the extended search functionality via LavaSearch you have to implement the AudioSearchManager
interface in the YandexMusicSourceManager
.
You can check this here for deezer as an example https://github.com/topi314/LavaSrc/blob/master/main/src/main/java/com/github/topi314/lavasrc/deezer/DeezerAudioSourceManager.java#L83
for (int i = 0; i < playlistTracks.size(); i += 300) { | ||
int endIndex = Math.min(i + 300, playlistTracks.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is still not a constant
String trackIdsStr = trackIds.stream() | ||
.collect(Collectors.joining(",")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String trackIdsStr = trackIds.stream() | |
.collect(Collectors.joining(",")); | |
String trackIdsStr = trackIds.stream().collect(Collectors.joining(",")); |
var playlistTitle = json.get("result").get("kind").text().equals("3") ? "Liked songs" : json.get("result").get("title").text(); | ||
var coverUri = json.get("result").get("cover").get("uri").text(); | ||
var author = json.get("result").get("owner").get("name").text(); | ||
return new YandexMusicAudioPlaylist(playlistTitle, tracks, ExtendedAudioPlaylist.Type.PLAYLIST, json.get("result").get("url").text(), this.formatCoverUri(coverUri), author); | ||
} | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -123,15 +123,15 @@ private AudioItem getAlbum(String id) throws IOException { | |||
|
|||
private AudioItem getTrack(String id) throws IOException { | |||
var json = this.getJson(PUBLIC_API_BASE + "/tracks/" + id); | |||
if (json.isNull() || json.get("result").values().get(0).get("available").text().equals("false")) { | |||
if (json == null || json.isNull() || !json.get("error").isNull() || json.get("result").values().get(0).get("available").text().equals("false")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of returning AudioReference.NO_TRACK
on error we should throw an exception
var json = this.getJson(PUBLIC_API_BASE + "/artists/" + id + "/tracks?page-size=10"); | ||
if (json.isNull() || json.get("result").values().isEmpty()) { | ||
var json = this.getJson(PUBLIC_API_BASE + "/artists/" + id + "/tracks?page_size=300"); | ||
if (json == null || json.isNull() || !json.get("error").isNull() || json.get("result").values().isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too
|
||
private AudioItem getAlbum(String id) throws IOException { | ||
var json = this.getJson(PUBLIC_API_BASE + "/albums/" + id + "/with-tracks"); | ||
if (json.isNull() || json.get("result").isNull()) { | ||
if (json == null || json.isNull() || !json.get("error").isNull() || json.get("result").isNull()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too
@@ -89,19 +90,18 @@ public AudioItem loadItem(AudioPlayerManager manager, AudioReference reference) | |||
|
|||
private AudioItem getSearch(String query) throws IOException { | |||
var json = this.getJson(PUBLIC_API_BASE + "/search?text=" + URLEncoder.encode(query, StandardCharsets.UTF_8) + "&type=track&page=0"); | |||
if (json.isNull() || json.get("result").get("tracks").isNull()) { | |||
if (json == null || json.isNull() || !json.get("error").isNull() || json.get("result").get("tracks").isNull()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too
@@ -148,7 +148,7 @@ private AudioItem getArtist(String id) throws IOException { | |||
|
|||
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()) { | |||
if (json == null || json.isNull() || !json.get("error").isNull() || json.get("result").isNull() || json.get("result").get("tracks").values().isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't understand anything. I've only added json == null here and !json.get("error").isNull()
Since sometimes the response comes without json and json.isNull() returns an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you already check for an error response here !json.get("error").isNull()
then you might as well throw an error when we get those.
silently returning no track on error would be kinda bad
before it would run into the code below and throw an error there since the other json props are missing, but this isnt the case anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Show an example of how to fix it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you still want this or can I close it? |
I understand that I have errors in the correctness of writing the code. I do not know how to fix them so that everything fits you. I compiled everything for myself, there were no problems. I'm too lazy to think about how to fix it. The error on your part has not been resolved, and playlists remain that simply do not work. Close it |
the main issue is the error handling |
if I leave what was before my changes, will it be wrong too? if (json.isNull() || json.get("result").isNull()) And so on |
is this still relevant after #197? |
I checked on different playlists that caused errors, it works correctly