From 9346fb6b18a3ec92a17267af04dd9277acde8eae Mon Sep 17 00:00:00 2001 From: Dominik Hrinkino Date: Mon, 30 Aug 2021 19:59:33 +0200 Subject: [PATCH] Added timer to discord presence, added Season and Episode number to presence and little ascii playback symbol --- Plex Discord Presence/Form1.cs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Plex Discord Presence/Form1.cs b/Plex Discord Presence/Form1.cs index 0728a9a..524f904 100644 --- a/Plex Discord Presence/Form1.cs +++ b/Plex Discord Presence/Form1.cs @@ -20,6 +20,8 @@ public partial class Form1 : Form private DiscordRpcClient client; private int tick = 0; private bool status = false; + private dynamic now = DateTime.UtcNow; + private bool detected = false; public Form1() { InitializeComponent(); @@ -94,14 +96,22 @@ private bool GetPlexData() string text_second = null; if (stuff["MediaContainer"]["@size"] > 1) { + if (detected == false) + { + // setting new datetime + now = DateTime.UtcNow; + detected = !detected; + } + if (stuff["MediaContainer"]["Video"][0]["@type"] == "movie") { - text = stuff["MediaContainer"]["Video"][0]["@title"]; + text = "▶ " + stuff["MediaContainer"]["Video"][0]["@title"]; } else { - text = stuff["MediaContainer"]["Video"][0]["@grandparentTitle"] + " " + stuff["MediaContainer"]["Video"][0]["@title"]; + text = "▶ " + stuff["MediaContainer"]["Video"][0]["@grandparentTitle"]; + text_second = "S" + int.Parse(stuff["MediaContainer"][0]["Video"]["@parentIndex"].ToString()).ToString("00") + "E" + int.Parse(stuff["MediaContainer"]["Video"][0]["@index"].ToString()).ToString("00") + " " + stuff["MediaContainer"]["Video"][0]["@title"]; } } @@ -109,14 +119,17 @@ private bool GetPlexData() { if (stuff["MediaContainer"]["Video"]["@type"] == "movie") { - text = stuff["MediaContainer"]["Video"]["@title"]; + // Movie + text = "▶ " + stuff["MediaContainer"]["Video"]["@title"]; text_second = ""; } else { - text = stuff["MediaContainer"]["Video"]["@grandparentTitle"]; - text_second = stuff["MediaContainer"]["Video"]["@title"]; + + // TV Show + text = "▶ " + stuff["MediaContainer"]["Video"]["@grandparentTitle"]; + text_second = "S"+ int.Parse(stuff["MediaContainer"]["Video"]["@parentIndex"].ToString()).ToString("00") + "E" + int.Parse(stuff["MediaContainer"]["Video"]["@index"].ToString()).ToString("00") + " "+ stuff["MediaContainer"]["Video"]["@title"]; } } @@ -134,9 +147,11 @@ private bool GetPlexData() } else { + detected = false; label1.Text = "Nothing Playing"; label5.Text = ""; client.ClearPresence(); + now = DateTime.UtcNow; } return true; @@ -148,8 +163,10 @@ private void UpdatePresence(string Details, string State,Assets PlexData) { Details = Details, State = State, - Assets = PlexData + Assets = PlexData, + Timestamps = new Timestamps(now) }); + } private void Form1_Load(object sender, EventArgs e) @@ -174,6 +191,7 @@ private void button1_Click_1(object sender, EventArgs e) else { timer1.Stop(); + detected = false; client.ClearPresence(); status = !status; button1.Text = "Run";