Skip to content
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

Closed
wants to merge 12 commits into from

Conversation

llimonix
Copy link

I checked on different playlists that caused errors, it works correctly

@topi314 topi314 linked an issue Dec 30, 2023 that may be closed by this pull request
Comment on lines 173 to 174
List<String> trackIds = playlistTracks.subList(i, endIndex);
var trackIdsStr = String.join("%2C", trackIds);
Copy link
Owner

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) {
Copy link
Owner

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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this a constant

@llimonix llimonix requested a review from topi314 January 1, 2024 16:27
Copy link
Owner

@topi314 topi314 left a 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

@llimonix
Copy link
Author

llimonix commented Jan 2, 2024

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

@llimonix llimonix requested a review from topi314 January 2, 2024 16:58
Copy link
Owner

@topi314 topi314 left a 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

Comment on lines +170 to +171
for (int i = 0; i < playlistTracks.size(); i += 300) {
int endIndex = Math.min(i + 300, playlistTracks.size());
Copy link
Owner

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

Comment on lines +173 to +174
String trackIdsStr = trackIds.stream()
.collect(Collectors.joining(","));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@@ -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")) {
Copy link
Owner

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()) {
Copy link
Owner

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()) {
Copy link
Owner

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()) {
Copy link
Owner

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()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

Copy link
Author

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

Copy link
Owner

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

Copy link
Author

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

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@topi314
Copy link
Owner

topi314 commented Feb 17, 2024

do you still want this or can I close it?

@llimonix
Copy link
Author

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

@topi314
Copy link
Owner

topi314 commented Feb 18, 2024

the main issue is the error handling
you are returning no track found if there is an error in the response which is not good since we wouldnt know if an error happened
you can make a similar method to this in deezer to check for errors in responses which would throw an appropriate error https://github.com/topi314/LavaSrc/blob/master/main/src/main/java/com/github/topi314/lavasrc/deezer/DeezerAudioTrack.java#L68

@llimonix
Copy link
Author

the main issue is the error handling you are returning no track found if there is an error in the response which is not good since we wouldnt know if an error happened you can make a similar method to this in deezer to check for errors in responses which would throw an appropriate error https://github.com/topi314/LavaSrc/blob/master/main/src/main/java/com/github/topi314/lavasrc/deezer/DeezerAudioTrack.java#L68

if I leave what was before my changes, will it be wrong too?

if (json.isNull() || json.get("result").isNull())
if (json.isNull() || json.get("result").isNull() || json.get("result").get("tracks").values().isEmpty())

And so on

@topi314
Copy link
Owner

topi314 commented May 16, 2024

is this still relevant after #197?

@llimonix llimonix closed this May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

some playlists don't work
2 participants