Implement saved tracks, albums, and artists
This commit is contained in:
19
src/album.rs
19
src/album.rs
@@ -1,7 +1,8 @@
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
|
||||
use rspotify::spotify::model::album::{FullAlbum, SimplifiedAlbum};
|
||||
use chrono::{DateTime, Utc};
|
||||
use rspotify::spotify::model::album::{FullAlbum, SavedAlbum, SimplifiedAlbum};
|
||||
|
||||
use queue::Queue;
|
||||
use spotify::Spotify;
|
||||
@@ -13,14 +14,16 @@ pub struct Album {
|
||||
pub id: String,
|
||||
pub title: String,
|
||||
pub artists: Vec<String>,
|
||||
pub artist_ids: Vec<String>,
|
||||
pub year: String,
|
||||
pub cover_url: Option<String>,
|
||||
pub url: String,
|
||||
pub tracks: Option<Vec<Track>>,
|
||||
pub added_at: Option<DateTime<Utc>>
|
||||
}
|
||||
|
||||
impl Album {
|
||||
fn load_tracks(&mut self, spotify: Arc<Spotify>) {
|
||||
pub fn load_tracks(&mut self, spotify: Arc<Spotify>) {
|
||||
if self.tracks.is_some() {
|
||||
return;
|
||||
}
|
||||
@@ -43,10 +46,12 @@ impl From<&SimplifiedAlbum> for Album {
|
||||
id: sa.id.clone(),
|
||||
title: sa.name.clone(),
|
||||
artists: sa.artists.iter().map(|sa| sa.name.clone()).collect(),
|
||||
artist_ids: sa.artists.iter().map(|sa| sa.id.clone()).collect(),
|
||||
year: sa.release_date.split('-').next().unwrap().into(),
|
||||
cover_url: sa.images.get(0).map(|i| i.url.clone()),
|
||||
url: sa.uri.clone(),
|
||||
tracks: None,
|
||||
added_at: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,14 +70,24 @@ impl From<&FullAlbum> for Album {
|
||||
id: fa.id.clone(),
|
||||
title: fa.name.clone(),
|
||||
artists: fa.artists.iter().map(|sa| sa.name.clone()).collect(),
|
||||
artist_ids: fa.artists.iter().map(|sa| sa.id.clone()).collect(),
|
||||
year: fa.release_date.split('-').next().unwrap().into(),
|
||||
cover_url: fa.images.get(0).map(|i| i.url.clone()),
|
||||
url: fa.uri.clone(),
|
||||
tracks,
|
||||
added_at: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&SavedAlbum> for Album {
|
||||
fn from(sa: &SavedAlbum) -> Self {
|
||||
let mut album: Self = (&sa.album).into();
|
||||
album.added_at = Some(sa.added_at);
|
||||
album
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Album {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{} - {}", self.artists.join(", "), self.title)
|
||||
|
||||
Reference in New Issue
Block a user