migrate to rspotify 0.10.0

in preparation for the future release with podcast API support
This commit is contained in:
Henrik Friedrichsen
2020-06-06 12:01:16 +02:00
parent 6f38c67ee3
commit bb89d189ae
9 changed files with 54 additions and 48 deletions

6
Cargo.lock generated
View File

@@ -1683,7 +1683,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.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rspotify 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"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.8.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3766,7 +3766,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.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a924a166cfb1315c8d9c89148e438a1337feb655ce052fc6dc952af8018bad93"
"checksum rspotify 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eefd7bb58b714606b30a490f751d7926942e2874eef5e82934d60d7a4a68dca4"
"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

@@ -28,7 +28,7 @@ librespot-core = "0.1.1"
librespot-playback = "0.1.1"
librespot-protocol = "0.1.1"
log = "0.4.0"
rspotify = "0.8"
rspotify = { version = "0.10.0", features = ["blocking"] }
serde = "1.0"
serde_json = "1.0"
toml = "0.5"

View File

@@ -2,7 +2,7 @@ use std::fmt;
use std::sync::Arc;
use chrono::{DateTime, Utc};
use rspotify::spotify::model::album::{FullAlbum, SavedAlbum, SimplifiedAlbum};
use rspotify::model::album::{FullAlbum, SavedAlbum, SimplifiedAlbum};
use crate::artist::Artist;
use crate::library::Library;

View File

@@ -1,7 +1,7 @@
use std::fmt;
use std::sync::Arc;
use rspotify::spotify::model::artist::{FullArtist, SimplifiedArtist};
use rspotify::model::artist::{FullArtist, SimplifiedArtist};
use crate::album::Album;
use crate::library::Library;

View File

@@ -5,7 +5,7 @@ use std::path::PathBuf;
use std::sync::{Arc, RwLock, RwLockReadGuard};
use std::thread;
use rspotify::spotify::model::playlist::SimplifiedPlaylist;
use rspotify::model::playlist::SimplifiedPlaylist;
use serde::de::DeserializeOwned;
use serde::Serialize;

View File

@@ -1,7 +1,7 @@
use std::iter::Iterator;
use std::sync::Arc;
use rspotify::spotify::model::playlist::{FullPlaylist, SimplifiedPlaylist};
use rspotify::model::playlist::{FullPlaylist, SimplifiedPlaylist};
use crate::library::Library;
use crate::queue::Queue;
@@ -31,7 +31,9 @@ impl Playlist {
let mut tracks_result = spotify.user_playlist_tracks(&self.id, 100, 0);
while let Some(ref tracks) = tracks_result.clone() {
for listtrack in &tracks.items {
collected_tracks.push((&listtrack.track).into());
if let Some(track) = &listtrack.track {
collected_tracks.push(track.into());
}
}
debug!("got {} tracks", tracks.items.len());

View File

@@ -12,17 +12,16 @@ use librespot_playback::config::Bitrate;
use librespot_playback::mixer::Mixer;
use librespot_playback::player::{Player, PlayerEvent as LibrespotPlayerEvent};
use rspotify::spotify::client::ApiError;
use rspotify::spotify::client::Spotify as SpotifyAPI;
use rspotify::spotify::model::album::{FullAlbum, SavedAlbum, SimplifiedAlbum};
use rspotify::spotify::model::artist::FullArtist;
use rspotify::spotify::model::page::{CursorBasedPage, Page};
use rspotify::spotify::model::playlist::{FullPlaylist, PlaylistTrack, SimplifiedPlaylist};
use rspotify::spotify::model::search::{
SearchAlbums, SearchArtists, SearchPlaylists, SearchTracks,
};
use rspotify::spotify::model::track::{FullTrack, SavedTrack};
use rspotify::spotify::model::user::PrivateUser;
use rspotify::blocking::client::ApiError;
use rspotify::blocking::client::Spotify as SpotifyAPI;
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::track::{FullTrack, SavedTrack};
use rspotify::model::user::PrivateUser;
use rspotify::senum::SearchType;
use serde_json::json;
@@ -667,20 +666,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

@@ -2,8 +2,8 @@ use std::fmt;
use std::sync::Arc;
use chrono::{DateTime, Utc};
use rspotify::spotify::model::album::FullAlbum;
use rspotify::spotify::model::track::{FullTrack, SavedTrack, SimplifiedTrack};
use rspotify::model::album::FullAlbum;
use rspotify::model::track::{FullTrack, SavedTrack, SimplifiedTrack};
use crate::album::Album;
use crate::artist::Artist;

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
}