Revert "switch to rspotify's new universal search method"

This reverts commit e55d0ac7ba.
This commit is contained in:
Henrik Friedrichsen
2020-06-25 21:05:49 +02:00
parent 0f08a56f90
commit 03045ba256
4 changed files with 31 additions and 37 deletions

View File

@@ -18,10 +18,9 @@ use rspotify::model::album::{FullAlbum, SavedAlbum, SimplifiedAlbum};
use rspotify::model::artist::FullArtist;
use rspotify::model::page::{CursorBasedPage, Page};
use rspotify::model::playlist::{FullPlaylist, PlaylistTrack, SimplifiedPlaylist};
use rspotify::model::search::SearchResult;
use rspotify::model::search::{SearchAlbums, SearchArtists, SearchPlaylists, SearchTracks};
use rspotify::model::track::{FullTrack, SavedTrack};
use rspotify::model::user::PrivateUser;
use rspotify::senum::SearchType;
use failure::Error;
@@ -643,15 +642,20 @@ impl Spotify {
self.api_with_retry(|api| api.track(track_id))
}
pub fn search(
&self,
searchtype: SearchType,
query: &str,
limit: u32,
offset: u32,
) -> Option<SearchResult> {
self.api_with_retry(|api| api.search(query, searchtype, limit, offset, None, None))
.take()
pub fn search_track(&self, query: &str, limit: u32, offset: u32) -> Option<SearchTracks> {
self.api_with_retry(|api| api.search_track(query, limit, offset, None))
}
pub fn search_album(&self, query: &str, limit: u32, offset: u32) -> Option<SearchAlbums> {
self.api_with_retry(|api| api.search_album(query, limit, offset, None))
}
pub fn search_artist(&self, query: &str, limit: u32, offset: u32) -> Option<SearchArtists> {
self.api_with_retry(|api| api.search_artist(query, limit, offset, None))
}
pub fn search_playlist(&self, query: &str, limit: u32, offset: u32) -> Option<SearchPlaylists> {
self.api_with_retry(|api| api.search_playlist(query, limit, offset, None))
}
pub fn current_user_playlist(

View File

@@ -22,8 +22,6 @@ use crate::track::Track;
use crate::traits::{ListItem, ViewExt};
use crate::ui::listview::{ListView, Pagination};
use crate::ui::tabview::TabView;
use rspotify::model::search::SearchResult;
use rspotify::senum::SearchType;
pub struct SearchView {
results_tracks: Arc<RwLock<Vec<Track>>>,
@@ -131,10 +129,8 @@ impl SearchView {
offset: usize,
append: bool,
) -> u32 {
if let Some(SearchResult::Tracks(results)) =
spotify.search(SearchType::Track, &query, 50, offset as u32)
{
let mut t = results.items.iter().map(|ft| ft.into()).collect();
if let Some(results) = spotify.search_track(&query, 50, offset as u32) {
let mut t = results.tracks.items.iter().map(|ft| ft.into()).collect();
let mut r = tracks.write().unwrap();
if append {
@@ -142,7 +138,7 @@ impl SearchView {
} else {
*r = t;
}
return results.total;
return results.tracks.total;
}
0
}
@@ -170,10 +166,8 @@ impl SearchView {
offset: usize,
append: bool,
) -> u32 {
if let Some(SearchResult::Albums(results)) =
spotify.search(SearchType::Album, &query, 50, offset as u32)
{
let mut a = results.items.iter().map(|sa| sa.into()).collect();
if let Some(results) = spotify.search_album(&query, 50, offset as u32) {
let mut a = results.albums.items.iter().map(|sa| sa.into()).collect();
let mut r = albums.write().unwrap();
if append {
@@ -181,7 +175,7 @@ impl SearchView {
} else {
*r = a;
}
return results.total;
return results.albums.total;
}
0
}
@@ -209,10 +203,8 @@ impl SearchView {
offset: usize,
append: bool,
) -> u32 {
if let Some(SearchResult::Artists(results)) =
spotify.search(SearchType::Artist, &query, 50, offset as u32)
{
let mut a = results.items.iter().map(|fa| fa.into()).collect();
if let Some(results) = spotify.search_artist(&query, 50, offset as u32) {
let mut a = results.artists.items.iter().map(|fa| fa.into()).collect();
let mut r = artists.write().unwrap();
if append {
@@ -220,7 +212,7 @@ impl SearchView {
} else {
*r = a;
}
return results.total;
return results.artists.total;
}
0
}
@@ -248,10 +240,8 @@ impl SearchView {
offset: usize,
append: bool,
) -> u32 {
if let Some(SearchResult::Playlists(results)) =
spotify.search(SearchType::Playlist, &query, 50, offset as u32)
{
let mut pls = results.items.iter().map(|sp| sp.into()).collect();
if let Some(results) = spotify.search_playlist(&query, 50, offset as u32) {
let mut pls = results.playlists.items.iter().map(|sp| sp.into()).collect();
let mut r = playlists.write().unwrap();
if append {
@@ -259,7 +249,7 @@ impl SearchView {
} else {
*r = pls;
}
return results.total;
return results.playlists.total;
}
0
}