Add top uers to plex panel

This commit is contained in:
Tyler Perkins 2021-12-24 12:27:08 -05:00
parent 2b3151fc7b
commit a8d32cef40
3 changed files with 37 additions and 1 deletions

View File

@ -109,11 +109,25 @@ void plex::update(){
json_string.clear();
//make request for top users
curl_easy_setopt(api_curl, CURLOPT_URL, PLEX_URL_SOURCE_TOP_USERS);
curl_easy_perform(api_curl);
json_doc.Parse(json_string.c_str());
curr_entry = json_doc["response"]["data"]["categories"];
for(rapidjson::SizeType i = 0; i < curr_entry.Size(); i++){
top_users[i] = truncate(curr_entry[i].GetString(), 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();
@ -359,6 +373,26 @@ void plex::update_texture(){
board::getString(total_duration,
{"Roboto_Mono/RobotoMono-Medium.ttf", 28}),
NULL, &tgt);
//draw the top users
tgt.y += tgt.h;
TTF_SizeText(board::getFont( {"Roboto_Mono/RobotoMono-Medium.ttf", 50} ),
"Top Users",
&tgt.w, &tgt.h);
SDL_RenderCopy(board::getRenderer(),
board::getString("Top Users",
{"Roboto_Mono/RobotoMono-Medium.ttf", 50}),
NULL, &tgt);
for(unsigned short i = 0; i < top_users.size(); ++i){
tgt.y += tgt.h;
TTF_SizeText(board::getFont( {"Roboto_Mono/RobotoMono-Medium.ttf", 28} ),
top_users[i].c_str(),
&tgt.w, &tgt.h);
SDL_RenderCopy(board::getRenderer(),
board::getString(top_users[i],
{"Roboto_Mono/RobotoMono-Medium.ttf", 28}),
NULL, &tgt);
}
}

View File

@ -48,6 +48,7 @@ namespace dashboard::panel {
};
std::array<plex_entry, 4> entries;
std::array<std::string, 10> top_users;
std::string total_plays;
std::string total_duration;
std::string friendly_name;

View File

@ -16,6 +16,7 @@ namespace dashboard::panel {
//Tautili endpoint
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";
constexpr char PLEX_URL_SOURCE_TOP_USERS[] = "http://192.168.1.104:8181/api/v2?apikey=64af06e0497342f7a5862462ddbbd309&cmd=get_plays_by_top_10_users";
//How many characters of a show title should we show?
constexpr size_t PLEX_MAX_STRING_LENGTH = 35;