ramsayleung / rspotify

Spotify Web API SDK implemented on Rust
MIT License
639 stars 123 forks source link

A way to search for multiple types of content #313

Closed PaulOlteanu closed 2 years ago

PaulOlteanu commented 2 years ago

Is your feature request related to a problem? Please describe. Currently the only way to use the search API is to specify the type of content you'd like to search for (e.g. Track, Album, Artist, etc.). I'd like to search for multiple, or all types of content.

Describe the solution you'd like The search function should take an option of a list of SearchTypes (e.g. Some(&[SearchType::Album, SearchType::Track])).

I'm not sure how the SearchResult would work, perhaps the response could be a Page<SearchResult>, and have SearchResult be an enum with a variant per content type (e.g. SearchResult::Track(FullTrack), SearchResult::Album(SimplifiedAlbum), etc.)

Edit: An even simpler way would to have SearchResult be a struct of options:

pub struct SearchResult {
    playlists: Option<Page<SimplifiedPlaylist>>,
    albums:    Option<Page<SimplifiedAlbum>>,
    artists:   Option<Page<FullArtist>>,
    tracks:    Option<Page<FullTrack>>,
    shows:     Option<Page<SimplifiedShow>>,
    episodes:  Option<Page<SimplifiedEpisode>>,
}

while less ergonomic, this more accurately represents the actual Spotify API response (I also now see that the pagination wouldn't really be feasible the way I first proposed)

PaulOlteanu commented 2 years ago

I think the end result for the user is still gonna be the same - having to handle the search results for the different types independently, so I'm not sure there would be much point to this change (other then perhaps reducing the number of API requests made from 1 per content type per search to one per search)