258 lines
14 KiB
HTML
258 lines
14 KiB
HTML
<%doc>
|
|
USAGE DOCUMENTATION :: PLEASE LEAVE THIS AT THE TOP OF THIS FILE
|
|
|
|
For Mako templating syntax documentation please visit: http://docs.makotemplates.org/en/latest/
|
|
|
|
Filename: home_stats.html
|
|
Version: 0.1
|
|
Variable names: data [array]
|
|
|
|
data[array_index] :: Usable parameters
|
|
|
|
data['stat_id'] Returns the name of the stat. Either 'top_tv', 'top_movies', 'popular_tv', 'popular_movies', 'top_user' or 'top_platform'
|
|
data['stat_type'] Returns the type of the stat. Either 'total_plays' or 'total_duration'
|
|
data['rows'] Returns an array containing stat data
|
|
|
|
data[array_index]['rows'] :: Usable parameters
|
|
|
|
row_id Return the db row id for a metadata item if one exists
|
|
|
|
== Only if 'stat_id' is 'top_tv' or 'popular_tv' or 'top_movies' or 'popular_movies' or 'top_music' or 'popular_music' or 'last_watched' ==
|
|
thumb Return the thumb for the media item.
|
|
|
|
== Only if 'stat_id' is 'top_tv' or 'popular_tv' or 'top_music' or 'popular_music' ==
|
|
grandparent_thumb Returns location of the item's thumbnail. Use with pms_image_proxy.
|
|
rating_key Returns the unique identifier for the media item.
|
|
title Returns the title for the associated stat.
|
|
|
|
== Only if 'stat_id' is 'top_tv' or 'top_movies' or 'top_music' or 'top_user' or 'top_platform' ==
|
|
total_plays Returns the count for the associated stat.
|
|
total_duration Returns the total duration for the associated stat.
|
|
|
|
== Only of 'stat_id' is 'popular_tv' or 'popular_movies' or 'popular_music' ==
|
|
users_watched Returns the count for the associated stat.
|
|
|
|
== Only if 'stat_id' is 'top_user' or 'last_watched' ==
|
|
user_thumb Returns url of the user's gravatar. Returns '' if none exists.
|
|
user Returns the username for the associated stat.
|
|
user_id Returns the user id for the associated stat.
|
|
friendly_name Returns the friendly name of the user for the associated stat.
|
|
|
|
== Only if 'stat_id' is 'top_platform' or 'last_watched' ==
|
|
player Returns the player name for the associated stat.
|
|
|
|
== Only if 'stat_id' is 'last_watched' ==
|
|
last_watch Returns the time the media item was last watched.
|
|
|
|
== Only if 'stat_id' is 'most_concurrent' ==
|
|
count Returns the count of the most concurrent streams.
|
|
started Returns the start time of the most concurrent streams.
|
|
stopped Returns the stop time of the most concurrent streams.
|
|
|
|
DOCUMENTATION :: END
|
|
</%doc>
|
|
|
|
<%!
|
|
from plexpy.helpers import cast_to_int, page
|
|
|
|
# Human readable duration
|
|
def hd(seconds):
|
|
m, s = divmod(cast_to_int(seconds), 60)
|
|
h, m = divmod(m, 60)
|
|
return str(h).zfill(1) + ':' + str(m).zfill(2)
|
|
%>
|
|
|
|
% if data and any(top_stat['rows'] for top_stat in data):
|
|
% for top_stat in data:
|
|
% if top_stat['rows']:
|
|
<%
|
|
stat_id = top_stat['stat_id']
|
|
row0 = top_stat['rows'][0]
|
|
%>
|
|
<div class="dashboard-stats-instance" id="stats-instance-${stat_id}" data-stat_id="${stat_id}">
|
|
<div class="dashboard-stats-container">
|
|
% if stat_id in ('top_movies', 'popular_movies', 'top_tv', 'popular_tv', 'top_music', 'popular_music', 'last_watched'):
|
|
<% fallback = 'art-live' if row0['live'] else 'art' %>
|
|
<div id="stats-background-${stat_id}" class="dashboard-stats-background" style="background-image: url(${page('pms_image_proxy', row0['art'], row0['rating_key'], 500, 280, 40, '282828', 3, fallback=fallback)});">
|
|
% elif stat_id == 'top_platforms':
|
|
<div id="stats-background-${stat_id}" class="dashboard-stats-background platform-${row0['platform_name']}-rgba no-image">
|
|
% else:
|
|
<div id="stats-background-${stat_id}" class="dashboard-stats-background flat">
|
|
% endif
|
|
% if stat_id in ('top_movies', 'popular_movies', 'top_tv', 'popular_tv', 'top_music', 'popular_music', 'last_watched'):
|
|
<div class="dashboard-stats-poster-container hidden-xs">
|
|
% if stat_id in ('top_music', 'popular_music'):
|
|
<div id="stats-thumb-${stat_id}-bg" class="dashboard-stats-poster" style="background-image: url(${page('pms_image_proxy', row0['thumb'], row0['rating_key'], 300, 300, 60, '282828', 3, fallback='cover')});"></div>
|
|
% endif
|
|
<%
|
|
height, fallback = ('450', 'poster')
|
|
if stat_id in ('top_music', 'popular_music'):
|
|
height, fallback = ('300', 'cover')
|
|
elif row0['live']:
|
|
height, fallback = ('450', 'poster-live')
|
|
|
|
href = '#'
|
|
if row0['rating_key']:
|
|
if row0['live']:
|
|
href = page('info', row0['rating_key'], row0['guid'], history=True, live=row0['live'])
|
|
else:
|
|
href = page('info', row0['rating_key'])
|
|
%>
|
|
<a id="stats-thumb-url-${stat_id}" href="${href}" title="${row0['title']}">
|
|
<div id="stats-thumb-${stat_id}" class="dashboard-stats-${fallback.split('-')[0]}" style="background-image: url(${page('pms_image_proxy', row0['thumb'], row0['rating_key'], 300, height, fallback=fallback)});"></div>
|
|
</a>
|
|
</div>
|
|
% elif stat_id == 'top_users':
|
|
<% user_href = page('user', row0['user_id']) if row0['user_id'] else '#' %>
|
|
<a id="stats-thumb-url-${stat_id}" href="${user_href}" title="${row0['friendly_name']}" class="hidden-xs">
|
|
<div id="stats-thumb-${stat_id}" class="dashboard-stats-circle" style="background-image: url(${row0['user_thumb'] or 'images/gravatar-default.png'})"></div>
|
|
</a>
|
|
% elif stat_id == 'top_platforms':
|
|
<div id="stats-thumb-${stat_id}" class="dashboard-stats-flat svg-icon platform-${row0['platform_name']} transparent hidden-xs"></div>
|
|
% elif stat_id == 'most_concurrent':
|
|
<div id="stats-thumb-${stat_id}" class="dashboard-stats-flat svg-icon stats-${stat_id} transparent hidden-xs"></div>
|
|
% endif
|
|
<div class="dashboard-stats-info-container">
|
|
<div id="stats-title-${stat_id}" class="dashboard-stats-info-title">
|
|
<h4>${top_stat['stat_title']}</h4>
|
|
% if stat_id.startswith('top') and top_stat.get('stat_type') == 'total_plays':
|
|
<span class="dashboard-stats-stats-units">plays</span>
|
|
% elif stat_id.startswith('top') and top_stat.get('stat_type') == 'total_duration':
|
|
<span class="dashboard-stats-stats-units">hh:mm</span>
|
|
% elif stat_id.startswith('popular'):
|
|
<span class="dashboard-stats-stats-units">users</span>
|
|
% elif stat_id == 'last_watched':
|
|
<span class="dashboard-stats-stats-units" id="last-watched-header-info">${row0['friendly_name']}</span>
|
|
% elif stat_id == 'most_concurrent':
|
|
<span class="dashboard-stats-stats-units" id="most-concurrent-header-info">streams</span>
|
|
% endif
|
|
</div>
|
|
<div class="dashboard-stats-info-scroller scrollbar-macosx">
|
|
<div class="dashboard-stats-info scoller-content">
|
|
<ul class="list-unstyled dashboard-stats-info-list">
|
|
% for row in top_stat['rows']:
|
|
<li class="dashboard-stats-info-item ${'expanded' if loop.index == 0 else ''}" data-stat_id="${stat_id}"
|
|
data-rating_key="${row.get('rating_key')}" data-guid="${row.get('guid')}" data-title="${row.get('title')}"
|
|
data-art="${row.get('art')}" data-thumb="${row.get('thumb')}" data-platform="${row.get('platform_name')}"
|
|
data-user_id="${row.get('user_id')}" data-friendly_name="${row.get('friendly_name')}" data-user_thumb="${row.get('user_thumb')}"
|
|
data-last_watch="${row.get('last_watch')}" data-started="${row.get('started')}" data-live="${row.get('live')}">
|
|
<div class="sub-list">${loop.index + 1}</div>
|
|
<div class="sub-value">
|
|
% if stat_id in ('top_movies', 'popular_movies', 'top_tv', 'popular_tv', 'top_music', 'popular_music', 'last_watched'):
|
|
<%
|
|
href = '#'
|
|
if row['rating_key']:
|
|
if row['live']:
|
|
href = page('info', row['rating_key'], row['guid'], history=True, live=row['live'])
|
|
else:
|
|
href = page('info', row['rating_key'])
|
|
%>
|
|
<a href="${href}" title="${row['title']}">
|
|
${row['title']}
|
|
</a>
|
|
% elif stat_id == 'top_users':
|
|
<% user_href = page('user', row['user_id']) if row['user_id'] else '#' %>
|
|
<a href="${user_href}" title="${row['friendly_name']}">
|
|
${row['friendly_name']}
|
|
</a>
|
|
% elif stat_id == 'top_platforms':
|
|
${row['platform']}
|
|
% elif stat_id == 'most_concurrent':
|
|
${row['title']}
|
|
% endif
|
|
</div>
|
|
<div class="sub-count">
|
|
% if stat_id.startswith('top') and top_stat.get('stat_type') == 'total_plays':
|
|
${row['total_plays']}
|
|
% elif stat_id.startswith('top') and top_stat.get('stat_type') == 'total_duration':
|
|
${row['total_duration'] | hd}
|
|
% elif stat_id.startswith('popular'):
|
|
${row['users_watched']}
|
|
% elif stat_id == 'most_concurrent':
|
|
${row['count']}
|
|
% endif
|
|
</div>
|
|
</li>
|
|
% endfor
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
% endif
|
|
% endfor
|
|
<script>
|
|
$('.dashboard-stats-instance .dashboard-stats-info-scroller').scrollbar();
|
|
|
|
function changeImages(elem) {
|
|
var stat_id = $(elem).data('stat_id');
|
|
var art = $(elem).data('art');
|
|
var thumb = $(elem).data('thumb');
|
|
var user_id = $(elem).data('user_id');
|
|
var user_thumb = $(elem).data('user_thumb');
|
|
var rating_key = $(elem).data('rating_key');
|
|
var guid = $(elem).data('guid');
|
|
var live = $(elem).data('live');
|
|
var [height, fallback_poster, fallback_art] = [450, 'poster', 'art'];
|
|
if ($.inArray(stat_id, ['top_music', 'popular_music']) > -1) {
|
|
[height, fallback_poster, fallback_art] = [300, 'cover', 'art'];
|
|
} else if (live) {
|
|
[height, fallback_poster, fallback_art] = [450, 'poster-live', 'art-live'];
|
|
}
|
|
var href = '#';
|
|
|
|
if (stat_id === 'most_concurrent') {
|
|
return
|
|
} else if (stat_id === 'top_users') {
|
|
$('#stats-thumb-' + stat_id).css('background-image', 'url(' + (user_thumb || 'images/gravatar-default.png') + ')');
|
|
if (user_id) {
|
|
href = page('user', user_id);
|
|
}
|
|
$('#stats-thumb-url-' + stat_id).attr('href', href).prop('title', $(elem).data('friendly_name'));
|
|
} else if (stat_id === 'top_platforms') {
|
|
$('#stats-thumb-' + stat_id).removeClass(function (index, className) {
|
|
return (className.match (/(^|\s)platform-\S+/g) || []).join(' ');
|
|
}).addClass('platform-' + $(elem).data('platform'));
|
|
$('#stats-background-' + stat_id).removeClass(function (index, className) {
|
|
return (className.match (/(^|\s)platform-\S+/g) || []).join(' ');
|
|
}).addClass('platform-' + $(elem).data('platform') + '-rgba');
|
|
} else {
|
|
if (rating_key) {
|
|
if (live) {
|
|
href = page('info', rating_key, guid, true, live);
|
|
} else {
|
|
href = page('info', rating_key);
|
|
}
|
|
}
|
|
$('#stats-thumb-url-' + stat_id).attr('href', href).prop('title', $(elem).data('title'));
|
|
$('#stats-background-' + stat_id).css('background-image', 'url(' + page('pms_image_proxy', art, rating_key, 500, 280, 40, '282828', 3, fallback_art) + ')');
|
|
$('#stats-thumb-' + stat_id).css('background-image', 'url(' + page('pms_image_proxy', thumb, rating_key, 300, height, null, null, null, fallback_poster) + ')');
|
|
$('#stats-thumb-' + stat_id + '-bg').css('background-image', 'url(' + page('pms_image_proxy', thumb, rating_key, 300, height, 60, '282828', 3, fallback_poster) + ')');
|
|
}
|
|
}
|
|
|
|
$('.dashboard-stats-info-item').mouseenter(function () {
|
|
changeImages(this);
|
|
if ($(this).data('stat_id') === 'last_watched') {
|
|
var friendly_name = $(this).data('friendly_name');
|
|
var last_watch = moment($(this).data('last_watch'), 'X').format(date_format);
|
|
$('#last-watched-header-info').html(friendly_name);
|
|
} else if ($(this).data('stat_id') === 'most_concurrent') {
|
|
var started = moment($(this).data('started'), 'X').format(date_format + ' ' + time_format);
|
|
$('#most-concurrent-header-info').html(started);
|
|
}
|
|
});
|
|
$('.dashboard-stats-instance').mouseleave(function () {
|
|
changeImages($(this).find('.dashboard-stats-info-item').first());
|
|
if ($(this).data('stat_id') === 'last_watched') {
|
|
$('#last-watched-header-info').text($(this).find('.dashboard-stats-info-item').first().data('friendly_name'));
|
|
} else if ($(this).data('stat_id') === 'most_concurrent') {
|
|
$('#most-concurrent-header-info').text('streams');
|
|
}
|
|
});
|
|
</script>
|
|
% else:
|
|
<div class="text-muted">No stats to show for the selected period.</div><br>
|
|
% endif |