switch to rspotify's new universal search method

This commit is contained in:
Henrik Friedrichsen
2020-06-07 17:44:28 +02:00
parent 20536580fc
commit e55d0ac7ba
4 changed files with 39 additions and 33 deletions

8
Cargo.lock generated
View File

@@ -1662,7 +1662,7 @@ dependencies = [
[[package]]
name = "ncspot"
version = "0.1.3"
version = "0.1.4"
dependencies = [
"chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1682,7 +1682,7 @@ dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)",
"rspotify 0.9.0 (git+https://github.com/ramsayleung/rspotify?rev=b857a6e685d6b3b43e4ab1802b618cdbb21f3f2c)",
"rspotify 0.9.0 (git+https://github.com/ramsayleung/rspotify?rev=450061bdc17c6282b2c99542fa7078c4bd2cee2d)",
"serde 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)",
"strum 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2437,7 +2437,7 @@ dependencies = [
[[package]]
name = "rspotify"
version = "0.9.0"
source = "git+https://github.com/ramsayleung/rspotify?rev=b857a6e685d6b3b43e4ab1802b618cdbb21f3f2c#b857a6e685d6b3b43e4ab1802b618cdbb21f3f2c"
source = "git+https://github.com/ramsayleung/rspotify?rev=450061bdc17c6282b2c99542fa7078c4bd2cee2d#450061bdc17c6282b2c99542fa7078c4bd2cee2d"
dependencies = [
"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3765,7 +3765,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum reqwest 0.10.6 (registry+https://github.com/rust-lang/crates.io-index)" = "3b82c9238b305f26f53443e3a4bc8528d64b8d0bee408ec949eb7bf5635ec680"
"checksum reqwest 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)" = "f88643aea3c1343c804950d7bf983bd2067f5ab59db6d613a08e05572f2714ab"
"checksum rodio 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d0f961b254e66d147a7b550c78b01308934c97d807a34b417fd0f5a0a0f3a2d"
"checksum rspotify 0.9.0 (git+https://github.com/ramsayleung/rspotify?rev=b857a6e685d6b3b43e4ab1802b618cdbb21f3f2c)" = "<none>"
"checksum rspotify 0.9.0 (git+https://github.com/ramsayleung/rspotify?rev=450061bdc17c6282b2c99542fa7078c4bd2cee2d)" = "<none>"
"checksum rust-argon2 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2bc8af4bda8e1ff4932523b94d3dd20ee30a87232323eda55903ffd71d2fb017"
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
"checksum rustc-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"

View File

@@ -2,7 +2,7 @@
name = "ncspot"
description = "ncurses Spotify client written in Rust using librespot, inspired by ncmpc and the likes."
exclude = ["screenshots/**"]
version = "0.1.3"
version = "0.1.4"
authors = ["Henrik Friedrichsen <henrik@affekt.org>"]
repository = "https://github.com/hrkfdn/ncspot"
keywords = ["spotify", "ncurses", "librespot"]
@@ -28,7 +28,7 @@ librespot-core = "0.1.1"
librespot-playback = "0.1.1"
librespot-protocol = "0.1.1"
log = "0.4.0"
rspotify = { git = "https://github.com/ramsayleung/rspotify", rev = "b857a6e685d6b3b43e4ab1802b618cdbb21f3f2c", features = ["blocking"] }
rspotify = { git = "https://github.com/ramsayleung/rspotify", rev = "450061bdc17c6282b2c99542fa7078c4bd2cee2d", features = ["blocking"] }
serde = "1.0"
serde_json = "1.0"
toml = "0.5"

View File

@@ -18,9 +18,10 @@ 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::{SearchAlbums, SearchArtists, SearchPlaylists, SearchTracks};
use rspotify::model::search::SearchResult;
use rspotify::model::track::{FullTrack, SavedTrack};
use rspotify::model::user::PrivateUser;
use rspotify::senum::SearchType;
use failure::Error;
@@ -580,20 +581,15 @@ impl Spotify {
self.api_with_retry(|api| api.track(track_id))
}
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 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 current_user_playlist(

View File

@@ -22,6 +22,8 @@ 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>>>,
@@ -129,8 +131,10 @@ impl SearchView {
offset: usize,
append: bool,
) -> u32 {
if let Some(results) = spotify.search_track(&query, 50, offset as u32) {
let mut t = results.tracks.items.iter().map(|ft| ft.into()).collect();
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();
let mut r = tracks.write().unwrap();
if append {
@@ -138,7 +142,7 @@ impl SearchView {
} else {
*r = t;
}
return results.tracks.total;
return results.total;
}
0
}
@@ -166,8 +170,10 @@ impl SearchView {
offset: usize,
append: bool,
) -> u32 {
if let Some(results) = spotify.search_album(&query, 50, offset as u32) {
let mut a = results.albums.items.iter().map(|sa| sa.into()).collect();
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();
let mut r = albums.write().unwrap();
if append {
@@ -175,7 +181,7 @@ impl SearchView {
} else {
*r = a;
}
return results.albums.total;
return results.total;
}
0
}
@@ -203,8 +209,10 @@ impl SearchView {
offset: usize,
append: bool,
) -> u32 {
if let Some(results) = spotify.search_artist(&query, 50, offset as u32) {
let mut a = results.artists.items.iter().map(|fa| fa.into()).collect();
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();
let mut r = artists.write().unwrap();
if append {
@@ -212,7 +220,7 @@ impl SearchView {
} else {
*r = a;
}
return results.artists.total;
return results.total;
}
0
}
@@ -240,8 +248,10 @@ impl SearchView {
offset: usize,
append: bool,
) -> u32 {
if let Some(results) = spotify.search_playlist(&query, 50, offset as u32) {
let mut pls = results.playlists.items.iter().map(|sp| sp.into()).collect();
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();
let mut r = playlists.write().unwrap();
if append {
@@ -249,7 +259,7 @@ impl SearchView {
} else {
*r = pls;
}
return results.playlists.total;
return results.total;
}
0
}