From 66050dc88030e17345cf812a5832960014294d20 Mon Sep 17 00:00:00 2001 From: Radical Date: Sat, 7 Oct 2023 21:45:42 +0200 Subject: [PATCH] Fixed content that doesnt have images (#76) Before it would just break and try to display the image anyways, now it checks if the URL is returning an image or just some text before it tries displaying it. --- src/services/jellyfin.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/services/jellyfin.rs b/src/services/jellyfin.rs index 3f90496..b49e197 100644 --- a/src/services/jellyfin.rs +++ b/src/services/jellyfin.rs @@ -140,7 +140,7 @@ impl Content { .and_then(|images| images.enable_images) .unwrap_or(false) { - image_url = Content::image(&config.jellyfin.url, content.item_id.clone()).await; + image_url = Content::image(&config.jellyfin.url, content.item_id.clone()).await.unwrap_or(String::from("")); } content.external_services(ExternalServices::get(now_playing_item).await); @@ -354,12 +354,18 @@ impl Content { state } - async fn image(url: &str, item_id: String) -> String { - format!( + async fn image(url: &str, item_id: String) -> Result { + let img = format!( "{}/Items/{}/Images/Primary", url.trim_end_matches('/'), item_id - ) + ); + + if reqwest::get(&img).await?.text().await.unwrap_or(String::from("_")).contains("does not have an image of type Primary") { + Ok(String::from("")) + } else { + Ok(img) + } } fn get_genres(npi: &Value) -> Option {