cargo fmt
This commit is contained in:
@@ -10,8 +10,8 @@ use librespot::playback::audio_backend;
|
|||||||
use librespot::playback::config::Bitrate;
|
use librespot::playback::config::Bitrate;
|
||||||
use librespot::playback::player::Player;
|
use librespot::playback::player::Player;
|
||||||
|
|
||||||
use rspotify::spotify::client::Spotify as SpotifyAPI;
|
|
||||||
use rspotify::spotify::client::ApiError;
|
use rspotify::spotify::client::ApiError;
|
||||||
|
use rspotify::spotify::client::Spotify as SpotifyAPI;
|
||||||
use rspotify::spotify::model::page::Page;
|
use rspotify::spotify::model::page::Page;
|
||||||
use rspotify::spotify::model::playlist::{PlaylistTrack, SimplifiedPlaylist};
|
use rspotify::spotify::model::playlist::{PlaylistTrack, SimplifiedPlaylist};
|
||||||
use rspotify::spotify::model::search::SearchTracks;
|
use rspotify::spotify::model::search::SearchTracks;
|
||||||
@@ -284,7 +284,9 @@ impl Spotify {
|
|||||||
|
|
||||||
/// retries once when rate limits are hit
|
/// retries once when rate limits are hit
|
||||||
fn api_with_retry<F, R>(&self, cb: F) -> Option<R>
|
fn api_with_retry<F, R>(&self, cb: F) -> Option<R>
|
||||||
where F: Fn(&SpotifyAPI) -> Result<R, Error> {
|
where
|
||||||
|
F: Fn(&SpotifyAPI) -> Result<R, Error>,
|
||||||
|
{
|
||||||
match cb(&self.api) {
|
match cb(&self.api) {
|
||||||
Ok(v) => Some(v),
|
Ok(v) => Some(v),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -294,17 +296,19 @@ impl Spotify {
|
|||||||
debug!("rate limit hit. waiting {:?} seconds", d);
|
debug!("rate limit hit. waiting {:?} seconds", d);
|
||||||
thread::sleep(Duration::from_secs(d.unwrap_or(0) as u64));
|
thread::sleep(Duration::from_secs(d.unwrap_or(0) as u64));
|
||||||
cb(&self.api).ok()
|
cb(&self.api).ok()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
else { None }
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
else { None }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn search(&self, query: &str, limit: u32, offset: u32) -> Option<SearchTracks> {
|
pub fn search(&self, query: &str, limit: u32, offset: u32) -> Option<SearchTracks> {
|
||||||
//let res = self.api.search_track(query, limit, offset, None);
|
//let res = self.api.search_track(query, limit, offset, None);
|
||||||
self.api_with_retry(|api| api.search_track(query, limit, offset, None) )
|
self.api_with_retry(|api| api.search_track(query, limit, offset, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_user_playlist(
|
pub fn current_user_playlist(
|
||||||
@@ -312,7 +316,7 @@ impl Spotify {
|
|||||||
limit: u32,
|
limit: u32,
|
||||||
offset: u32,
|
offset: u32,
|
||||||
) -> Option<Page<SimplifiedPlaylist>> {
|
) -> Option<Page<SimplifiedPlaylist>> {
|
||||||
self.api_with_retry(|api| api.current_user_playlists(limit, offset) )
|
self.api_with_retry(|api| api.current_user_playlists(limit, offset))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn user_playlist_tracks(
|
pub fn user_playlist_tracks(
|
||||||
@@ -321,8 +325,9 @@ impl Spotify {
|
|||||||
limit: u32,
|
limit: u32,
|
||||||
offset: u32,
|
offset: u32,
|
||||||
) -> Option<Page<PlaylistTrack>> {
|
) -> Option<Page<PlaylistTrack>> {
|
||||||
self.api_with_retry(|api| api
|
self.api_with_retry(|api| {
|
||||||
.user_playlist_tracks(&self.user, playlist_id, None, limit, offset, None))
|
api.user_playlist_tracks(&self.user, playlist_id, None, limit, offset, None)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(&self, track: &Track) {
|
pub fn load(&self, track: &Track) {
|
||||||
|
|||||||
Reference in New Issue
Block a user