diff --git a/jellyfin-rpc/src/lib.rs b/jellyfin-rpc/src/lib.rs index 824a0ab..f1fe8d6 100644 --- a/jellyfin-rpc/src/lib.rs +++ b/jellyfin-rpc/src/lib.rs @@ -5,7 +5,7 @@ use discord_rich_presence::{ }; pub use error::JfError; pub use jellyfin::{Button, MediaType}; -use jellyfin::{EndTime, Item, RawSession, Session}; +use jellyfin::{EndTime, ExternalUrl, Item, RawSession, Session}; use log::debug; use reqwest::header::{HeaderMap, AUTHORIZATION}; use std::str::FromStr; @@ -245,6 +245,10 @@ impl Client { &session.now_playing_item.external_urls, self.buttons.as_ref(), ) { + let ext_urls: Vec<&ExternalUrl> = ext_urls + .iter() + .filter(|eu| !eu.url.starts_with("http://localhost") && !eu.url.starts_with("https://localhost")) + .collect(); let mut i = 0; for button in buttons { if activity_buttons.len() == 2 { @@ -252,7 +256,7 @@ impl Client { } if button.is_dynamic() { - if ext_urls.len() - 1 == i { + if ext_urls.len() > i { activity_buttons.push(Button::new( ext_urls[i].name.clone(), ext_urls[i].url.clone(), @@ -264,24 +268,28 @@ impl Client { } } return Some(activity_buttons); - } else if let Some(ext_urls) = &session.now_playing_item.external_urls { - for ext_url in ext_urls { + } else if let Some(buttons) = self.buttons.as_ref() { + for button in buttons { if activity_buttons.len() == 2 { break; } - activity_buttons.push(Button::new(ext_url.name.clone(), ext_url.url.clone())) + if !button.is_dynamic() { + activity_buttons.push(button.clone()) + } } return Some(activity_buttons); - } else if let Some(buttons) = self.buttons.as_ref() { - for button in buttons { + } else if let Some(ext_urls) = &session.now_playing_item.external_urls { + let ext_urls: Vec<&ExternalUrl> = ext_urls + .iter() + .filter(|eu| !eu.url.starts_with("http://localhost") && !eu.url.starts_with("https://localhost")) + .collect(); + for ext_url in ext_urls { if activity_buttons.len() == 2 { break; } - if !button.is_dynamic() { - activity_buttons.push(button.clone()) - } + activity_buttons.push(Button::new(ext_url.name.clone(), ext_url.url.clone())) } return Some(activity_buttons); }