33
src/album.rs
33
src/album.rs
@@ -33,15 +33,32 @@ impl Album {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref album_id) = self.id {
|
if let Some(ref album_id) = self.id {
|
||||||
if let Some(fa) = spotify.full_album(&album_id) {
|
let mut collected_tracks = Vec::new();
|
||||||
self.tracks = Some(
|
if let Some(full_album) = spotify.full_album(album_id) {
|
||||||
fa.tracks
|
let mut tracks_result = Some(full_album.tracks.clone());
|
||||||
.items
|
while let Some(ref tracks) = tracks_result {
|
||||||
.iter()
|
for t in &tracks.items {
|
||||||
.map(|st| Track::from_simplified_track(&st, &fa))
|
collected_tracks.push(Track::from_simplified_track(t, &full_album));
|
||||||
.collect(),
|
}
|
||||||
);
|
|
||||||
|
debug!("got {} tracks", tracks.items.len());
|
||||||
|
|
||||||
|
// load next batch if necessary
|
||||||
|
tracks_result = match tracks.next {
|
||||||
|
Some(_) => {
|
||||||
|
debug!("requesting tracks again..");
|
||||||
|
spotify.album_tracks(
|
||||||
|
album_id,
|
||||||
|
50,
|
||||||
|
tracks.offset + tracks.items.len() as u32,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.tracks = Some(collected_tracks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use rspotify::model::artist::FullArtist;
|
|||||||
use rspotify::model::page::{CursorBasedPage, Page};
|
use rspotify::model::page::{CursorBasedPage, Page};
|
||||||
use rspotify::model::playlist::{FullPlaylist, PlaylistTrack, SimplifiedPlaylist};
|
use rspotify::model::playlist::{FullPlaylist, PlaylistTrack, SimplifiedPlaylist};
|
||||||
use rspotify::model::search::SearchResult;
|
use rspotify::model::search::SearchResult;
|
||||||
use rspotify::model::track::{FullTrack, SavedTrack};
|
use rspotify::model::track::{FullTrack, SavedTrack, SimplifiedTrack};
|
||||||
use rspotify::model::user::PrivateUser;
|
use rspotify::model::user::PrivateUser;
|
||||||
use rspotify::senum::SearchType;
|
use rspotify::senum::SearchType;
|
||||||
|
|
||||||
@@ -713,6 +713,15 @@ impl Spotify {
|
|||||||
self.api_with_retry(|api| api.album(album_id))
|
self.api_with_retry(|api| api.album(album_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn album_tracks(
|
||||||
|
&self,
|
||||||
|
album_id: &str,
|
||||||
|
limit: u32,
|
||||||
|
offset: u32,
|
||||||
|
) -> Option<Page<SimplifiedTrack>> {
|
||||||
|
self.api_with_retry(|api| api.album_track(album_id, limit, offset))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn artist_albums(
|
pub fn artist_albums(
|
||||||
&self,
|
&self,
|
||||||
artist_id: &str,
|
artist_id: &str,
|
||||||
|
|||||||
Reference in New Issue
Block a user