Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Artists Page #2

Open
wants to merge 9 commits into
base: development
Choose a base branch
from
16 changes: 11 additions & 5 deletions src/api/api_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,16 @@ trait WithImages {
}

fn best_image_for_width(&self, width: i32) -> Option<&Image> {
self.best_image(|i| (width - i.width.unwrap_or(0) as i32).abs())
// When the API does return a float, it seems to just be an integer with a .0
self.best_image(|i| (width - (i.width.unwrap_or(0.0).abs()) as i32))
}
}

#[derive(Deserialize, Debug, Clone)]
pub struct Playlist {
pub id: String,
pub name: String,
pub images: Vec<Image>,
pub images: Option<Vec<Image>>,
pub tracks: Page<PlaylistTrack>,
pub owner: PlaylistOwner,
}
Expand All @@ -199,7 +200,11 @@ pub struct PlaylistOwner {

impl WithImages for Playlist {
fn images(&self) -> &[Image] {
&self.images
if let Some(ref images) = self.images {
images
} else {
&[]
}
}
}

Expand Down Expand Up @@ -261,8 +266,9 @@ impl WithImages for Album {
#[derive(Deserialize, Debug, Clone)]
pub struct Image {
pub url: String,
pub height: Option<u32>,
pub width: Option<u32>,
// Spotify's API sometimes returns image height/width as a float instead of a integer
pub height: Option<f64>,
pub width: Option<f64>,
}

#[derive(Deserialize, Debug, Clone)]
Expand Down
1 change: 0 additions & 1 deletion src/api/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ impl SpotifyClient {
B: Into<isahc::AsyncBody>,
{
let mut result = self.client.send_async(request).await?;

let etag = result
.headers()
.get("etag")
Expand Down