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

Set activity type for different media #136

Merged
merged 5 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion jellyfin-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repository = "https://github.com/Radiicall/jellyfin-rpc"
keywords = ["jellyfin", "discord", "rich-presence"]

[dependencies]
discord-rich-presence = "0.2"
discord-rich-presence = { git = "https://github.com/Radiicall/discord-rich-presence" }
serde_json = "1.0"
log = "0.4"
url = "2.5"
Expand Down
25 changes: 18 additions & 7 deletions jellyfin-rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use discord_rich_presence::activity::Button as ActButton;
use discord_rich_presence::activity::{ActivityType, Button as ActButton};
use discord_rich_presence::{
activity::{Activity, Assets, Timestamps},
DiscordIpc, DiscordIpcClient,
Expand Down Expand Up @@ -173,6 +173,14 @@ impl Client {
details += "‎‎‎";
}

match session.now_playing_item.media_type {
MediaType::Book => (),
MediaType::Music | MediaType::AudioBook => {
activity = activity.activity_type(ActivityType::Listening)
}
_ => activity = activity.activity_type(ActivityType::Watching),
}

activity = activity
.timestamps(timestamps)
.assets(assets)
Expand Down Expand Up @@ -494,10 +502,10 @@ impl Client {

let ancestors: Vec<Item> = self
.reqwest
.get(self.url.join(&format!(
"Items/{}/Ancestors",
session.now_playing_item.id
))?)
.get(
self.url
.join(&format!("Items/{}/Ancestors", session.now_playing_item.id))?,
)
.send()?
.json()?;

Expand Down Expand Up @@ -796,12 +804,15 @@ impl ClientBuilder {
/// ```
pub fn build(self) -> JfResult<Client> {
if self.url.is_empty() || self.usernames.is_empty() || self.api_key.is_empty() {
return Err(Box::new(JfError::MissingRequiredValues))
return Err(Box::new(JfError::MissingRequiredValues));
}

let mut headers = HeaderMap::new();

headers.insert(AUTHORIZATION, format!("MediaBrowser Token=\"{}\"", self.api_key).parse()?);
headers.insert(
AUTHORIZATION,
format!("MediaBrowser Token=\"{}\"", self.api_key).parse()?,
);
headers.insert("X-Emby-Token", self.api_key.parse()?);

Ok(Client {
Expand Down
Loading