From 2b3151fc7bf617a1f6bf19214a6ab6a5945eec44 Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Fri, 24 Dec 2021 10:59:53 -0500 Subject: [PATCH] Add total plays, total duration, and server friendly name to plex panel --- src/panel/plex.cpp | 52 +++++++++++++++++++++++++++++++++++++-- src/panel/plex.hpp | 3 +++ src/panel/plex_config.hpp | 3 ++- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/panel/plex.cpp b/src/panel/plex.cpp index 682b863..e25a180 100644 --- a/src/panel/plex.cpp +++ b/src/panel/plex.cpp @@ -21,7 +21,7 @@ plex::plex(){ _title = PLEX_TITLE; api_curl = curl_easy_init(); - curl_easy_setopt(api_curl, CURLOPT_URL, PLEX_URL_SOURCE); + curl_easy_setopt(api_curl, CURLOPT_URL, PLEX_URL_SOURCE_HISTORY); curl_easy_setopt(api_curl, CURLOPT_WRITEFUNCTION, dashboard::panel::plex::curl_callback); curl_easy_setopt(api_curl, CURLOPT_WRITEDATA, &json_string); @@ -73,11 +73,11 @@ void plex::update(){ //fetch updates //CURL object has been setup in the constructor + curl_easy_setopt(api_curl, CURLOPT_URL, PLEX_URL_SOURCE_HISTORY); curl_easy_perform(api_curl); //parse the result json_doc.Parse(json_string.c_str()); - //entries.clear(); //update internal state rapidjson::Value& curr_entry = json_doc["response"]["data"]["data"]; @@ -99,6 +99,22 @@ void plex::update(){ std::cerr << entries[i].title << "\n"; std::cerr << entries[i].state << "\n"; } + + //get misc entries for right hand bar + total_plays = std::to_string(json_doc["response"]["data"]["recordsTotal"] + .GetInt()); + total_plays = truncate("Plays: " + total_plays, PLEX_MAX_STRING_LENGTH); + total_duration = json_doc["response"]["data"]["total_duration"].GetString(); + total_duration = truncate("Duration: " + total_duration, PLEX_MAX_STRING_LENGTH); + + json_string.clear(); + + //make request for friendly server name + curl_easy_setopt(api_curl, CURLOPT_URL, PLEX_URL_SOURCE_NAME); + curl_easy_perform(api_curl); + + json_doc.Parse(json_string.c_str()); + friendly_name = truncate(json_doc["response"]["data"].GetString(), PLEX_MAX_STRING_LENGTH - 10); json_string.clear(); } @@ -314,6 +330,38 @@ void plex::update_texture(){ NULL, &tgt); } + //draw info for right hand side box + { + tgt.x = ((2*SCREEN_WIDTH) / 3) + GAP_SIZE; + tgt.y = DEF_OVERLAY_BAR_HEIGHT + GAP_SIZE; + TTF_SizeText(board::getFont( {"Roboto_Mono/RobotoMono-Medium.ttf", 50} ), + friendly_name.c_str(), + &tgt.w, &tgt.h); + SDL_RenderCopy(board::getRenderer(), + board::getString(friendly_name, + {"Roboto_Mono/RobotoMono-Medium.ttf", 50}), + NULL, &tgt); + + tgt.y += tgt.h; + TTF_SizeText(board::getFont( {"Roboto_Mono/RobotoMono-Medium.ttf", 28} ), + total_plays.c_str(), + &tgt.w, &tgt.h); + SDL_RenderCopy(board::getRenderer(), + board::getString(total_plays, + {"Roboto_Mono/RobotoMono-Medium.ttf", 28}), + NULL, &tgt); + + tgt.y += tgt.h; + TTF_SizeText(board::getFont( {"Roboto_Mono/RobotoMono-Medium.ttf", 28} ), + total_duration.c_str(), + &tgt.w, &tgt.h); + SDL_RenderCopy(board::getRenderer(), + board::getString(total_duration, + {"Roboto_Mono/RobotoMono-Medium.ttf", 28}), + NULL, &tgt); + } + + SDL_SetRenderTarget(board::getRenderer(), NULL); diff --git a/src/panel/plex.hpp b/src/panel/plex.hpp index 09c4f46..b5a8c5f 100644 --- a/src/panel/plex.hpp +++ b/src/panel/plex.hpp @@ -48,6 +48,9 @@ namespace dashboard::panel { }; std::array entries; + std::string total_plays; + std::string total_duration; + std::string friendly_name; std::chrono::time_point _last_update; diff --git a/src/panel/plex_config.hpp b/src/panel/plex_config.hpp index 0c5ee6d..a0f8e41 100644 --- a/src/panel/plex_config.hpp +++ b/src/panel/plex_config.hpp @@ -14,7 +14,8 @@ namespace dashboard::panel { constexpr char PLEX_TITLE[] = "Plex"; //Tautili endpoint - constexpr char PLEX_URL_SOURCE[] = "http://192.168.1.104:8181/api/v2?apikey=64af06e0497342f7a5862462ddbbd309&cmd=get_history&length=5"; + constexpr char PLEX_URL_SOURCE_HISTORY[] = "http://192.168.1.104:8181/api/v2?apikey=64af06e0497342f7a5862462ddbbd309&cmd=get_history&length=5"; + constexpr char PLEX_URL_SOURCE_NAME[] = "http://192.168.1.104:8181/api/v2?apikey=64af06e0497342f7a5862462ddbbd309&cmd=get_server_friendly_name"; //How many characters of a show title should we show? constexpr size_t PLEX_MAX_STRING_LENGTH = 35;