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

Can I sort data by popularity from search response? #138

Open
vovaklh opened this issue Feb 22, 2023 · 3 comments
Open

Can I sort data by popularity from search response? #138

vovaklh opened this issue Feb 22, 2023 · 3 comments

Comments

@vovaklh
Copy link

vovaklh commented Feb 22, 2023

Now search response contains a List of pages. Each page contains tracks or albums, or something else. How I can combine tracks and albums on UI and sort data by popularity?

@hayribakici
Copy link
Collaborator

hayribakici commented Feb 27, 2023

In the search, the access of the popularity property can only be done throughArtist and Track. It is not possible with Album as the search uses a simple version (AlbumSimple) of the Album model, which does not contain the popularity property. I think an investigation is necessary here, if Album can bu used in the search handling.

What would also be interesting is to extract common properties like href of popularity into parent objects, so that sorting by popularity beyond the search result type (Album, Track etc.) can be possible. @rinukkusu What do you think about this?

@vovaklh, I would filter out the Album, Tracks etc. of the search results into a separate lists and sort each type by popularity.

@rinukkusu
Copy link
Owner

Yeah, we'd need to look into that Album issue. The Spotify API docs sadly don't really make clear when they're using the stripped down version of their entities and when not. Sometimes you can deduct it from the request/response examples, but they don't seem to be always accurate.

@hayribakici
Copy link
Collaborator

hayribakici commented Apr 9, 2023

Regarding this issue, I am suggesting this solution:

class Popularity {
  int? popularity;
}

so that Artist and Track can implement it with

class Track extends TrackSimple implements Popularity {
...
}

, so that it is possible to extract the types with a popularity property by implementing

  var search = await spotify.search.get('metallica').first(2);

  search.forEach((pages) {
    var pops = pages.items!.whereType<Popularity>().toList();
    pops.sort((a, b) => a.popularity?.compareTo(b.popularity ?? 0) ?? 0);
    ...
  }

@rinukkusu @vovaklh What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants