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;