Add total plays, total duration, and server friendly name to plex panel

This commit is contained in:
Tyler Perkins 2021-12-24 10:59:53 -05:00
parent 40941908fa
commit 2b3151fc7b
3 changed files with 55 additions and 3 deletions

View File

@ -21,7 +21,7 @@ plex::plex(){
_title = PLEX_TITLE; _title = PLEX_TITLE;
api_curl = curl_easy_init(); 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, curl_easy_setopt(api_curl, CURLOPT_WRITEFUNCTION,
dashboard::panel::plex::curl_callback); dashboard::panel::plex::curl_callback);
curl_easy_setopt(api_curl, CURLOPT_WRITEDATA, &json_string); curl_easy_setopt(api_curl, CURLOPT_WRITEDATA, &json_string);
@ -73,11 +73,11 @@ void plex::update(){
//fetch updates //fetch updates
//CURL object has been setup in the constructor //CURL object has been setup in the constructor
curl_easy_setopt(api_curl, CURLOPT_URL, PLEX_URL_SOURCE_HISTORY);
curl_easy_perform(api_curl); curl_easy_perform(api_curl);
//parse the result //parse the result
json_doc.Parse(json_string.c_str()); json_doc.Parse(json_string.c_str());
//entries.clear();
//update internal state //update internal state
rapidjson::Value& curr_entry = json_doc["response"]["data"]["data"]; rapidjson::Value& curr_entry = json_doc["response"]["data"]["data"];
@ -100,6 +100,22 @@ void plex::update(){
std::cerr << entries[i].state << "\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(); json_string.clear();
} }
@ -314,6 +330,38 @@ void plex::update_texture(){
NULL, &tgt); 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); SDL_SetRenderTarget(board::getRenderer(), NULL);

View File

@ -48,6 +48,9 @@ namespace dashboard::panel {
}; };
std::array<plex_entry, 4> entries; std::array<plex_entry, 4> entries;
std::string total_plays;
std::string total_duration;
std::string friendly_name;
std::chrono::time_point<std::chrono::high_resolution_clock> _last_update; std::chrono::time_point<std::chrono::high_resolution_clock> _last_update;

View File

@ -14,7 +14,8 @@ namespace dashboard::panel {
constexpr char PLEX_TITLE[] = "Plex"; constexpr char PLEX_TITLE[] = "Plex";
//Tautili endpoint //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? //How many characters of a show title should we show?
constexpr size_t PLEX_MAX_STRING_LENGTH = 35; constexpr size_t PLEX_MAX_STRING_LENGTH = 35;