mirror of
https://github.com/aunefyren/wrapperr
synced 2024-12-14 13:22:26 +00:00
Caching back as loop-page, more stats
This commit is contained in:
parent
05ffbc274a
commit
00f1bd48e3
6 changed files with 593 additions and 116 deletions
10
admin.js
10
admin.js
|
@ -143,7 +143,7 @@ function set_tautulli(back) {
|
|||
html += '</div>';
|
||||
|
||||
html += '<div class="form-group">';
|
||||
html += '<label for="tautulli_ip" title="The IP address or domain that connects to Tautulli. No subfolders as this is another setting, but subdomains can be defined.">IP or domain for Tautulli connection</label>';
|
||||
html += '<label for="tautulli_ip" title="The IP address or domain that connects to Tautulli. No subfolders, as this is another setting, but subdomains can be defined.">IP or domain for Tautulli connection</label>';
|
||||
html += '<input type="text" class="form-control" id="tautulli_ip" value="' + tautulli_ip + '" required placeholder="mycooldomain.plex" /><br>';
|
||||
html += '</div>';
|
||||
|
||||
|
@ -153,7 +153,7 @@ function set_tautulli(back) {
|
|||
html += '</div>';
|
||||
|
||||
html += '<div class="form-group">';
|
||||
html += '<label for="tautulli_length" title="The max amount of entries Tautulli responds with during API calls. Typically doesn\'t need to be changed, but with server-wide stats it could limit results if the amount of entries in your Tautulli is extreme.">Tautlli item length</label>';
|
||||
html += '<label for="tautulli_length" title="The max amount of entries Tautulli responds with during API calls. Typically doesn\'t need to be changed, but if you have more than 5000 entries in a day, they won\'t be loaded.">Tautlli item length</label>';
|
||||
html += '<input type="number" min="0" class="form-control" id="tautulli_length" value="' + tautulli_length + '" autocomplete="off" placeholder="5000" required /><br>';
|
||||
html += '</div>';
|
||||
|
||||
|
@ -168,7 +168,7 @@ function set_tautulli(back) {
|
|||
html += '</div>';
|
||||
|
||||
html += '<div class="form-group">';
|
||||
html += '<label for="ssl" title="Enable if your connection uses HTTPS.">Use SSL</label>';
|
||||
html += '<label for="ssl" title="Enable if your connection uses HTTPS or HTTP.">Use HTTPS</label>';
|
||||
html += '<input type="checkbox" class="form-control" id="ssl" ';
|
||||
if(ssl) {
|
||||
html += 'checked="' + ssl + '" ';
|
||||
|
@ -219,6 +219,7 @@ function set_tautulli_details(back) {
|
|||
var temp_date_first = temp_date[0].split('/');
|
||||
var temp_date_second = temp_date[1].split(':');
|
||||
html += '<div class="form-group">';
|
||||
html += '<div class="warning">!<br>Load time for long wrapped periods are extensive. Consider enabling caching and performing pre-caching once.</div>';
|
||||
html += '<label for="wrapped_start" title="The start of the period you want wrapped.">Start of wrapped period</label>';
|
||||
html += '<input type="datetime-local" class="form-control" id="wrapped_start" value="' + temp_date_first[2].trim() + '-' + temp_date_first[1].trim() + '-' + temp_date_first[0].trim() + 'T' + temp_date_second[0].trim() + ':' + temp_date_second[1].trim() + '" required /><br>';
|
||||
html += '</div>';
|
||||
|
@ -326,8 +327,9 @@ function set_tautulli_details(back) {
|
|||
}
|
||||
html += '/><br>';
|
||||
html += '</div>';
|
||||
|
||||
|
||||
html += '<div class="form-group">';
|
||||
html += '<div class="warning">!<br>If your wrapped period is long and no results are cached, the wait time can be extensive. Using the cache feature and pre-caching once is recommended.</div>';
|
||||
html += '<label for="use_cache" title="Caches your results in cache.json for later use.">Cache results for later use<br>';
|
||||
html += '<input type="checkbox" class="form-control" id="use_cache" ';
|
||||
if(use_cache) {
|
||||
|
|
|
@ -25,16 +25,88 @@ date_default_timezone_set($config->timezone);
|
|||
//Base-URL for connections
|
||||
$connection = create_url();
|
||||
|
||||
//Declare given email
|
||||
//Declare given inputs
|
||||
if(!empty($data)){
|
||||
$p_identity = htmlspecialchars(trim($data->p_identity));
|
||||
} else if(isset($_GET["p_identity"])) {
|
||||
$caching = htmlspecialchars(trim($data->caching));
|
||||
} else if(isset($_GET["p_identity"]) && isset($_GET["caching"])) {
|
||||
$p_identity = htmlspecialchars(trim($_GET["p_identity"]));
|
||||
$caching = htmlspecialchars(trim($_GET["caching"]));
|
||||
} else {
|
||||
echo json_encode(array("message" => "No input provided.", "error" => true));
|
||||
echo json_encode(array("message" => "Input error.", "error" => true));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if($caching == "False" || $caching == "false") {
|
||||
$caching = False;
|
||||
} else if($caching == "True" || $caching == "true") {
|
||||
$caching = True;
|
||||
} else {
|
||||
echo json_encode(array("message" => "Can't parse caching parameter.", "error" => true));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Confirm input variables
|
||||
if($caching) {
|
||||
if(!empty($data->cache_limit)) {
|
||||
$cache_limit = htmlspecialchars(trim($data->cache_limit));
|
||||
} else if(isset($_GET["cache_limit"])) {
|
||||
$cache_limit = htmlspecialchars(trim($_GET["cache_limit"]));
|
||||
} else {
|
||||
echo json_encode(array("message" => "No cache_limit input.", "error" => true));
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
// IF CACHING IS TRUE DO THIS
|
||||
if($caching) {
|
||||
$id = "Caching mode";
|
||||
log_activity($id, "Caching mode enabled");
|
||||
|
||||
if(!$config->use_cache) {
|
||||
echo json_encode(array("message" => "Caching is disabled.", "error" => true));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Log checking cache
|
||||
log_activity($id, "Starting cache loop");
|
||||
|
||||
|
||||
// Log checking cache
|
||||
log_activity($id, "Checking data-cache");
|
||||
|
||||
// GET WRAPPED DATES CACHE
|
||||
if($config->use_cache) {
|
||||
if($cache = check_cache()) {
|
||||
$tautulli_data = $cache;
|
||||
} else {
|
||||
$tautulli_data = array();
|
||||
}
|
||||
} else {
|
||||
$tautulli_data = array();
|
||||
}
|
||||
|
||||
// Log refresh cache
|
||||
log_activity($id, "Refreshing data-cache of missing/incomplete days, maximum " . $cache_limit . " days");
|
||||
|
||||
// REFRESH THE CACHE
|
||||
$tautulli_data = tautulli_get_wrapped_dates($id, $tautulli_data, $cache_limit);
|
||||
$complete_date_loop = $tautulli_data["complete"];
|
||||
$tautulli_data = $tautulli_data["data"];
|
||||
|
||||
// Log updating cache
|
||||
log_activity($id, "Saving data-cache");
|
||||
|
||||
// SAVE WRAPPED DATES CACHE
|
||||
if($config->use_cache) {
|
||||
update_cache($tautulli_data);
|
||||
}
|
||||
|
||||
echo json_encode(array("message" => "Caching complete.", "caching_complete" => $complete_date_loop, "error" => False));
|
||||
exit(0);
|
||||
|
||||
}
|
||||
|
||||
// Get user ID
|
||||
$id = tautulli_get_user($p_identity);
|
||||
if (!$id) {
|
||||
|
@ -67,10 +139,11 @@ if($config->use_cache) {
|
|||
}
|
||||
|
||||
// Log refresh cache
|
||||
log_activity($id, "Refreshing data-cache");
|
||||
log_activity($id, "Refreshing data-cache of missing/incomplete days");
|
||||
|
||||
// REFRESH THE CACHE
|
||||
$tautulli_data = tautulli_get_wrapped_dates($id, $tautulli_data);
|
||||
$tautulli_data = tautulli_get_wrapped_dates($id, $tautulli_data, False);
|
||||
$tautulli_data = $tautulli_data["data"];
|
||||
|
||||
// Log updating cache
|
||||
log_activity($id, "Saving data-cache");
|
||||
|
@ -84,7 +157,7 @@ if($config->use_cache) {
|
|||
log_activity($id, "Creating wrapped data");
|
||||
|
||||
// NEW LOOP USER-STATS
|
||||
if($config->get_user_movie_stats || $config->get_user_show_stats || $config->get_user_music_stats || $config->get_year_stats_movies) {
|
||||
if($config->get_user_movie_stats || $config->get_user_show_stats || $config->get_user_music_stats || $config->get_year_stats_movies || $config->get_year_stats_shows || $config->get_year_stats_music) {
|
||||
$user_stats = data_get_user_stats_loop($id, $tautulli_data);
|
||||
|
||||
if($config->get_user_movie_stats) {
|
||||
|
@ -139,7 +212,14 @@ if($config->get_user_movie_stats || $config->get_user_show_stats || $config->get
|
|||
$year_users = array("error" => True, "message" => "Disabled in config.");
|
||||
}
|
||||
|
||||
$user_shows["data"] = $user_shows["data"] + array("show_buddy" => array("message" => "Disabled in config.", "error" => True));
|
||||
if($config->get_year_stats_shows && $config->get_user_show_buddy && count($user_shows["data"]["shows"]) > 0) {
|
||||
log_activity($id, "Getting show buddy");
|
||||
//print_r($tautulli_data);
|
||||
//exit();
|
||||
$user_shows["data"] = $user_shows["data"] + array("show_buddy" => data_get_user_show_buddy($id, $user_shows["data"]["shows"][0]["title"], $tautulli_data));
|
||||
} else {
|
||||
$user_shows["data"] = $user_shows["data"] + array("show_buddy" => array("message" => "Disabled in config.", "error" => True));
|
||||
}
|
||||
|
||||
$now = new DateTime('NOW');
|
||||
|
||||
|
@ -300,7 +380,7 @@ function log_activity($id, $message) {
|
|||
return True;
|
||||
}
|
||||
|
||||
function tautulli_get_wrapped_dates($id, $array) {
|
||||
function tautulli_get_wrapped_dates($id, $array, $loop_interval) {
|
||||
|
||||
$time_start = microtime(true);
|
||||
|
||||
|
@ -309,6 +389,12 @@ function tautulli_get_wrapped_dates($id, $array) {
|
|||
global $arrContextOptions;
|
||||
|
||||
$end_loop_date = $config->wrapped_end;
|
||||
|
||||
if($loop_interval == 0) {
|
||||
$loop_interval = False;
|
||||
}
|
||||
|
||||
$complete_date_loop = True;
|
||||
|
||||
for ($loop_time = $config->wrapped_start; $loop_time <= $end_loop_date; $loop_time += 86400) {
|
||||
|
||||
|
@ -346,8 +432,9 @@ function tautulli_get_wrapped_dates($id, $array) {
|
|||
$temp_clean = array();
|
||||
for($j = 0; $j < count($temp); $j++) {
|
||||
if($temp[$j]["media_type"] == "movie" || $temp[$j]["media_type"] == "episode" || $temp[$j]["media_type"] == "track") {
|
||||
array_push($temp_clean, $temp[$j]);
|
||||
}
|
||||
$temp2 = array("date" => $temp[$j]["date"], "duration" => $temp[$j]["duration"], "friendly_name" => $temp[$j]["friendly_name"], "full_title" => $temp[$j]["full_title"], "grandparent_rating_key" => $temp[$j]["grandparent_rating_key"], "grandparent_title" => $temp[$j]["grandparent_title"], "original_title" => $temp[$j]["original_title"], "media_type" => $temp[$j]["media_type"], "parent_rating_key" => $temp[$j]["parent_rating_key"], "parent_title" => $temp[$j]["parent_title"], "paused_counter" => $temp[$j]["paused_counter"], "percent_complete" => $temp[$j]["percent_complete"], "rating_key" => $temp[$j]["rating_key"], "title" => $temp[$j]["title"], "user" => $temp[$j]["user"], "user_id" => $temp[$j]["user_id"], "year" => $temp[$j]["year"]);
|
||||
array_push($temp_clean, $temp2);
|
||||
}
|
||||
}
|
||||
|
||||
if($now->format('Y-m-d') == $then->format('Y-m-d')) {
|
||||
|
@ -361,8 +448,15 @@ function tautulli_get_wrapped_dates($id, $array) {
|
|||
} else {
|
||||
array_push($array, array("date" => $current_loop_date, "data" => $temp_clean, "complete" => $complete));
|
||||
}
|
||||
|
||||
if($loop_interval > 0) {
|
||||
$loop_interval -= 1;
|
||||
} else if($loop_interval === 0) {
|
||||
$complete_date_loop = False;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Sort data by date
|
||||
$date = array_column($array, 'date');
|
||||
array_multisort($date, SORT_ASC, $array);
|
||||
|
@ -370,8 +464,8 @@ function tautulli_get_wrapped_dates($id, $array) {
|
|||
$time_end = microtime(true);
|
||||
$execution_time = ($time_end - $time_start);
|
||||
log_activity($id, 'Refresh execution: '.$execution_time.' Seconds');
|
||||
|
||||
return $array;
|
||||
|
||||
return array("data" => $array, "complete" => $complete_date_loop);
|
||||
}
|
||||
|
||||
function data_get_user_stats_loop($id, $array) {
|
||||
|
@ -385,6 +479,7 @@ function data_get_user_stats_loop($id, $array) {
|
|||
$movies = array();
|
||||
$movies_percent_complete = array();
|
||||
$shows = array();
|
||||
$episodes = array();
|
||||
$tracks = array();
|
||||
|
||||
$year_movies = array();
|
||||
|
@ -407,15 +502,18 @@ function data_get_user_stats_loop($id, $array) {
|
|||
|
||||
$duration = $array[$i]["data"][$d]["duration"];
|
||||
$percent_complete = $array[$i]["data"][$d]["percent_complete"];
|
||||
|
||||
if($duration > 300) {
|
||||
array_push($movies_percent_complete, $percent_complete);
|
||||
}
|
||||
|
||||
$title = $array[$i]["data"][$d]["full_title"];
|
||||
$year = $array[$i]["data"][$d]["year"];
|
||||
$percent_complete = $array[$i]["data"][$d]["percent_complete"];
|
||||
$paused_counter = $array[$i]["data"][$d]["paused_counter"];
|
||||
|
||||
if($year == "") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if($duration > 300) {
|
||||
array_push($movies_percent_complete, $percent_complete);
|
||||
}
|
||||
|
||||
$found = False;
|
||||
|
||||
|
@ -443,21 +541,38 @@ function data_get_user_stats_loop($id, $array) {
|
|||
}
|
||||
|
||||
$title = $array[$i]["data"][$d]["grandparent_title"];
|
||||
$episode_title = $array[$i]["data"][$d]["title"];
|
||||
$season_title = $array[$i]["data"][$d]["parent_title"];
|
||||
$duration = $array[$i]["data"][$d]["duration"];
|
||||
$found = False;
|
||||
$show_found = False;
|
||||
$episode_found = False;
|
||||
|
||||
for ($j = 0; $j < count($shows); $j++) {
|
||||
if($shows[$j]["title"] == $title) {
|
||||
$shows[$j]["duration"] = intval($shows[$j]["duration"]) + intval($duration);
|
||||
$shows[$j]["plays"] = intval($shows[$j]["plays"]) + 1;
|
||||
$found = True;
|
||||
$show_found = True;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for ($j = 0; $j < count($episodes); $j++) {
|
||||
if($episodes[$j]["grandparent_title"] == $title && $episodes[$j]["parent_title"] == $season_title && $episodes[$j]["title"] == $episode_title) {
|
||||
$episodes[$j]["duration"] = intval($episodes[$j]["duration"]) + intval($duration);
|
||||
$episodes[$j]["plays"] = intval($episodes[$j]["plays"]) + 1;
|
||||
$episode_found = True;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$found) {
|
||||
if(!$show_found) {
|
||||
array_push($shows, array("title" => $title, "duration" => $duration, "plays" => 1));
|
||||
}
|
||||
|
||||
if(!$episode_found) {
|
||||
array_push($episodes, array("title" => $episode_title, "parent_title" => $season_title, "grandparent_title" => $title, "duration" => $duration, "plays" => 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -510,6 +625,10 @@ function data_get_user_stats_loop($id, $array) {
|
|||
$user = $array[$i]["data"][$d]["friendly_name"];
|
||||
$user_id = $array[$i]["data"][$d]["user_id"];
|
||||
$year = $array[$i]["data"][$d]["year"];
|
||||
|
||||
if($year == "") {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user_found = False;
|
||||
$movie_found = False;
|
||||
|
@ -669,6 +788,15 @@ function data_get_user_stats_loop($id, $array) {
|
|||
//Sort shows by duration
|
||||
$duration = array_column($shows, 'duration');
|
||||
array_multisort($duration, SORT_DESC, $shows);
|
||||
|
||||
//Sort episodes by duration
|
||||
$duration = array_column($episodes, 'duration');
|
||||
array_multisort($duration, SORT_DESC, $episodes);
|
||||
if(count($episodes) > 0) {
|
||||
$episode_duration_longest = $episodes[0];
|
||||
} else {
|
||||
$episode_duration_longest = array("title" => "None", "parent_title" => "None", "grandparent_title" => "None", "duration" => 0, "plays" => 0);
|
||||
}
|
||||
|
||||
// Sort $tracks for longest pause
|
||||
$duration = array_column($tracks, 'duration');
|
||||
|
@ -708,7 +836,7 @@ function data_get_user_stats_loop($id, $array) {
|
|||
}
|
||||
|
||||
if($config->get_user_show_stats) {
|
||||
$return_shows = array("shows" => $shows);
|
||||
$return_shows = array("shows" => $shows, "episode_duration_longest" => $episode_duration_longest);
|
||||
} else {
|
||||
$return_shows = array();
|
||||
}
|
||||
|
@ -750,51 +878,45 @@ function data_get_user_stats_loop($id, $array) {
|
|||
return array("movies" => $return_movies, "shows" => $return_shows, "music" => $return_music, "year_movies" => $return_year_movies, "year_shows" => $return_year_shows, "year_music" => $return_year_music, "year_users" => $return_year_users);
|
||||
}
|
||||
|
||||
function tautulli_get_user_show_buddy($id, $shows) {
|
||||
function data_get_user_show_buddy($id, $show, $array) {
|
||||
|
||||
$time_start = microtime(true);
|
||||
|
||||
global $connection;
|
||||
global $config;
|
||||
global $library_id_shows;
|
||||
global $name;
|
||||
global $arrContextOptions;
|
||||
|
||||
$url = $connection . "/api/v2?apikey=" . $config->tautulli_apikey . "&cmd=get_history§ion_id=" . $library_id_shows . "&order_column=date&include_activity=0&media_type=episode&order_dir=desc&length=" . $config->tautulli_length . "&search=" . urlencode($shows[0]["title"]);
|
||||
|
||||
if($config->ssl) {
|
||||
$response = json_decode(file_get_contents($url, false, stream_context_create($arrContextOptions)));
|
||||
} else {
|
||||
$response = json_decode(file_get_contents($url));
|
||||
}
|
||||
|
||||
$array = $response->response->data->data;
|
||||
if(empty($array)) {
|
||||
$array = array();
|
||||
}
|
||||
$top_show_users = array();
|
||||
|
||||
for ($i = 0; $i < count($array); $i++) {
|
||||
$user = $array[$i]->friendly_name;
|
||||
$duration = $array[$i]->duration;
|
||||
for($j = 0; $j < count($array[$i]["data"]); $j++) {
|
||||
$user_id = $array[$i]["data"][$j]["user_id"];
|
||||
$friendly_name = $array[$i]["data"][$j]["friendly_name"];
|
||||
$duration = $array[$i]["data"][$j]["duration"];
|
||||
$grandparent_title = $array[$i]["data"][$j]["grandparent_title"];
|
||||
|
||||
if($array[$i]->date > $config->wrapped_end || $array[$i]->grandparent_title != $shows[0]["title"]) {
|
||||
continue;
|
||||
} else if($array[$i]->date < $config->wrapped_start) {
|
||||
break;
|
||||
}
|
||||
if($array[$i]["data"][$j]["date"] > $config->wrapped_end || $grandparent_title != $show) {
|
||||
continue;
|
||||
} else if($array[$i]["data"][$j]["date"] < $config->wrapped_start) {
|
||||
break;
|
||||
}
|
||||
|
||||
$found = False;
|
||||
$found = False;
|
||||
|
||||
for ($j = 0; $j < count($top_show_users); $j++) {
|
||||
if($top_show_users[$j]["user"] == $user) {
|
||||
$top_show_users[$j]["duration"] = intval($top_show_users[$j]["duration"]) + intval($duration);
|
||||
$found = True;
|
||||
for ($u = 0; $u < count($top_show_users); $u++) {
|
||||
if($top_show_users[$u]["user_id"] == $user_id) {
|
||||
$top_show_users[$u]["duration"] = intval($top_show_users[$u]["duration"]) + intval($duration);
|
||||
$found = True;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$found) {
|
||||
array_push($top_show_users, array("user" => $user, "duration" => $duration));
|
||||
}
|
||||
if(!$found) {
|
||||
array_push($top_show_users, array("user_id" => $user_id, "duration" => $duration, "friendly_name" => $friendly_name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort show-buddies by duration
|
||||
|
@ -804,20 +926,24 @@ function tautulli_get_user_show_buddy($id, $shows) {
|
|||
$index = 0;
|
||||
if(count($top_show_users) > 1) {
|
||||
for($i = 0; $i < count($top_show_users); $i++) {
|
||||
if($top_show_users[$i]["user"] == $name) {
|
||||
if($top_show_users[$i]["user_id"] == $id) {
|
||||
$index = $i;
|
||||
}
|
||||
}
|
||||
|
||||
if((($index == 0) || ($index % 2 == 0)) AND ($index < count($top_show_users)-1)) {
|
||||
$buddy = array("user" => $top_show_users[$index+1]["user"], "duration" => $top_show_users[$index+1]["duration"], "found" => True, "watched_relative_to_you" => "less");
|
||||
$buddy = array("friendly_name" => $top_show_users[$index+1]["friendly_name"], "user_id" => $top_show_users[$index+1]["user_id"], "duration" => $top_show_users[$index+1]["duration"], "found" => True, "watched_relative_to_you" => "less");
|
||||
} else {
|
||||
$buddy = array("user" => $top_show_users[$index-1]["user"], "duration" => $top_show_users[$index-1]["duration"], "found" => True, "watched_relative_to_you" => "more");
|
||||
$buddy = array("friendly_name" => $top_show_users[$index-1]["friendly_name"], "user_id" => $top_show_users[$index-1]["user_id"], "duration" => $top_show_users[$index-1]["duration"], "found" => True, "watched_relative_to_you" => "more");
|
||||
}
|
||||
|
||||
} else {
|
||||
$buddy = array("user" => False, "duration" => 0, "found" => False, "watched_relative_to_you" => False);
|
||||
$buddy = array("friendly_name" => False, "user_id" => False, "duration" => 0, "found" => False, "watched_relative_to_you" => False);
|
||||
}
|
||||
|
||||
$time_end = microtime(true);
|
||||
$execution_time = ($time_end - $time_start);
|
||||
log_activity($id, 'Buddy execution: '.$execution_time.' seconds');
|
||||
|
||||
return $buddy;
|
||||
}
|
||||
|
|
|
@ -160,6 +160,7 @@ img {
|
|||
background-color: #ffbd55;
|
||||
border-radius: 25px;
|
||||
color: black;
|
||||
font-size: 0.75em;
|
||||
}
|
||||
|
||||
.boks-knapp {
|
||||
|
@ -369,9 +370,20 @@ form {
|
|||
.btn {
|
||||
background-color: #ffbd55;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
label {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
input[type="checkbox" i] {
|
||||
transform: scale(1.5);
|
||||
cursor: pointer;
|
||||
width: auto;
|
||||
box-sizing: content-box;
|
||||
display: block;
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
|
||||
.footer {
|
||||
|
|
71
caching.html
Normal file
71
caching.html
Normal file
|
@ -0,0 +1,71 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
|
||||
|
||||
<title>Plex Wrapped</title>
|
||||
|
||||
<!-- Bootstrap 4 CSS and custom CSS -->
|
||||
<link rel="stylesheet" type="text/css" href="assets/css/wrapped.css" />
|
||||
<link rel="shortcut icon" href="assets/img/favicons/favicon.ico" />
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
|
||||
<script src="./caching.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="content" id="login_content" style="">
|
||||
|
||||
<div class="boks">
|
||||
|
||||
<div class="boks3" id="search_input" style="padding: 0 !important;">
|
||||
|
||||
<div class="boks2" style="float: none !important; display: block; padding: 0; margin-top: 0em;">
|
||||
<img src="assets/img/gift.svg" onclick="window.location.href = './';" style="width: 15em; cursor: pointer;">
|
||||
</div>
|
||||
|
||||
<div class="boks2" style="float: none !important; display: block; margin-top: 0em; padding-top: 0;">
|
||||
|
||||
<div class="stats_tekst" style="height: auto;">
|
||||
<p>
|
||||
If you want to decrease loadtime for your users you can pre-cache their results.
|
||||
<br><br>Remember to configure the system first.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div class="status" id="stats" style="">
|
||||
|
||||
<h1>Wrapped Caching</h1>
|
||||
|
||||
<div class="search" id="cache">
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="content" id="search_results">
|
||||
</div>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
get_config_cache();
|
||||
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
199
caching.js
Normal file
199
caching.js
Normal file
|
@ -0,0 +1,199 @@
|
|||
var cached = 0;
|
||||
var input_array;
|
||||
|
||||
function search_box() {
|
||||
var html = `
|
||||
<form id='stats_form' class='form' onsubmit='return false' action="" method="post">
|
||||
|
||||
<p style="font-size:1em;">
|
||||
This will call the API in a loop until all the entires in the set period are cached. The entry below allows you to choose the maximum amount of days to be cached each time you call the API to attempt pre-caching. Having a higher amount of days requires the PHP script to run longer meaning you might have to configure the php.ini file.
|
||||
</p>
|
||||
|
||||
<div class='form-group'>
|
||||
|
||||
<label for="days" title="">Maximum days per API call</label>
|
||||
<input type="number" class='form-control' name="days" id="days" minlenght='1' value='100' autocomplete="off" required />
|
||||
|
||||
</div>
|
||||
|
||||
<div class='form-group'>
|
||||
|
||||
<input type="submit" class='form-control btn' value="Cache" name="cache_button" id="cache_button" required/>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
`;
|
||||
|
||||
document.getElementById('cache').innerHTML = html;
|
||||
}
|
||||
|
||||
$(document).on('submit', '#stats_form', function(){
|
||||
|
||||
cache();
|
||||
|
||||
});
|
||||
|
||||
function cache() {
|
||||
var days = document.getElementById('days').value;
|
||||
|
||||
var html = `
|
||||
<form id='stats_form' class='form' onsubmit='return false' action="" method="post">
|
||||
|
||||
<div class='form-group'>
|
||||
<img id="loading_icon" src="assets/loading.gif" style="border-radius: 25px; background-color: white; padding: 1em; width: 4em; height: 4em; display: inline;">
|
||||
</div>
|
||||
|
||||
<h3>Caching log:</h3>
|
||||
|
||||
<div id="cache_results">
|
||||
</div>
|
||||
|
||||
|
||||
</form>
|
||||
`;
|
||||
|
||||
document.getElementById('cache').innerHTML = html;
|
||||
|
||||
document.getElementById('cache_results').innerHTML += '<p style="color:white;">' + 'Creating new cache request. Maximum ' + days + ' days.' + '</p>';
|
||||
|
||||
get_stats(days);
|
||||
}
|
||||
|
||||
function cache_log(days, result, complete) {
|
||||
if(result) {
|
||||
document.getElementById('cache_results').innerHTML += '<p style="color:darkseagreen;">' + 'Completed one caching with a maxmimum of ' + days + ' days.' + '</p>';
|
||||
} else {
|
||||
document.getElementById('cache_results').innerHTML += '<p style="color:indianred;"> ' + 'Error caching ' + days + ' days. Stopping.' + '</p>';
|
||||
document.getElementById('loading_icon').style.display = "none";
|
||||
}
|
||||
|
||||
if(complete) {
|
||||
document.getElementById('cache_results').innerHTML += '<p style="color:darkseagreen;">' + 'Finished caching loop.' + '</p>';
|
||||
document.getElementById('loading_icon').style.display = "none";
|
||||
} else {
|
||||
document.getElementById('cache_results').innerHTML += '<p style="color:white;">' + 'Creating new cache request. Maximum ' + days + ' days.' + '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
function get_stats(days) {
|
||||
|
||||
stats_form = {
|
||||
"p_identity" : '0',
|
||||
"caching" : "True",
|
||||
"cache_limit" : days
|
||||
};
|
||||
|
||||
var stats_data = JSON.stringify(stats_form);
|
||||
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
try {
|
||||
var result = JSON.parse(this.responseText);
|
||||
|
||||
if(result.error) {
|
||||
cache_log(days, false, true);
|
||||
} else {
|
||||
if(!result.caching_complete) {
|
||||
cache_log(days, true, result.caching_complete);
|
||||
get_stats(days);
|
||||
} else {
|
||||
cache_log(days, true, result.caching_complete);
|
||||
}
|
||||
}
|
||||
} catch(error) {
|
||||
cache_log(days, false, true);
|
||||
console.log('Error: ' + error);
|
||||
console.log(this.responseText);
|
||||
}
|
||||
}
|
||||
};
|
||||
xhttp.withCredentials = true;
|
||||
xhttp.open("post", "api/get_stats.php", );
|
||||
xhttp.send(stats_data);
|
||||
return;
|
||||
}
|
||||
|
||||
function topFunction() {
|
||||
document.body.scrollTop = 0; // For Safari
|
||||
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
|
||||
}
|
||||
|
||||
function get_config_cache() {
|
||||
|
||||
config_form = {
|
||||
"password" : "",
|
||||
"username" : "",
|
||||
};
|
||||
|
||||
var config_data = JSON.stringify(config_form);
|
||||
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
var result = JSON.parse(this.responseText);
|
||||
if(result.password) {
|
||||
login_menu();
|
||||
} else {
|
||||
alert(result.message);
|
||||
}
|
||||
}
|
||||
};
|
||||
xhttp.withCredentials = true;
|
||||
xhttp.open("post", "api/get_config.php");
|
||||
xhttp.send(config_data);
|
||||
}
|
||||
|
||||
function get_config() {
|
||||
|
||||
current_password = document.getElementById('password').value;
|
||||
current_username = document.getElementById('username').value;
|
||||
|
||||
config_form = {
|
||||
"password" : current_password,
|
||||
"username" : current_username
|
||||
};
|
||||
|
||||
var config_data = JSON.stringify(config_form);
|
||||
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
var result = JSON.parse(this.responseText);
|
||||
if(result.error) {
|
||||
alert(result.message);
|
||||
} else {
|
||||
if(!result.data.use_cache) {
|
||||
alert("You have disabled cache in the configuration!");
|
||||
}
|
||||
search_box();
|
||||
}
|
||||
}
|
||||
};
|
||||
xhttp.withCredentials = true;
|
||||
xhttp.open("post", "api/get_config.php");
|
||||
xhttp.send(config_data);
|
||||
}
|
||||
|
||||
function login_menu() {
|
||||
topFunction();
|
||||
var html = '<form id="password_login_form" onsubmit="get_config();return false">'
|
||||
|
||||
html += '<div class="form-group">';
|
||||
html += '<label for="username" title="The username chosen during first-time setup.">Username</label>';
|
||||
html += '<input type="text" class="form-control" id="username" value="" autocomplete="on" minlength=4 required />';
|
||||
html += '</div>';
|
||||
|
||||
html += '<div class="form-group">';
|
||||
html += '<label for="password" title="The password chosen during first-time setup.">Password</label>';
|
||||
html += '<input type="password" class="form-control" id="password" value="" autocomplete="off" required />';
|
||||
html += '</div>';
|
||||
|
||||
html += '<div class="form-group">';
|
||||
html += '<input type="submit" class="form-control btn" id="password_button" value="Log in" required />';
|
||||
html += '</div>';
|
||||
|
||||
html += '</form>';
|
||||
document.getElementById("cache").innerHTML = html;
|
||||
}
|
175
get_stats.js
175
get_stats.js
|
@ -5,10 +5,9 @@ function get_stats() {
|
|||
|
||||
var p_identity = document.getElementById("p_identity").value;
|
||||
|
||||
//var p_identity = p_identity.replace(/[&\/\\#,+()$~%:*?<>{}]/g, '');
|
||||
|
||||
stats_form = {
|
||||
"p_identity" : p_identity.trim()
|
||||
"p_identity" : p_identity.trim(),
|
||||
"caching" : "False"
|
||||
};
|
||||
|
||||
var stats_data = JSON.stringify(stats_form);
|
||||
|
@ -16,16 +15,21 @@ function get_stats() {
|
|||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
console.log(this.responseText);
|
||||
var result = JSON.parse(this.responseText);
|
||||
if(result.error) {
|
||||
loading_icon.style.display = "none";
|
||||
search_button("SEARCH");
|
||||
document.getElementById('results_error').innerHTML = '<p style="color:inherit; text-shadow: none;">' + result.message + '</p>';
|
||||
|
||||
} else {
|
||||
load_page(this.responseText);
|
||||
}
|
||||
try {
|
||||
var result= JSON.parse(this.responseText);
|
||||
if(result.error) {
|
||||
loading_icon.style.display = "none";
|
||||
search_button("SEARCH");
|
||||
document.getElementById('results_error').innerHTML = '<p style="color:inherit; text-shadow: none;">' + result.message + '</p>';
|
||||
} else {
|
||||
load_page(this.responseText);
|
||||
}
|
||||
} catch(error) {
|
||||
document.getElementById('results_error').innerHTML = '<p style="color:inherit; text-shadow: none;">' + "API response can't be parsed." + '</p>';
|
||||
console.log('Error: ' + error);
|
||||
console.log(this.responseText);
|
||||
loading_icon.style.display = "none";
|
||||
}
|
||||
}
|
||||
};
|
||||
xhttp.withCredentials = true;
|
||||
|
@ -184,12 +188,14 @@ function load_movies() {
|
|||
text += "<div class='boks' style='height: auto !important; width: 100%; padding-bottom: 25em; padding-top: 25em; height:10em; background-color:#B9A3D2;'>";
|
||||
|
||||
text += "<div class='boks3'>";
|
||||
text += "<div class='status'>";
|
||||
text += "<h1>Movies!</h1>";
|
||||
text += "<br><br><br>";
|
||||
text += "<h2>You watched " + results.user.user_movies.data.movies.length + " movies. That's impressive in itself!</h2><p>(might wanna try it)</p>"
|
||||
text += '<img src="assets/img/bored.svg" style="margin: auto; display: block; width: 15em;">';
|
||||
text += "</div>";
|
||||
text += "<div class='boks2'>";
|
||||
text += "<div class='status'>";
|
||||
text += "<h1>Movies!</h1>";
|
||||
text += "<br><br><br>";
|
||||
text += "<h2>You watched " + results.user.user_movies.data.movies.length + " movies. That's impressive in itself!</h2><p>(might wanna try it)</p>"
|
||||
text += '<img src="assets/img/bored.svg" style="margin: auto; display: block; width: 15em;">';
|
||||
text += "</div>";
|
||||
text += "</div>";
|
||||
text += "</div>";
|
||||
|
||||
text += "</div>";
|
||||
|
@ -222,6 +228,12 @@ function load_shows() {
|
|||
text += load_showbuddy();
|
||||
text += "</div>";
|
||||
}
|
||||
|
||||
if(results.user.user_shows.data.episode_duration_longest.plays != 0 && results.user.user_shows.data.episode_duration_longest.duration != 0) {
|
||||
text += "<div class='boks2'>";
|
||||
text += load_longest_episode(results.user.user_shows.data.episode_duration_longest);
|
||||
text += "</div>";
|
||||
}
|
||||
|
||||
var sum = 0;
|
||||
for(i = 0; (i < results.user.user_shows.data.shows.length); i++) {
|
||||
|
@ -257,6 +269,12 @@ function load_shows() {
|
|||
text += load_showbuddy();
|
||||
text += "</div>";
|
||||
}
|
||||
|
||||
if(results.user.user_shows.data.episode_duration_longest.plays != 0 && results.user.user_shows.data.episode_duration_longest.duration != 0) {
|
||||
text += "<div class='boks2'>";
|
||||
text += load_longest_episode(results.user.user_shows.data.episode_duration_longest);
|
||||
text += "</div>";
|
||||
}
|
||||
|
||||
text += "</div>";
|
||||
text += "</div>";
|
||||
|
@ -266,12 +284,14 @@ function load_shows() {
|
|||
text += "<div class='boks' style='height: auto !important; width: 100%; padding-bottom: 25em; padding-top: 25em; height:10em; background-color:#B9A3D2;'>";
|
||||
|
||||
text += "<div class='boks3'>";
|
||||
text += "<div class='status'>";
|
||||
text += "<h1>Shows!</h1>";
|
||||
text += "<br><br><br>";
|
||||
text += "<h2>You watched " + results.user.user_shows.data.shows.length + " shows. I get it, it's not for everyone!</h2><p>(might wanna try it)</p>"
|
||||
text += '<img src="assets/img/bored.svg" style="margin: auto; display: block; width: 15em;">';
|
||||
text += "</div>";
|
||||
text += "<div class='boks2'>";
|
||||
text += "<div class='status'>";
|
||||
text += "<h1>Shows!</h1>";
|
||||
text += "<br><br><br>";
|
||||
text += "<h2>You watched " + results.user.user_shows.data.shows.length + " shows. I get it, it's not for everyone!</h2><p>(might wanna try it)</p>"
|
||||
text += '<img src="assets/img/bored.svg" style="margin: auto; display: block; width: 15em;">';
|
||||
text += "</div>";
|
||||
text += "</div>";
|
||||
text += "</div>";
|
||||
|
||||
text += "</div>";
|
||||
|
@ -286,6 +306,7 @@ function load_music() {
|
|||
|
||||
var albums = [];
|
||||
var artists = [];
|
||||
var tracks = results.user.user_music.data.music;
|
||||
|
||||
for(var i = 0; i < results.user.user_music.data.music.length; i++) {
|
||||
var found = false;
|
||||
|
@ -300,7 +321,7 @@ function load_music() {
|
|||
}
|
||||
|
||||
if(!found && results.user.user_music.data.music[i].parent_title != "" && results.user.user_music.data.music[i].grandparent_title != "") {
|
||||
albums.push({"title" : results.user.user_music.data.music[i].parent_title, "parent_rating_key" : results.user.user_music.data.music[i].parent_rating_key,"grandparent_title" : results.user.user_music.data.music[i].grandparent_title, "plays" : 1, "duration" : results.user.user_music.data.music[i].duration});
|
||||
albums.push({"title" : results.user.user_music.data.music[i].parent_title, "parent_rating_key" : results.user.user_music.data.music[i].parent_rating_key,"grandparent_title" : results.user.user_music.data.music[i].grandparent_title, "plays" : 1, "duration" : results.user.user_music.data.music[i].duration, "year" : results.user.user_music.data.music[i].year});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -350,20 +371,31 @@ function load_music() {
|
|||
text += "<div class='boks2'>";
|
||||
text += top_list(artists, "Your top artists", false, false);
|
||||
text += "</div>";
|
||||
|
||||
text += "<div class='boks2' style='padding: 0;'>";
|
||||
|
||||
albums.sort(function(a, b) {
|
||||
return parseFloat(a.year) - parseFloat(b.year);
|
||||
});
|
||||
text += "<div class='boks2'>";
|
||||
text += oldest_album(albums);
|
||||
text += "</div>";
|
||||
|
||||
var sum = 0;
|
||||
for(i = 0; (i < results.user.user_music.data.music.length); i++) {
|
||||
sum += results.user.user_music.data.music[i].duration;
|
||||
}
|
||||
|
||||
var sum = 0;
|
||||
for(i = 0; (i < results.user.user_music.data.music.length); i++) {
|
||||
sum += results.user.user_music.data.music[i].duration;
|
||||
}
|
||||
|
||||
text += "<div class='boks2'>";
|
||||
text += you_spent(sum, 'music', 'listening');
|
||||
text += "</div>";
|
||||
text += "<div class='boks2'>";
|
||||
text += you_spent(sum, 'music', 'listening');
|
||||
text += "</div>";
|
||||
|
||||
text += "</div>";
|
||||
|
||||
text += "</div>";
|
||||
text += "</div>";
|
||||
|
||||
} else if(results.user.user_shows.data.shows.length == 1) {
|
||||
} else if(results.user.user_music.data.music.length == 1) {
|
||||
|
||||
text += "<div class='boks' style='height: auto !important; width: 100%; padding-bottom: 25em; padding-top: 25em; height:10em; background-color:#CFA38C;'>";
|
||||
|
||||
|
@ -385,12 +417,14 @@ function load_music() {
|
|||
text += "<div class='boks' style='height: auto !important; width: 100%; padding-bottom: 25em; padding-top: 25em; height:10em; background-color:#CFA38C;'>";
|
||||
|
||||
text += "<div class='boks3'>";
|
||||
text += "<div class='status'>";
|
||||
text += "<h1>Shows!</h1>";
|
||||
text += "<br><br><br>";
|
||||
text += "<h2>You listened to " + results.user.user_music.data.music.length + " tracks. I get it, it's not for everyone!</h2><p>(might wanna try it)</p>"
|
||||
text += '<img src="assets/img/bored.svg" style="margin: auto; display: block; width: 15em;">';
|
||||
text += "</div>";
|
||||
text += "<div class='boks2'>";
|
||||
text += "<div class='status'>";
|
||||
text += "<h1>Music!</h1>";
|
||||
text += "<br><br><br>";
|
||||
text += "<h2>You listened to " + results.user.user_music.data.music.length + " tracks. No speakers, huh?</h2><p>(might wanna try it)</p>"
|
||||
text += '<img src="assets/img/bored.svg" style="margin: auto; display: block; width: 15em;">';
|
||||
text += "</div>";
|
||||
text += "</div>";
|
||||
text += "</div>";
|
||||
|
||||
text += "</div>";
|
||||
|
@ -424,6 +458,21 @@ function oldest_movie(array) {
|
|||
return html;
|
||||
}
|
||||
|
||||
function oldest_album(array) {
|
||||
var html = "";
|
||||
|
||||
html += "<div class='status' id='list3' style='padding:1em;min-width:15em;'>";
|
||||
html += "<div class='stats'>";
|
||||
html += "The oldest album you listened to was <br><b>" + array[0].title + " (" + array[0].year + ")</b> by " + array[0].grandparent_title + "<br>";
|
||||
html += "<br>Maybe get the vinyl release?";
|
||||
html += '<br><br><img src="assets/img/old-man.svg" style="margin: auto; display: block; width: 15em;">';
|
||||
|
||||
html += "</div>";
|
||||
html += "</div>";
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
function completion_movie(user_movie_finishing_percent, single) {
|
||||
var html = "";
|
||||
|
||||
|
@ -474,6 +523,7 @@ function paused_movie(array, single) {
|
|||
|
||||
return html;
|
||||
}
|
||||
|
||||
function load_showbuddy() {
|
||||
var html = "";
|
||||
|
||||
|
@ -481,13 +531,13 @@ function load_showbuddy() {
|
|||
html += "<div class='stats'>";
|
||||
html += "<b>Your top show was " + results.user.user_shows.data.shows[0].title + "</b><br>";
|
||||
if(!results.user.user_shows.data.show_buddy.error) {
|
||||
if(!results.user.user_shows.data.show_buddy.user.found) {
|
||||
if(!results.user.user_shows.data.show_buddy.found) {
|
||||
html += '<br><img src="assets/img/quest.svg" style="margin: auto; display: block; width: 15em;">';
|
||||
html += "<br>That means you dared to explore where no one else would, because you are the only viewer of that show";
|
||||
} else {
|
||||
html += "And you're not alone! Your " + results.user.user_shows.data.shows[0].title + "-buddy is ";
|
||||
html += "<b>" + results.user.user_shows.data.show_buddy.user.user + "!</b><br><br>";
|
||||
var combined = results.user.user_shows.data.show_buddy.user.duration + parseInt(results.user.user_shows.data.shows[0].duration);
|
||||
html += "<b>" + results.user.user_shows.data.show_buddy.friendly_name + "!</b><br><br>";
|
||||
var combined = results.user.user_shows.data.show_buddy.duration + parseInt(results.user.user_shows.data.shows[0].duration);
|
||||
var combined_2 = seconds_to_time(combined);
|
||||
html += '<img src="assets/img/social-event.svg" style="margin: auto; display: block; width: 15em;">';
|
||||
html += "<br>Your combined efforts resulted in <b>" + combined_2 + "</b> of " + results.user.user_shows.data.shows[0].title + "!</b>";
|
||||
|
@ -499,6 +549,19 @@ function load_showbuddy() {
|
|||
return html;
|
||||
}
|
||||
|
||||
function load_longest_episode(array) {
|
||||
var html = "";
|
||||
|
||||
html += "<div class='status' id='list3' style='padding:1em;min-width:15em;'>";
|
||||
html += "<div class='stats'>";
|
||||
html += "Your really liked the episode <b>" + array.title + "</b> from " + array.grandparent_title + "<br>";
|
||||
html += "<br>It recieved " + play_plays(array.plays) + " and was endured for " + seconds_to_time(array.duration, false) + ".";
|
||||
html += "</div>";
|
||||
html += "</div>";
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
function you_spent(time, category, verb) {
|
||||
var html = "";
|
||||
|
||||
|
@ -619,19 +682,19 @@ function load_users() {
|
|||
var sum_shows = 0;
|
||||
var sum_artists = 0;
|
||||
|
||||
if(functions.get_year_stats_movies) {
|
||||
if(functions.get_year_stats_movies && results.year_stats.year_movies.data.length > 0) {
|
||||
for(i = 0; (i < results.year_stats.year_movies.data.length); i++) {
|
||||
sum_movies += results.year_stats.year_movies.data[i].duration;
|
||||
}
|
||||
}
|
||||
|
||||
if(functions.get_year_stats_shows) {
|
||||
if(functions.get_year_stats_shows && results.year_stats.year_shows.data.length > 0) {
|
||||
for(i = 0; (i < results.year_stats.year_shows.data.length); i++) {
|
||||
sum_shows += results.year_stats.year_shows.data[i].duration;
|
||||
}
|
||||
}
|
||||
|
||||
if(functions.get_year_stats_music) {
|
||||
if(functions.get_year_stats_music && results.year_stats.year_music.data.length > 0) {
|
||||
for(i = 0; (i < results.year_stats.year_music.data.length); i++) {
|
||||
sum_artists += results.year_stats.year_music.data[i].duration;
|
||||
}
|
||||
|
@ -641,30 +704,34 @@ function load_users() {
|
|||
var time_shows = seconds_to_time(sum_shows, false);
|
||||
var time_artists = seconds_to_time(sum_artists, false);
|
||||
var time_all = seconds_to_time(Math.floor(sum_movies + sum_shows + sum_artists), false);
|
||||
var function_sum = 0;
|
||||
|
||||
text += "<div class='boks2'>";
|
||||
text += "<div class='status' id='list3' style='padding:1em;min-width:15em;'>";
|
||||
text += "<div class='stats'>";
|
||||
|
||||
if(functions.get_year_stats_movies) {
|
||||
if(functions.get_year_stats_movies && results.year_stats.year_movies.data.length > 0) {
|
||||
text += "All the different users combined spent <b>" + time_movies + "</b>";
|
||||
text += " watching movies.";
|
||||
text += "<br><br>";
|
||||
function_sum += 1;
|
||||
}
|
||||
|
||||
if(functions.get_year_stats_shows) {
|
||||
if(functions.get_year_stats_shows && results.year_stats.year_shows.data.length > 0) {
|
||||
text += "All the different users combined spent <b>" + time_shows + "</b>";
|
||||
text += " watching shows.";
|
||||
text += "<br><br>";
|
||||
function_sum += 1;
|
||||
}
|
||||
|
||||
if(functions.get_year_stats_music) {
|
||||
if(functions.get_year_stats_music && results.year_stats.year_music.data.length > 0) {
|
||||
text += "All the different users combined spent <b>" + time_artists + "</b>";
|
||||
text += " listening to artists.";
|
||||
text += "<br><br>";
|
||||
function_sum += 1;
|
||||
}
|
||||
|
||||
if(functions.get_year_stats_movies && (functions.get_year_stats_shows || functions.get_year_stats_music) || (functions.get_year_stats_shows && functions.get_year_stats_music)) {
|
||||
if(function_sum > 1) {
|
||||
text += "That is <b>" + time_all + "</b><br>of content!";
|
||||
}
|
||||
|
||||
|
@ -679,19 +746,19 @@ function load_users() {
|
|||
text += "</div>";
|
||||
text += "<div class='boks3'>";
|
||||
|
||||
if(functions.get_year_stats_movies) {
|
||||
if(functions.get_year_stats_movies && results.year_stats.year_movies.data.length > 0) {
|
||||
text += "<div class='boks2'>";
|
||||
text += top_list(results.year_stats.year_movies.data, "Top movies", false, true);
|
||||
text += "</div>";
|
||||
}
|
||||
|
||||
if(functions.get_year_stats_shows) {
|
||||
if(functions.get_year_stats_shows && results.year_stats.year_shows.data.length > 0) {
|
||||
text += "<div class='boks2'>";
|
||||
text += top_list(results.year_stats.year_shows.data, "Top shows", false, false);
|
||||
text += "</div>";
|
||||
}
|
||||
|
||||
if(functions.get_year_stats_music) {
|
||||
if(functions.get_year_stats_music && results.year_stats.year_music.data.length > 0) {
|
||||
var artists = [];
|
||||
|
||||
for(var i = 0; i < results.year_stats.year_music.data.length; i++) {
|
||||
|
|
Loading…
Reference in a new issue