Skip to content

Commit

Permalink
Fixed content that doesnt have images (#76)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Radiicall authored Oct 7, 2023
1 parent 5ed7bde commit 66050dc
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/services/jellyfin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<String, reqwest::Error> {
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<String> {
Expand Down

0 comments on commit 66050dc

Please sign in to comment.