From e73486acd2a09cb8f0eb7af9377561dd148e877b Mon Sep 17 00:00:00 2001 From: Radical Date: Mon, 26 Aug 2024 09:02:27 +0000 Subject: [PATCH 1/2] Check if url returns an image --- jellyfin-rpc/src/error.rs | 2 ++ jellyfin-rpc/src/lib.rs | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/jellyfin-rpc/src/error.rs b/jellyfin-rpc/src/error.rs index e1cb929..3f9f036 100644 --- a/jellyfin-rpc/src/error.rs +++ b/jellyfin-rpc/src/error.rs @@ -9,6 +9,7 @@ pub enum JfError { /// Content is in blacklist ContentBlacklist, MissingRequiredValues, + NoImage, } impl Error for JfError {} @@ -19,6 +20,7 @@ impl Display for JfError { JfError::MissingRequiredValues => write!(f, "missing required values to build client"), JfError::UnrecognizedMediaType => write!(f, "unrecognized media type"), JfError::ContentBlacklist => write!(f, "content is blacklisted"), + JfError::NoImage => write!(f, "media does not have an image"), } } } diff --git a/jellyfin-rpc/src/lib.rs b/jellyfin-rpc/src/lib.rs index 537423b..0675c8f 100644 --- a/jellyfin-rpc/src/lib.rs +++ b/jellyfin-rpc/src/lib.rs @@ -288,12 +288,21 @@ impl Client { None } - fn get_image(&self) -> Result { + fn get_image(&self) -> JfResult { let session = self.session.as_ref().unwrap(); let path = "Items/".to_string() + &session.item_id + "/Images/Primary"; - self.url.join(&path) + let image_url = self.url.join(&path)?; + + if self.reqwest.get(image_url.as_ref()) + .send()? + .text()? + .contains("does not have an image of type Primary") { + Err(Box::new(JfError::NoImage)) + } else { + Ok(image_url) + } } fn get_state(&self) -> String { From 4424083cf13bf67c8ff7c67ea5689901a8b6626d Mon Sep 17 00:00:00 2001 From: Radical Date: Fri, 30 Aug 2024 22:19:40 +0000 Subject: [PATCH 2/2] Remove unneeded import --- jellyfin-rpc/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jellyfin-rpc/src/lib.rs b/jellyfin-rpc/src/lib.rs index 0675c8f..824a0ab 100644 --- a/jellyfin-rpc/src/lib.rs +++ b/jellyfin-rpc/src/lib.rs @@ -9,7 +9,7 @@ use jellyfin::{EndTime, Item, RawSession, Session}; use log::debug; use reqwest::header::{HeaderMap, AUTHORIZATION}; use std::str::FromStr; -use url::{ParseError, Url}; +use url::Url; mod error; mod external;