Skip to content

Commit

Permalink
feat: support for trakt and imdb link buttons (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsojramos authored Feb 7, 2022
1 parent d30d9f7 commit 26e4ac8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "discrakt"
version = "2.0.0"
version = "2.1.0"
edition = "2021"
authors = ["afonsojramos"]
description = "Easy to Use Trakt/Plex Discord Rich Presence"
Expand Down
22 changes: 20 additions & 2 deletions src/discord.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use chrono::{DateTime, SecondsFormat, Utc};
use discord_rich_presence::{
activity::{Activity, Assets, Timestamps},
activity::{Activity, Assets, Button, Timestamps},
new_client, DiscordIpc,
};
use std::{thread::sleep, time::Duration};
Expand All @@ -27,6 +27,8 @@ pub fn set_activity(discord_client: &mut impl DiscordIpc, trakt_response: &Trakt
let details;
let state;
let media;
let link_imdb;
let link_trakt;
let start_date = DateTime::parse_from_rfc3339(&trakt_response.started_at).unwrap();
let end_date = DateTime::parse_from_rfc3339(&trakt_response.expires_at).unwrap();
let now = Utc::now();
Expand All @@ -40,13 +42,25 @@ pub fn set_activity(discord_client: &mut impl DiscordIpc, trakt_response: &Trakt
details = movie.title.to_string();
state = movie.year.to_string();
media = "movies";
link_imdb = format!("https://www.imdb.com/title/{}", movie.ids.imdb);
link_trakt = format!(
"https://trakt.tv/{}/{}",
media,
movie.ids.slug.as_ref().unwrap().to_string()
);
}
"episode" if trakt_response.episode.is_some() => {
let episode = trakt_response.episode.as_ref().unwrap();
let show = trakt_response.show.as_ref().unwrap();
details = show.title.to_string();
state = format!("S{}E{} - {}", episode.season, episode.number, episode.title);
media = "shows";
link_imdb = format!("https://www.imdb.com/title/{}", show.ids.imdb);
link_trakt = format!(
"https://trakt.tv/{}/{}",
media,
show.ids.slug.as_ref().unwrap().to_string()
);
}
_ => {
println!("Unknown media type: {}", trakt_response.r#type);
Expand Down Expand Up @@ -76,7 +90,11 @@ pub fn set_activity(discord_client: &mut impl DiscordIpc, trakt_response: &Trakt
Timestamps::new()
.start(start_date.timestamp())
.end(end_date.timestamp()),
);
)
.buttons(vec![
Button::new("IMDB", &link_imdb),
Button::new("Trakt", &link_trakt),
]);

if discord_client.set_activity(payload).is_err() && discord_client.reconnect().is_ok() {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/trakt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct TraktIds {
pub trakt: u32,
pub slug: Option<String>,
pub tvdb: Option<u32>,
pub imdb: Option<String>,
pub imdb: String,
pub tmdb: Option<u32>,
pub tvrage: Option<String>,
}
Expand Down

0 comments on commit 26e4ac8

Please sign in to comment.