Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
cea4992331 | ||
![]() |
c98a8865d6 | ||
![]() |
fd3daae491 | ||
![]() |
697d107952 | ||
![]() |
65e42be278 | ||
![]() |
ad79d860db | ||
![]() |
5826a823a8 | ||
![]() |
cbec1e7768 | ||
![]() |
40f72bbe5f | ||
![]() |
699f481308 | ||
![]() |
411c28a10b | ||
![]() |
375bd733f1 | ||
![]() |
a96482ee3c | ||
![]() |
5fa6489733 | ||
![]() |
804a667b19 | ||
![]() |
7a7c92191d | ||
![]() |
b7baf1a05d | ||
![]() |
c4416572cf | ||
![]() |
5062c6e67a | ||
![]() |
3fc2f43b79 | ||
![]() |
a0bd94397c | ||
![]() |
ad12a85c6c | ||
![]() |
e8e5a0b5ff | ||
![]() |
0877a6bf21 | ||
![]() |
b0ded77571 |
32
CHANGELOG.md
32
CHANGELOG.md
@@ -1,10 +1,36 @@
|
||||
# Changelog
|
||||
|
||||
## v1.0 (2015-07-11)
|
||||
## v1.0 (2015-08-11)
|
||||
|
||||
* First release
|
||||
|
||||
## v1.0.1 (2015-07-13)
|
||||
## v1.0.1 (2015-08-13)
|
||||
|
||||
* Allow SSL certificate check override for certain systems with bad CA stores.
|
||||
* Fix typo on graphs page causing date selection to break on Safari.
|
||||
* Fix typo on graphs page causing date selection to break on Safari.
|
||||
|
||||
## v1.1.0 (2015-08-15)
|
||||
|
||||
* Add option to disable all history logging per user.
|
||||
* Add option to change user avatar URL. Thanks @jroyal.
|
||||
* Show all users on users table even if they don't yet have history.
|
||||
* Add option to change time frame of statistics on home page (Settings -> Extra Settings). Thanks @jroyal.
|
||||
* Add 7 day period for graphs. Thanks @jroyal.
|
||||
* Add pause, resume and buffer warning notification options.
|
||||
* Add fine tuning settings for buffer warning triggers.
|
||||
* Fix issue with SSL cert verification bypass when method doesn't exist (depends on Python version).
|
||||
* Fix bug on home stats which wouldn't update unless a TV show was first logged.
|
||||
* Fix alignment of bands on daily graphs which highlight weekends.
|
||||
* Fix behaviour of close button on update popup, will now stay closed for an hour after clicking close.
|
||||
* Fix some styling niggles.
|
||||
|
||||
## v1.1.1 (2015-08-15)
|
||||
|
||||
* Added Most watched movie for home stats. Thanks @jroyal.
|
||||
* Added TV show title to recently added text. Thanks @jroyal.
|
||||
* Fix bug with buffer warnings where notification would trigger continuously after first trigger.
|
||||
* Fix bug where custom avatar URL would get reset on every user refresh.
|
||||
|
||||
## v1.1.2 (2015-08-16)
|
||||
|
||||
* Fix bug where user refresh would fail under certain circumstances.
|
@@ -30,16 +30,16 @@ from plexpy import version
|
||||
<div class="container">
|
||||
<div id="ajaxMsg" class="ajaxMsg"></div>
|
||||
% if plexpy.CONFIG.CHECK_GITHUB and not plexpy.CURRENT_VERSION:
|
||||
<div id="updatebar">
|
||||
<div id="updatebar" style="display: none;">
|
||||
You're running an unknown version of PlexPy. <a href="update">Update</a> or
|
||||
<a href="#" onclick="$('#updatebar').slideUp('slow');">Close</a>
|
||||
<a href="#" id="updateDismiss">Close</a>
|
||||
</div>
|
||||
% elif plexpy.CONFIG.CHECK_GITHUB and plexpy.CURRENT_VERSION != plexpy.LATEST_VERSION and plexpy.COMMITS_BEHIND > 0 and plexpy.INSTALL_TYPE != 'win':
|
||||
<div id="updatebar">
|
||||
<div id="updatebar" style="display: none;">
|
||||
A <a
|
||||
href="https://github.com/${plexpy.CONFIG.GIT_USER}/plexpy/compare/${plexpy.CURRENT_VERSION}...${plexpy.LATEST_VERSION}">
|
||||
newer version</a> is available. You're ${plexpy.COMMITS_BEHIND} commits behind. <a href="update">Update</a> or
|
||||
<a href="#" onclick="$('#updatebar').slideUp('slow');">Close</a>
|
||||
<a href="#" id="updateDismiss">Close</a>
|
||||
</div>
|
||||
% endif
|
||||
<nav class="navbar navbar-fixed-top">
|
||||
@@ -104,6 +104,17 @@ ${next.body()}
|
||||
<script src="interfaces/default/js/jquery-2.1.4.min.js"></script>
|
||||
<script src="interfaces/default/js/bootstrap3/bootstrap.min.js"></script>
|
||||
<script src="interfaces/default/js/script.js"></script>
|
||||
<script>
|
||||
$('#updateDismiss').click(function() {
|
||||
$('#updatebar').slideUp('slow');
|
||||
// Set cookie to remember dismiss decision for 1 hour.
|
||||
setCookie('updateDismiss', 'true', 1/24);
|
||||
});
|
||||
|
||||
if (!getCookie('updateDismiss')) {
|
||||
$('#updatebar').show();
|
||||
}
|
||||
</script>
|
||||
${next.javascriptIncludes()}
|
||||
</body>
|
||||
</html>
|
||||
|
@@ -72,7 +72,7 @@ ul.ColVis_collection {
|
||||
width: 150px;
|
||||
padding: 8px 8px 4px 8px;
|
||||
margin: 10px 0px 0px 0px;
|
||||
background-color: rgba( 88, 88, 88, 0.8 );
|
||||
background-color: #444;
|
||||
overflow: hidden;
|
||||
z-index: 2002;
|
||||
}
|
||||
|
@@ -1368,7 +1368,7 @@ input[type="color"],
|
||||
}
|
||||
.stacked-configs > li > span > a.toggle-left {
|
||||
color: #444;
|
||||
padding-right: 2px;
|
||||
padding-right: 8px;
|
||||
}
|
||||
.stacked-configs > li > span > a:hover {
|
||||
color: #eee;
|
||||
@@ -1501,7 +1501,7 @@ input[type="color"],
|
||||
z-index: 9999;
|
||||
}
|
||||
#updatebar {
|
||||
background-color: rgba(255,255,255,0.075);
|
||||
background-color: #444;
|
||||
color: #999999;
|
||||
display: none;
|
||||
font-size: 14px;
|
||||
|
@@ -14,6 +14,7 @@ user Return the real Plex username
|
||||
user_id Return the Plex user_id
|
||||
friendly_name Returns the friendly edited Plex username
|
||||
do_notify Returns bool value for whether the user should trigger notifications
|
||||
keep_history Returns bool value for whether the user's activity should be logged
|
||||
|
||||
DOCUMENTATION :: END
|
||||
</%doc>
|
||||
@@ -30,18 +31,33 @@ DOCUMENTATION :: END
|
||||
<div class="form-group">
|
||||
<label for="friendly_name">Friendly Name</label>
|
||||
<div class="row">
|
||||
<div class="col-xs-6">
|
||||
<div class="col-md-6">
|
||||
<input type="text" class="form-control" id="friendly_name" name="friendly_name" value="${data['friendly_name']}" size="30">
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">Replace all occurances of the username with this name.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="profile_url">Profile Picture URL</label>
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<input type="text" class="form-control" id="profile_url" name="profile_url" value="${data['thumb']}">
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">Change the users profile picture in PlexPy. To reset to default, leave this field empty and save then perform a user refresh.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" id="do_notify" name="do_notify" value="1" ${data['do_notify']}> Enable notifications
|
||||
</label>
|
||||
<p class="help-block">Uncheck this if you do not want to receive notifications for this user's activity.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" id="keep_history" name="keep_history" value="1" ${data['keep_history']}> Keep history
|
||||
</label>
|
||||
<p class="help-block">Uncheck this if you do not want this keep any history on this user's activity.</p>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
@@ -56,15 +72,20 @@ DOCUMENTATION :: END
|
||||
// Set new friendly name
|
||||
$("#save_user_name").click(function() {
|
||||
var friendly_name = $("#friendly_name").val();
|
||||
var thumb = $("#profile_url").val();
|
||||
var do_notify = 0;
|
||||
var keep_history = 0;
|
||||
if ($("#do_notify").is(":checked")) {
|
||||
do_notify = 1;
|
||||
}
|
||||
if ($("#keep_history").is(":checked")) {
|
||||
keep_history = 1;
|
||||
}
|
||||
|
||||
% if data['user_id']:
|
||||
$.ajax({
|
||||
url: 'edit_user',
|
||||
data: {user_id: '${data['user_id']}', friendly_name: friendly_name, do_notify: do_notify},
|
||||
data: {user_id: '${data['user_id']}', friendly_name: friendly_name, do_notify: do_notify, keep_history: keep_history, thumb: thumb},
|
||||
cache: false,
|
||||
async: true,
|
||||
success: function(data) {
|
||||
@@ -72,12 +93,13 @@ DOCUMENTATION :: END
|
||||
if ($.trim(friendly_name) !== '') {
|
||||
$(".set-username").html(friendly_name);
|
||||
}
|
||||
$("#user-profile-thumb").attr('src', thumb);
|
||||
}
|
||||
});
|
||||
% else:
|
||||
$.ajax({
|
||||
url: 'edit_user',
|
||||
data: {user: '${data['user']}', friendly_name: friendly_name, do_notify: do_notify},
|
||||
data: {user: '${data['user']}', friendly_name: friendly_name, do_notify: do_notify, keep_history: keep_history, thumb: thumb},
|
||||
cache: false,
|
||||
async: true,
|
||||
success: function(data) {
|
||||
@@ -85,6 +107,7 @@ DOCUMENTATION :: END
|
||||
if ($.trim(friendly_name) !== '') {
|
||||
$(".set-username").html(friendly_name);
|
||||
}
|
||||
$("#user-profile-thumb").attr('src', thumb);
|
||||
}
|
||||
});
|
||||
% endif
|
||||
|
@@ -21,6 +21,9 @@
|
||||
</label>
|
||||
</div>
|
||||
<div class="btn-group" data-toggle="buttons" id="days-selection">
|
||||
<label class="btn btn-dark">
|
||||
<input type="radio" name="date-options" id="graph-7" value="7" autocomplete="off"> 7 days
|
||||
</label>
|
||||
<label class="btn btn-dark active">
|
||||
<input type="radio" name="date-options" id="graph-30" value="30" autocomplete="off" checked> 30 days
|
||||
</label>
|
||||
@@ -280,8 +283,8 @@
|
||||
if ((moment(data.categories[i], 'YYYY-MM-DD').format('ddd') == 'Sat') ||
|
||||
(moment(data.categories[i], 'YYYY-MM-DD').format('ddd') == 'Sun')) {
|
||||
hc_plays_by_day_options.xAxis.plotBands.push({
|
||||
from: i,
|
||||
to: i+1,
|
||||
from: i-0.5,
|
||||
to: i+0.5,
|
||||
color: 'rgba(80,80,80,0.3)'
|
||||
});
|
||||
}
|
||||
@@ -358,8 +361,8 @@
|
||||
if ((moment(data.categories[i], 'YYYY-MM-DD').format('ddd') == 'Sat') ||
|
||||
(moment(data.categories[i], 'YYYY-MM-DD').format('ddd') == 'Sun')) {
|
||||
hc_plays_by_stream_type_options.xAxis.plotBands.push({
|
||||
from: i,
|
||||
to: i+1,
|
||||
from: i-0.5,
|
||||
to: i+0.5,
|
||||
color: 'rgba(80,80,80,0.3)'
|
||||
});
|
||||
}
|
||||
|
@@ -39,11 +39,11 @@ platform_type Returns the platform name for the associated stat.
|
||||
DOCUMENTATION :: END
|
||||
</%doc>
|
||||
|
||||
% if data != None:
|
||||
% if data[0]['rows']:
|
||||
% if data:
|
||||
% if data[0]['rows'] or data[2]['rows']:
|
||||
<ul class="list-unstyled">
|
||||
% for a in data:
|
||||
% if a['stat_id'] == 'top_tv':
|
||||
% if a['stat_id'] == 'top_tv' and a['rows']:
|
||||
<div class="home-platforms-instance">
|
||||
<li>
|
||||
<span>
|
||||
@@ -68,7 +68,7 @@ DOCUMENTATION :: END
|
||||
</div>
|
||||
</li>
|
||||
</div>
|
||||
% elif a['stat_id'] == 'popular_tv':
|
||||
% elif a['stat_id'] == 'popular_tv' and a['rows']:
|
||||
<div class="home-platforms-instance">
|
||||
<li>
|
||||
<span>
|
||||
@@ -93,7 +93,32 @@ DOCUMENTATION :: END
|
||||
</div>
|
||||
</li>
|
||||
</div>
|
||||
% elif a['stat_id'] == 'top_users':
|
||||
% elif a['stat_id'] == 'top_movies' and a['rows']:
|
||||
<div class="home-platforms-instance">
|
||||
<li>
|
||||
<span>
|
||||
<a href="info?item_id=${a['rows'][0]['rating_key']}">
|
||||
% if a['rows'][0]['thumb']:
|
||||
<img class="home-platforms-instance-poster"
|
||||
src="pms_image_proxy?img=${a['rows'][0]['thumb']}&width=162&height=240&fallback=poster">
|
||||
% else:
|
||||
<img class="home-platforms-instance-poster" src="interfaces/default/images/poster.png">
|
||||
% endif
|
||||
</a>
|
||||
</span>
|
||||
<div class="home-platforms-instance-name">
|
||||
<h4>Most Watched Movie</h4>
|
||||
<h5><a href="info?item_id=${a['rows'][0]['rating_key']}">
|
||||
${a['rows'][0]['title']}
|
||||
</a></h5>
|
||||
</div>
|
||||
<div class="user-platforms-instance-playcount">
|
||||
<h3>${a['rows'][0]['total_plays']}</h3>
|
||||
<p> plays</p>
|
||||
</div>
|
||||
</li>
|
||||
</div>
|
||||
% elif a['stat_id'] == 'top_users' and a['rows']:
|
||||
<div class="home-platforms-instance">
|
||||
<li>
|
||||
<span>
|
||||
@@ -129,7 +154,7 @@ DOCUMENTATION :: END
|
||||
</div>
|
||||
</li>
|
||||
</div>
|
||||
% elif a['stat_id'] == 'top_platforms':
|
||||
% elif a['stat_id'] == 'top_platforms' and a['rows']:
|
||||
<div class="home-platforms-instance">
|
||||
<li>
|
||||
<div id="platform-stat">
|
||||
|
@@ -19,7 +19,7 @@
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="padded-header">
|
||||
<h3>Statistics <small>Last 30 days</small></h3>
|
||||
<h3>Statistics <small>Last ${config['home_stats_length']} days</small></h3>
|
||||
</div>
|
||||
<div id="home-stats" class="user-platforms">
|
||||
<div class='text-muted'><i class="fa fa-refresh fa-spin"></i> Loading stats...</div>
|
||||
@@ -110,7 +110,7 @@
|
||||
});
|
||||
});
|
||||
|
||||
getHomeStats(30);
|
||||
getHomeStats(${config['home_stats_length']});
|
||||
|
||||
|
||||
</script>
|
||||
|
@@ -27,6 +27,7 @@ users_list_table_options = {
|
||||
}
|
||||
},
|
||||
"orderable": false,
|
||||
"searchable": false,
|
||||
"className": "users-poster-face",
|
||||
"width": "40px"
|
||||
},
|
||||
@@ -47,21 +48,33 @@ users_list_table_options = {
|
||||
},
|
||||
{
|
||||
"targets": [2],
|
||||
"data": "started",
|
||||
"data": "last_seen",
|
||||
"render": function ( data, type, full ) {
|
||||
return moment(data, "X").fromNow();
|
||||
if (data) {
|
||||
return moment(data, "X").fromNow();
|
||||
} else {
|
||||
return "never";
|
||||
}
|
||||
},
|
||||
"searchable": false,
|
||||
"className": "hidden-xs",
|
||||
},
|
||||
{
|
||||
"targets": [3],
|
||||
"data": "ip_address",
|
||||
"searchable": false,
|
||||
"render": function ( data, type, full ) {
|
||||
if (data) {
|
||||
return data;
|
||||
} else {
|
||||
return "n/a";
|
||||
}
|
||||
},
|
||||
"className": "hidden-xs",
|
||||
},
|
||||
{
|
||||
"targets": [4],
|
||||
"data": "plays"
|
||||
"data": "plays",
|
||||
"searchable": false
|
||||
}
|
||||
|
||||
],
|
||||
|
98
data/interfaces/default/notification_triggers_modal.html
Normal file
98
data/interfaces/default/notification_triggers_modal.html
Normal file
@@ -0,0 +1,98 @@
|
||||
<%!
|
||||
from plexpy import helpers
|
||||
%>
|
||||
% if data:
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-remove"></i></button>
|
||||
<h4 class="modal-title" id="notification-triggers-modal-header">${data['name']} Notification Triggers</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<p class="help-block">
|
||||
Watched notifications are only applicable for video items.
|
||||
</p>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" data-size="small" data-id="${data['id']}" data-config-name="${data['config_prefix']}_on_play" ${helpers.checked(data['on_play'])} class="toggle-switches">
|
||||
Notify on playback start
|
||||
</label>
|
||||
<p class="help-block">Trigger notification when a new media item is started.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" data-size="small" data-id="${data['id']}" data-config-name="${data['config_prefix']}_on_stop" ${helpers.checked(data['on_stop'])} class="toggle-switches">
|
||||
Notify on playback stop
|
||||
</label>
|
||||
<p class="help-block">Trigger notification when a media item is stopped.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" data-size="small" data-id="${data['id']}" data-config-name="${data['config_prefix']}_on_pause" ${helpers.checked(data['on_pause'])} class="toggle-switches">
|
||||
Notify on playback pause
|
||||
</label>
|
||||
<p class="help-block">Trigger notification when a media item is paused.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" data-size="small" data-id="${data['id']}" data-config-name="${data['config_prefix']}_on_resume" ${helpers.checked(data['on_resume'])} class="toggle-switches">
|
||||
Notify on playback resume
|
||||
</label>
|
||||
<p class="help-block">Trigger notification when a media item is resumed from a paused state.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" data-size="small" data-id="${data['id']}" data-config-name="${data['config_prefix']}_on_watched" ${helpers.checked(data['on_watched'])} class="toggle-switches">
|
||||
Notify on watched
|
||||
</label>
|
||||
<p class="help-block">Trigger notification when a video item reaches the defined watch percentage.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" data-size="small" data-id="${data['id']}" data-config-name="${data['config_prefix']}_on_buffer" ${helpers.checked(data['on_buffer'])} class="toggle-switches">
|
||||
Notify on buffer warning
|
||||
</label>
|
||||
<p class="help-block">Trigger notification when a media item triggers the defined buffer threshold.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<input type="button" class="btn btn-bright" data-dismiss="modal" value="Close">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$('.toggle-switches').click(function() {
|
||||
var configToggle = $(this).data('id');
|
||||
var toggle = $(this);
|
||||
if ($(this).is(":checked")) {
|
||||
var data = {};
|
||||
data[$(this).data('config-name')] = 1;
|
||||
$.ajax({
|
||||
url: 'set_notification_config',
|
||||
data: data,
|
||||
async: true,
|
||||
success: function(data) {
|
||||
console.log('success');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var data = {};
|
||||
data[$(this).data('config-name')] = 0;
|
||||
$.ajax({
|
||||
url: 'set_notification_config',
|
||||
data: data,
|
||||
async: true,
|
||||
success: function(data) {
|
||||
console.log('success');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
% endif
|
@@ -15,6 +15,7 @@ type Returns the type of media. Either 'movie' or 'season'.
|
||||
thumb Returns the location of the item's thumbnail. Use with pms_image_proxy.
|
||||
added_at Returns the time when the media was added to the library.
|
||||
title Returns the name of the movie or season.
|
||||
parent_title Returns the name of the TV Show a season belongs too.
|
||||
|
||||
== Only if 'type' is 'movie' ==
|
||||
year Returns the movie release year.
|
||||
@@ -42,7 +43,9 @@ DOCUMENTATION :: END
|
||||
% endif
|
||||
</div>
|
||||
<div class="dashboard-recent-media-metacontainer">
|
||||
% if item['type'] == 'season' or item['type'] == 'album':
|
||||
% if item['type'] == 'season':
|
||||
<h3>${item['parent_title']} - ${item['title']}</h3>
|
||||
% elif item['type'] == 'album':
|
||||
<h3>${item['title']}</h3>
|
||||
% elif item['type'] == 'movie':
|
||||
<h3>${item['title']} (${item['year']})</h3>
|
||||
|
@@ -5,6 +5,8 @@ from plexpy import notifiers
|
||||
|
||||
available_notification_agents = notifiers.available_notification_agents()
|
||||
%>
|
||||
<%def name="headIncludes()">
|
||||
</%def>
|
||||
|
||||
<%def name="headerIncludes()">
|
||||
</%def>
|
||||
@@ -79,7 +81,7 @@ available_notification_agents = notifiers.available_notification_agents()
|
||||
</div>
|
||||
<p class="help-block">Set your preferred time format. <a href="javascript:void(0)" data-target="#dateTimeOptionsModal" data-toggle="modal">Click here</a> to see the parameter list.</p>
|
||||
</div>
|
||||
<input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully">
|
||||
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="tabs-2">
|
||||
<div class="padded-header">
|
||||
@@ -127,7 +129,7 @@ available_notification_agents = notifiers.available_notification_agents()
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully">
|
||||
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="tabs-3">
|
||||
|
||||
@@ -179,7 +181,7 @@ available_notification_agents = notifiers.available_notification_agents()
|
||||
<p class="help-block">Current API key: <strong><br/>${config['api_key']}</strong></p>
|
||||
</div>
|
||||
|
||||
<input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully">
|
||||
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="tabs-4">
|
||||
|
||||
@@ -260,7 +262,7 @@ available_notification_agents = notifiers.available_notification_agents()
|
||||
<p class="help-block">Refresh the user list when PlexPy starts.</p>
|
||||
</div>
|
||||
|
||||
<input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully">
|
||||
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="tabs-6">
|
||||
<div class="padded-header">
|
||||
@@ -274,6 +276,16 @@ available_notification_agents = notifiers.available_notification_agents()
|
||||
<p class="help-block">If you have media indexing enabled on your server, use these on the activity pane.</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="home_stats_length">Homepage Statistics Time Frame</label>
|
||||
<div class="row">
|
||||
<div class="col-md-2">
|
||||
<input type="text" class="form-control" data-parsley-type="integer" id="home_stats_length" name="home_stats_length" value="${config['home_stats_length']}" size="3" data-parsley-min="0" data-parsley-trigger="change" required>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">Specify the number of days for the statistics on the home page. Default is 30 days.</p>
|
||||
</div>
|
||||
|
||||
<div class="padded-header">
|
||||
<h3>Plex Logs</h3>
|
||||
</div>
|
||||
@@ -294,7 +306,7 @@ available_notification_agents = notifiers.available_notification_agents()
|
||||
</div>
|
||||
<p class="help-block"><a href="javascript:void(0)" id="toggle-plexwatch-import-modal" data-target="#plexwatch-import-modal" data-toggle="modal">Click here to Import an existing Plexwatch database.</a></p>
|
||||
|
||||
<input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully">
|
||||
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="tabs-7">
|
||||
|
||||
@@ -349,7 +361,30 @@ available_notification_agents = notifiers.available_notification_agents()
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully">
|
||||
<div class="padded-header">
|
||||
<h3>Buffer Warnings</h3>
|
||||
</div>
|
||||
<p class="help-block">Note: Buffer warnings only work on certain Plex clients. Android and PlexWeb do not report buffer events accurately or at all.</p>
|
||||
<div class="form-group">
|
||||
<label for="buffer_threshold">Buffer Threshold</label>
|
||||
<div class="row">
|
||||
<div class="col-md-2">
|
||||
<input type="text" class="form-control" data-parsley-type="integer" id="buffer_threshold" name="buffer_threshold" value="${config['buffer_threshold']}" data-parsley-range="[0,50]" data-parsley-trigger="change" required>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">How many buffer events should we wait before triggering the first warning. Buffer events increment on each monitor ping if play state is buffering. 0 to disable buffer warnings.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="buffer_wait">Buffer Wait</label>
|
||||
<div class="row">
|
||||
<div class="col-md-2">
|
||||
<input type="text" class="form-control" data-parsley-type="integer" id="buffer_wait" name="buffer_wait" value="${config['buffer_wait']}" data-parsley-min="0" data-parsley-trigger="change" required>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">The value (in seconds) PlexPy should wait before triggering the next buffer warning. 0 to always trigger.</p>
|
||||
</div>
|
||||
|
||||
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="tabs-8">
|
||||
|
||||
@@ -428,6 +463,40 @@ available_notification_agents = notifiers.available_notification_agents()
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<div class="link"><i class="fa fa-pause"></i>Playback Pause<i class="fa fa-chevron-down"></i></div>
|
||||
<ul class="submenu">
|
||||
<li>
|
||||
<div class="form-group">
|
||||
<label for="notify_on_pause_subject_text">Subject Line</label>
|
||||
<input class="form-control" type="text" id="notify_on_pause_subject_text" name="notify_on_pause_subject_text" value="${config['notify_on_pause_subject_text']}" data-parsley-trigger="change" required>
|
||||
<p class="help-block">Set a custom subject line.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="notify_on_pause_body_text">Message Body</label>
|
||||
<input class="form-control" type="text" id="notify_on_pause_body_text" name="notify_on_pause_body_text" value="${config['notify_on_pause_body_text']}" data-parsley-trigger="change" required>
|
||||
<p class="help-block">Set a custom body.</p>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<div class="link"><i class="fa fa-play"></i>Playback Resume<i class="fa fa-chevron-down"></i></div>
|
||||
<ul class="submenu">
|
||||
<li>
|
||||
<div class="form-group">
|
||||
<label for="notify_on_resume_subject_text">Subject Line</label>
|
||||
<input class="form-control" type="text" id="notify_on_resume_subject_text" name="notify_on_resume_subject_text" value="${config['notify_on_resume_subject_text']}" data-parsley-trigger="change" required>
|
||||
<p class="help-block">Set a custom subject line.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="notify_on_resume_body_text">Message Body</label>
|
||||
<input class="form-control" type="text" id="notify_on_resume_body_text" name="notify_on_resume_body_text" value="${config['notify_on_resume_body_text']}" data-parsley-trigger="change" required>
|
||||
<p class="help-block">Set a custom body.</p>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<div class="link"><i class="fa fa-eye"></i>Watched<i class="fa fa-chevron-down"></i></div>
|
||||
<ul class="submenu">
|
||||
@@ -445,9 +514,26 @@ available_notification_agents = notifiers.available_notification_agents()
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<div class="link"><i class="fa fa-spinner"></i>Buffer Warnings<i class="fa fa-chevron-down"></i></div>
|
||||
<ul class="submenu">
|
||||
<li>
|
||||
<div class="form-group">
|
||||
<label for="notify_on_buffer_subject_text">Subject Line</label>
|
||||
<input class="form-control" type="text" id="notify_on_buffer_subject_text" name="notify_on_buffer_subject_text" value="${config['notify_on_buffer_subject_text']}" data-parsley-trigger="change" required>
|
||||
<p class="help-block">Set a custom subject line.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="notify_on_buffer_body_text">Message Body</label>
|
||||
<input class="form-control" type="text" id="notify_on_buffer_body_text" name="notify_on_buffer_body_text" value="${config['notify_on_buffer_body_text']}" data-parsley-trigger="change" required>
|
||||
<p class="help-block">Set a custom body.</p>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully">
|
||||
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="tabs-9">
|
||||
|
||||
@@ -455,18 +541,18 @@ available_notification_agents = notifiers.available_notification_agents()
|
||||
<h3>Notification Agents</h3>
|
||||
</div>
|
||||
<p class="help-block">
|
||||
Toggle the desired notification option and configure it by selecting the settings icon to the right.
|
||||
Watched notifications are only applicable for video items.
|
||||
Toggle the desired notification options by clicking the bolt icon and configure it by selecting the settings icon to the right.
|
||||
</p>
|
||||
<br/>
|
||||
<ul class="stacked-configs list-unstyled">
|
||||
% for agent in available_notification_agents:
|
||||
<li>
|
||||
<span>
|
||||
<!--<input type="checkbox" name="${agent['config_prefix']}_enabled" id="${agent['config_prefix']}" value="1" ${agent['state']}> ${agent['name']}-->
|
||||
<a class="toggle-left notify-toggle-icon" href="javascript:void(0)" data-toggle="tooltip" data-placement="top" title data-title="Notify on playback start" data-id="${agent['id']}" data-config-name="${agent['config_prefix']}_on_play" data-config-value="${agent['on_play']}"><i class="fa fa-play"></i></a>
|
||||
<a class="toggle-left notify-toggle-icon" href="javascript:void(0)" data-toggle="tooltip" data-placement="top" title data-title="Notify on stop" data-id="${agent['id']}" data-config-name="${agent['config_prefix']}_on_stop" data-config-value="${agent['on_stop']}"><i class="fa fa-stop"></i></a>
|
||||
<a class="toggle-left notify-toggle-icon" href="javascript:void(0)" data-toggle="tooltip" data-placement="top" title data-title="Notify on watched" data-id="${agent['id']}" data-config-name="${agent['config_prefix']}_on_watched" data-config-value="${agent['on_watched']}"><i class="fa fa-eye"></i></a>
|
||||
% if agent['on_play'] or agent['on_stop'] or agent['on_pause'] or agent['on_resume'] or agent['on_buffer'] or agent['on_watched']:
|
||||
<a href="javascript:void(0)" data-target="#notification-triggers-modal" data-id="${agent['id']}" class="toggle-notification-triggers-modal toggle-left active" data-toggle="modal"><i class="fa fa-lg fa-flash"></i></a>
|
||||
% else:
|
||||
<a href="javascript:void(0)" data-target="#notification-triggers-modal" data-id="${agent['id']}" class="toggle-notification-triggers-modal toggle-left" data-toggle="modal"><i class="fa fa-lg fa-flash"></i></a>
|
||||
% endif
|
||||
${agent['name']}
|
||||
% if agent['has_config']:
|
||||
<a href="javascript:void(0)" rel="tooltip" data-target="#notification-config-modal" data-placement="top" title data-title="Open configuration" data-id="${agent['id']}" class="toggle-notification-config-modal toggle-right" data-toggle="modal"><i class="fa fa-lg fa-cog"></i></a>
|
||||
@@ -651,7 +737,8 @@ available_notification_agents = notifiers.available_notification_agents()
|
||||
</div>
|
||||
</div>
|
||||
<div id="plexwatch-import-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="plexwatch-import-modal"></div>
|
||||
<div id="notification-config-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="notification-setting-modal"></div>
|
||||
<div id="notification-config-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="notification-config-modal"></div>
|
||||
<div id="notification-triggers-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="notification-triggers-modal"></div>
|
||||
<div id="notify-text-sub-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="notify-text-sub-modal">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
@@ -834,6 +921,8 @@ $(document).ready(function() {
|
||||
});
|
||||
|
||||
$("#menu_link_update_check").click(function() {
|
||||
// Allow the update bar to show again if previously dismissed.
|
||||
setCookie('updateDismiss', 'true', 0);
|
||||
$(this).html('<i class="fa fa-spin fa-refresh"></i> Checking</button>');
|
||||
$(this).prop('disabled', true);
|
||||
window.location.href = "checkGithub";
|
||||
@@ -965,7 +1054,7 @@ $(document).ready(function() {
|
||||
});
|
||||
});
|
||||
|
||||
// Load PlexWatch import modal
|
||||
// Load notification agent config modal
|
||||
$(".toggle-notification-config-modal").click(function() {
|
||||
var configId = $(this).data('id');
|
||||
$.ajax({
|
||||
@@ -979,100 +1068,18 @@ $(document).ready(function() {
|
||||
});
|
||||
});
|
||||
|
||||
$('.notify-toggle-icon').tooltip();
|
||||
|
||||
$('.notify-toggle-icon').each(function() {
|
||||
if ($(this).data('config-value') == 1) {
|
||||
$(this).addClass("active");
|
||||
}
|
||||
});
|
||||
|
||||
$('.notify-toggle-icon').click(function() {
|
||||
var configToggle = $(this).data('id');
|
||||
var toggle = $(this);
|
||||
if ($(this).hasClass("active")) {
|
||||
var data = {};
|
||||
data[$(this).data('config-name')] = 0;
|
||||
$.ajax({
|
||||
url: 'set_notification_config',
|
||||
data: data,
|
||||
async: true,
|
||||
success: function(data) {
|
||||
toggle.removeClass("active");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var data = {};
|
||||
data[$(this).data('config-name')] = 1;
|
||||
$.ajax({
|
||||
url: 'set_notification_config',
|
||||
data: data,
|
||||
async: true,
|
||||
success: function(data) {
|
||||
toggle.addClass("active");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if ($("#tv_notify_enable").is(":checked"))
|
||||
{
|
||||
$("#tv_notify_options").show();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#tv_notify_options").hide();
|
||||
}
|
||||
|
||||
$("#tv_notify_enable").click(function(){
|
||||
if ($("#tv_notify_enable").is(":checked"))
|
||||
{
|
||||
$("#tv_notify_options").slideDown();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#tv_notify_options").slideUp();
|
||||
}
|
||||
});
|
||||
|
||||
if ($("#movie_notify_enable").is(":checked"))
|
||||
{
|
||||
$("#movie_notify_options").show();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#movie_notify_options").hide();
|
||||
}
|
||||
|
||||
$("#movie_notify_enable").click(function(){
|
||||
if ($("#movie_notify_enable").is(":checked"))
|
||||
{
|
||||
$("#movie_notify_options").slideDown();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#movie_notify_options").slideUp();
|
||||
}
|
||||
});
|
||||
|
||||
if ($("#music_notify_enable").is(":checked"))
|
||||
{
|
||||
$("#music_notify_options").show();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#music_notify_options").hide();
|
||||
}
|
||||
|
||||
$("#music_notify_enable").click(function(){
|
||||
if ($("#music_notify_enable").is(":checked"))
|
||||
{
|
||||
$("#music_notify_options").slideDown();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#music_notify_options").slideUp();
|
||||
// Load notification triggers config modal
|
||||
$(".toggle-notification-triggers-modal").click(function() {
|
||||
var configId = $(this).data('id');
|
||||
$.ajax({
|
||||
url: 'get_notification_agent_triggers',
|
||||
data: { config_id: configId },
|
||||
cache: false,
|
||||
async: true,
|
||||
complete: function(xhr, status) {
|
||||
$("#notification-triggers-modal").html(xhr.responseText);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#osxnotifyregister').click(function () {
|
||||
|
@@ -41,7 +41,7 @@ from plexpy import helpers
|
||||
<div class="table-card-back">
|
||||
<div class="user-info-wrapper">
|
||||
<div class="user-info-poster-face" id="user-gravatar">
|
||||
<img src="${data['thumb']}" height="80px" width="80px">
|
||||
<img id="user-profile-thumb" src="${data['thumb']}" height="80px" width="80px">
|
||||
</div>
|
||||
<div class="user-info-username">
|
||||
<span class="set-username">${data['friendly_name']}</span> <span id="edit-user-tooltip" data-target="tooltip" title="Edit user details"><a href="#" data-toggle="modal" data-target="#edit-user-modal" id="toggle-edit-user-modal"><i class="fa fa-pencil"></i></a></span>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<div class='container-fluid'>
|
||||
<div class='table-card-header'>
|
||||
<div class="header-bar">
|
||||
<span><i class="fa fa-group"></i> Active Users</span>
|
||||
<span><i class="fa fa-group"></i> All Users</span>
|
||||
</div>
|
||||
<div class="button-bar">
|
||||
<button class="btn btn-dark" id="refresh-users-list"><i class="fa fa-refresh"></i> Refresh users</button>
|
||||
|
@@ -348,7 +348,8 @@ def dbcheck():
|
||||
'bitrate INTEGER, video_resolution TEXT, video_framerate TEXT, aspect_ratio TEXT, '
|
||||
'audio_channels INTEGER, transcode_protocol TEXT, transcode_container TEXT, '
|
||||
'transcode_video_codec TEXT, transcode_audio_codec TEXT, transcode_audio_channels INTEGER,'
|
||||
'transcode_width INTEGER, transcode_height INTEGER)'
|
||||
'transcode_width INTEGER, transcode_height INTEGER, buffer_count INTEGER DEFAULT 0, '
|
||||
'buffer_last_triggered INTEGER)'
|
||||
)
|
||||
|
||||
# session_history table :: This is a history table which logs essential stream details
|
||||
@@ -386,7 +387,8 @@ def dbcheck():
|
||||
'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
||||
'user_id INTEGER DEFAULT NULL UNIQUE, username TEXT NOT NULL UNIQUE, '
|
||||
'friendly_name TEXT, thumb TEXT, email TEXT, is_home_user INTEGER DEFAULT NULL, '
|
||||
'is_allow_sync INTEGER DEFAULT NULL, is_restricted INTEGER DEFAULT NULL, do_notify INTEGER DEFAULT 1)'
|
||||
'is_allow_sync INTEGER DEFAULT NULL, is_restricted INTEGER DEFAULT NULL, do_notify INTEGER DEFAULT 1, '
|
||||
'keep_history INTEGER DEFAULT 1, custom_avatar_url TEXT)'
|
||||
)
|
||||
|
||||
# Upgrade sessions table from earlier versions
|
||||
@@ -528,18 +530,64 @@ def dbcheck():
|
||||
c_db.execute(
|
||||
'CREATE TABLE IF NOT EXISTS notify_log (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
||||
'session_key INTEGER, rating_key INTEGER, user_id INTEGER, user TEXT, '
|
||||
'agent_id INTEGER, agent_name TEXT, on_play INTEGER, on_stop INTEGER, on_watched INTEGER)'
|
||||
'agent_id INTEGER, agent_name TEXT, on_play INTEGER, on_stop INTEGER, on_watched INTEGER, '
|
||||
'on_pause INTEGER, on_resume INTEGER, on_buffer INTEGER)'
|
||||
)
|
||||
|
||||
# Upgrade sessions table from earlier versions
|
||||
# Upgrade users table from earlier versions
|
||||
try:
|
||||
c_db.execute('SELECT do_notify from users')
|
||||
except sqlite3.OperationalError:
|
||||
logger.debug(u"Altering database. Updating database table sessions.")
|
||||
logger.debug(u"Altering database. Updating database table users.")
|
||||
c_db.execute(
|
||||
'ALTER TABLE users ADD COLUMN do_notify INTEGER DEFAULT 1'
|
||||
)
|
||||
|
||||
# Upgrade users table from earlier versions
|
||||
try:
|
||||
c_db.execute('SELECT keep_history from users')
|
||||
except sqlite3.OperationalError:
|
||||
logger.debug(u"Altering database. Updating database table users.")
|
||||
c_db.execute(
|
||||
'ALTER TABLE users ADD COLUMN keep_history INTEGER DEFAULT 1'
|
||||
)
|
||||
|
||||
# Upgrade notify_log table from earlier versions
|
||||
try:
|
||||
c_db.execute('SELECT on_pause from notify_log')
|
||||
except sqlite3.OperationalError:
|
||||
logger.debug(u"Altering database. Updating database table notify_log.")
|
||||
c_db.execute(
|
||||
'ALTER TABLE notify_log ADD COLUMN on_pause INTEGER'
|
||||
)
|
||||
c_db.execute(
|
||||
'ALTER TABLE notify_log ADD COLUMN on_resume INTEGER'
|
||||
)
|
||||
c_db.execute(
|
||||
'ALTER TABLE notify_log ADD COLUMN on_buffer INTEGER'
|
||||
)
|
||||
|
||||
# Upgrade sessions table from earlier versions
|
||||
try:
|
||||
c_db.execute('SELECT buffer_count from sessions')
|
||||
except sqlite3.OperationalError:
|
||||
logger.debug(u"Altering database. Updating database table sessions.")
|
||||
c_db.execute(
|
||||
'ALTER TABLE sessions ADD COLUMN buffer_count INTEGER DEFAULT 0'
|
||||
)
|
||||
c_db.execute(
|
||||
'ALTER TABLE sessions ADD COLUMN buffer_last_triggered INTEGER'
|
||||
)
|
||||
|
||||
# Upgrade users table from earlier versions
|
||||
try:
|
||||
c_db.execute('SELECT custom_avatar_url from users')
|
||||
except sqlite3.OperationalError:
|
||||
logger.debug(u"Altering database. Updating database table users.")
|
||||
c_db.execute(
|
||||
'ALTER TABLE users ADD COLUMN custom_avatar_url TEXT'
|
||||
)
|
||||
|
||||
conn_db.commit()
|
||||
c_db.close()
|
||||
|
||||
|
@@ -39,7 +39,12 @@ _CONFIG_DEFINITIONS = {
|
||||
'BOXCAR_TOKEN': (str, 'Boxcar', ''),
|
||||
'BOXCAR_ON_PLAY': (int, 'Boxcar', 0),
|
||||
'BOXCAR_ON_STOP': (int, 'Boxcar', 0),
|
||||
'BOXCAR_ON_PAUSE': (int, 'Boxcar', 0),
|
||||
'BOXCAR_ON_RESUME': (int, 'Boxcar', 0),
|
||||
'BOXCAR_ON_BUFFER': (int, 'Boxcar', 0),
|
||||
'BOXCAR_ON_WATCHED': (int, 'Boxcar', 0),
|
||||
'BUFFER_THRESHOLD': (int, 'Monitoring', 3),
|
||||
'BUFFER_WAIT': (int, 'Monitoring', 900),
|
||||
'CACHE_DIR': (str, 'General', ''),
|
||||
'CACHE_SIZEMB': (int, 'Advanced', 32),
|
||||
'CHECK_GITHUB': (int, 'General', 1),
|
||||
@@ -58,6 +63,9 @@ _CONFIG_DEFINITIONS = {
|
||||
'EMAIL_TLS': (int, 'Email', 0),
|
||||
'EMAIL_ON_PLAY': (int, 'Email', 0),
|
||||
'EMAIL_ON_STOP': (int, 'Email', 0),
|
||||
'EMAIL_ON_PAUSE': (int, 'Email', 0),
|
||||
'EMAIL_ON_RESUME': (int, 'Email', 0),
|
||||
'EMAIL_ON_BUFFER': (int, 'Email', 0),
|
||||
'EMAIL_ON_WATCHED': (int, 'Email', 0),
|
||||
'ENABLE_HTTPS': (int, 'General', 0),
|
||||
'FIRST_RUN_COMPLETE': (int, 'General', 0),
|
||||
@@ -70,7 +78,11 @@ _CONFIG_DEFINITIONS = {
|
||||
'GROWL_PASSWORD': (str, 'Growl', ''),
|
||||
'GROWL_ON_PLAY': (int, 'Growl', 0),
|
||||
'GROWL_ON_STOP': (int, 'Growl', 0),
|
||||
'GROWL_ON_PAUSE': (int, 'Growl', 0),
|
||||
'GROWL_ON_RESUME': (int, 'Growl', 0),
|
||||
'GROWL_ON_BUFFER': (int, 'Growl', 0),
|
||||
'GROWL_ON_WATCHED': (int, 'Growl', 0),
|
||||
'HOME_STATS_LENGTH': (int, 'General', 30),
|
||||
'HTTPS_CERT': (str, 'General', ''),
|
||||
'HTTPS_KEY': (str, 'General', ''),
|
||||
'HTTP_HOST': (str, 'General', '0.0.0.0'),
|
||||
@@ -100,18 +112,30 @@ _CONFIG_DEFINITIONS = {
|
||||
'NMA_PRIORITY': (int, 'NMA', 0),
|
||||
'NMA_ON_PLAY': (int, 'NMA', 0),
|
||||
'NMA_ON_STOP': (int, 'NMA', 0),
|
||||
'NMA_ON_PAUSE': (int, 'NMA', 0),
|
||||
'NMA_ON_RESUME': (int, 'NMA', 0),
|
||||
'NMA_ON_BUFFER': (int, 'NMA', 0),
|
||||
'NMA_ON_WATCHED': (int, 'NMA', 0),
|
||||
'NOTIFY_WATCHED_PERCENT': (int, 'Monitoring', 85),
|
||||
'NOTIFY_ON_START_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
|
||||
'NOTIFY_ON_START_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) started playing {title}.'),
|
||||
'NOTIFY_ON_STOP_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
|
||||
'NOTIFY_ON_STOP_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has stopped {title}.'),
|
||||
'NOTIFY_ON_PAUSE_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
|
||||
'NOTIFY_ON_PAUSE_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has paused {title}.'),
|
||||
'NOTIFY_ON_RESUME_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
|
||||
'NOTIFY_ON_RESUME_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has resumed {title}.'),
|
||||
'NOTIFY_ON_BUFFER_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
|
||||
'NOTIFY_ON_BUFFER_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) is buffering {title}.'),
|
||||
'NOTIFY_ON_WATCHED_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
|
||||
'NOTIFY_ON_WATCHED_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has watched {title}.'),
|
||||
'OSX_NOTIFY_APP': (str, 'OSX_Notify', '/Applications/PlexPy'),
|
||||
'OSX_NOTIFY_ENABLED': (int, 'OSX_Notify', 0),
|
||||
'OSX_NOTIFY_ON_PLAY': (int, 'OSX_Notify', 0),
|
||||
'OSX_NOTIFY_ON_STOP': (int, 'OSX_Notify', 0),
|
||||
'OSX_NOTIFY_ON_PAUSE': (int, 'OSX_Notify', 0),
|
||||
'OSX_NOTIFY_ON_RESUME': (int, 'OSX_Notify', 0),
|
||||
'OSX_NOTIFY_ON_BUFFER': (int, 'OSX_Notify', 0),
|
||||
'OSX_NOTIFY_ON_WATCHED': (int, 'OSX_Notify', 0),
|
||||
'PLEX_CLIENT_HOST': (str, 'Plex', ''),
|
||||
'PLEX_ENABLED': (int, 'Plex', 0),
|
||||
@@ -119,17 +143,26 @@ _CONFIG_DEFINITIONS = {
|
||||
'PLEX_USERNAME': (str, 'Plex', ''),
|
||||
'PLEX_ON_PLAY': (int, 'Plex', 0),
|
||||
'PLEX_ON_STOP': (int, 'Plex', 0),
|
||||
'PLEX_ON_PAUSE': (int, 'Plex', 0),
|
||||
'PLEX_ON_RESUME': (int, 'Plex', 0),
|
||||
'PLEX_ON_BUFFER': (int, 'Plex', 0),
|
||||
'PLEX_ON_WATCHED': (int, 'Plex', 0),
|
||||
'PROWL_ENABLED': (int, 'Prowl', 0),
|
||||
'PROWL_KEYS': (str, 'Prowl', ''),
|
||||
'PROWL_PRIORITY': (int, 'Prowl', 0),
|
||||
'PROWL_ON_PLAY': (int, 'Prowl', 0),
|
||||
'PROWL_ON_STOP': (int, 'Prowl', 0),
|
||||
'PROWL_ON_PAUSE': (int, 'Prowl', 0),
|
||||
'PROWL_ON_RESUME': (int, 'Prowl', 0),
|
||||
'PROWL_ON_BUFFER': (int, 'Prowl', 0),
|
||||
'PROWL_ON_WATCHED': (int, 'Prowl', 0),
|
||||
'PUSHALOT_APIKEY': (str, 'Pushalot', ''),
|
||||
'PUSHALOT_ENABLED': (int, 'Pushalot', 0),
|
||||
'PUSHALOT_ON_PLAY': (int, 'Pushalot', 0),
|
||||
'PUSHALOT_ON_STOP': (int, 'Pushalot', 0),
|
||||
'PUSHALOT_ON_PAUSE': (int, 'Pushalot', 0),
|
||||
'PUSHALOT_ON_RESUME': (int, 'Pushalot', 0),
|
||||
'PUSHALOT_ON_BUFFER': (int, 'Pushalot', 0),
|
||||
'PUSHALOT_ON_WATCHED': (int, 'Pushalot', 0),
|
||||
'PUSHBULLET_APIKEY': (str, 'PushBullet', ''),
|
||||
'PUSHBULLET_DEVICEID': (str, 'PushBullet', ''),
|
||||
@@ -137,6 +170,9 @@ _CONFIG_DEFINITIONS = {
|
||||
'PUSHBULLET_ENABLED': (int, 'PushBullet', 0),
|
||||
'PUSHBULLET_ON_PLAY': (int, 'PushBullet', 0),
|
||||
'PUSHBULLET_ON_STOP': (int, 'PushBullet', 0),
|
||||
'PUSHBULLET_ON_PAUSE': (int, 'PushBullet', 0),
|
||||
'PUSHBULLET_ON_RESUME': (int, 'PushBullet', 0),
|
||||
'PUSHBULLET_ON_BUFFER': (int, 'PushBullet', 0),
|
||||
'PUSHBULLET_ON_WATCHED': (int, 'PushBullet', 0),
|
||||
'PUSHOVER_APITOKEN': (str, 'Pushover', ''),
|
||||
'PUSHOVER_ENABLED': (int, 'Pushover', 0),
|
||||
@@ -144,6 +180,9 @@ _CONFIG_DEFINITIONS = {
|
||||
'PUSHOVER_PRIORITY': (int, 'Pushover', 0),
|
||||
'PUSHOVER_ON_PLAY': (int, 'Pushover', 0),
|
||||
'PUSHOVER_ON_STOP': (int, 'Pushover', 0),
|
||||
'PUSHOVER_ON_PAUSE': (int, 'Pushover', 0),
|
||||
'PUSHOVER_ON_RESUME': (int, 'Pushover', 0),
|
||||
'PUSHOVER_ON_BUFFER': (int, 'Pushover', 0),
|
||||
'PUSHOVER_ON_WATCHED': (int, 'Pushover', 0),
|
||||
'REFRESH_USERS_INTERVAL': (int, 'Monitoring', 12),
|
||||
'REFRESH_USERS_ON_STARTUP': (int, 'Monitoring', 1),
|
||||
@@ -164,6 +203,9 @@ _CONFIG_DEFINITIONS = {
|
||||
'XBMC_USERNAME': (str, 'XBMC', ''),
|
||||
'XBMC_ON_PLAY': (int, 'XBMC', 0),
|
||||
'XBMC_ON_STOP': (int, 'XBMC', 0),
|
||||
'XBMC_ON_PAUSE': (int, 'XBMC', 0),
|
||||
'XBMC_ON_RESUME': (int, 'XBMC', 0),
|
||||
'XBMC_ON_BUFFER': (int, 'XBMC', 0),
|
||||
'XBMC_ON_WATCHED': (int, 'XBMC', 0)
|
||||
}
|
||||
# pylint:disable=R0902
|
||||
|
@@ -26,67 +26,6 @@ class DataFactory(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def get_user_list(self, kwargs=None):
|
||||
data_tables = datatables.DataTables()
|
||||
|
||||
columns = ['session_history.id',
|
||||
'users.thumb as thumb',
|
||||
'(case when users.friendly_name is null then session_history.user else \
|
||||
users.friendly_name end) as friendly_name',
|
||||
'session_history.started',
|
||||
'session_history.ip_address',
|
||||
'COUNT(session_history.id) as plays',
|
||||
'session_history.user',
|
||||
'session_history.user_id',
|
||||
'(case when typeof(session_history.user_id) = "integer" \
|
||||
then session_history.user_id else -1 end) as grp_id',
|
||||
]
|
||||
try:
|
||||
query = data_tables.ssp_query(table_name='session_history',
|
||||
columns=columns,
|
||||
custom_where=[],
|
||||
group_by=['grp_id'],
|
||||
join_types=['LEFT OUTER JOIN'],
|
||||
join_tables=['users'],
|
||||
join_evals=[['grp_id', 'users.user_id']],
|
||||
kwargs=kwargs)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
return {'recordsFiltered': 0,
|
||||
'recordsTotal': 0,
|
||||
'draw': 0,
|
||||
'data': 'null',
|
||||
'error': 'Unable to execute database query.'}
|
||||
|
||||
users = query['result']
|
||||
|
||||
rows = []
|
||||
for item in users:
|
||||
if not item['thumb'] or item['thumb'] == '':
|
||||
user_thumb = common.DEFAULT_USER_THUMB
|
||||
else:
|
||||
user_thumb = item['thumb']
|
||||
|
||||
row = {"id": item['id'],
|
||||
"plays": item['plays'],
|
||||
"started": item['started'],
|
||||
"friendly_name": item["friendly_name"],
|
||||
"ip_address": item["ip_address"],
|
||||
"thumb": user_thumb,
|
||||
"user": item["user"],
|
||||
"user_id": item['user_id']
|
||||
}
|
||||
|
||||
rows.append(row)
|
||||
|
||||
dict = {'recordsFiltered': query['filteredCount'],
|
||||
'recordsTotal': query['totalCount'],
|
||||
'data': rows,
|
||||
'draw': query['draw']
|
||||
}
|
||||
|
||||
return dict
|
||||
|
||||
def get_history(self, kwargs=None, custom_where=None):
|
||||
data_tables = datatables.DataTables()
|
||||
|
||||
@@ -171,275 +110,14 @@ class DataFactory(object):
|
||||
|
||||
return dict
|
||||
|
||||
def get_user_unique_ips(self, kwargs=None, custom_where=None):
|
||||
data_tables = datatables.DataTables()
|
||||
|
||||
columns = ['session_history.started as last_seen',
|
||||
'session_history.ip_address as ip_address',
|
||||
'COUNT(session_history.id) as play_count',
|
||||
'session_history.player as platform',
|
||||
'session_history_metadata.full_title as last_watched',
|
||||
'session_history.user as user',
|
||||
'session_history.user_id as user_id'
|
||||
]
|
||||
|
||||
try:
|
||||
query = data_tables.ssp_query(table_name='session_history',
|
||||
columns=columns,
|
||||
custom_where=custom_where,
|
||||
group_by=['ip_address'],
|
||||
join_types=['JOIN'],
|
||||
join_tables=['session_history_metadata'],
|
||||
join_evals=[['session_history.id', 'session_history_metadata.id']],
|
||||
kwargs=kwargs)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
return {'recordsFiltered': 0,
|
||||
'recordsTotal': 0,
|
||||
'draw': 0,
|
||||
'data': 'null',
|
||||
'error': 'Unable to execute database query.'}
|
||||
|
||||
results = query['result']
|
||||
|
||||
rows = []
|
||||
for item in results:
|
||||
row = {"last_seen": item['last_seen'],
|
||||
"ip_address": item['ip_address'],
|
||||
"play_count": item['play_count'],
|
||||
"platform": item['platform'],
|
||||
"last_watched": item['last_watched']
|
||||
}
|
||||
|
||||
rows.append(row)
|
||||
|
||||
dict = {'recordsFiltered': query['filteredCount'],
|
||||
'recordsTotal': query['totalCount'],
|
||||
'data': rows,
|
||||
'draw': query['draw']
|
||||
}
|
||||
|
||||
return dict
|
||||
|
||||
# TODO: The getter and setter for this needs to become a config getter/setter for more than just friendlyname
|
||||
def set_user_friendly_name(self, user=None, user_id=None, friendly_name=None, do_notify=0):
|
||||
if user_id:
|
||||
if friendly_name.strip() == '':
|
||||
friendly_name = None
|
||||
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
control_value_dict = {"user_id": user_id}
|
||||
new_value_dict = {"friendly_name": friendly_name,
|
||||
"do_notify": do_notify}
|
||||
try:
|
||||
monitor_db.upsert('users', new_value_dict, control_value_dict)
|
||||
except Exception, e:
|
||||
logger.debug(u"Uncaught exception %s" % e)
|
||||
if user:
|
||||
if friendly_name.strip() == '':
|
||||
friendly_name = None
|
||||
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
control_value_dict = {"username": user}
|
||||
new_value_dict = {"friendly_name": friendly_name,
|
||||
"do_notify": do_notify}
|
||||
try:
|
||||
monitor_db.upsert('users', new_value_dict, control_value_dict)
|
||||
except Exception, e:
|
||||
logger.debug(u"Uncaught exception %s" % e)
|
||||
|
||||
def get_user_friendly_name(self, user=None, user_id=None):
|
||||
if user_id:
|
||||
monitor_db = database.MonitorDatabase()
|
||||
query = 'select username, ' \
|
||||
'(CASE WHEN friendly_name IS NULL THEN username ELSE friendly_name END),' \
|
||||
'do_notify ' \
|
||||
'FROM users WHERE user_id = ?'
|
||||
result = monitor_db.select(query, args=[user_id])
|
||||
if result:
|
||||
user_detail = {'user_id': user_id,
|
||||
'user': result[0][0],
|
||||
'friendly_name': result[0][1],
|
||||
'do_notify': helpers.checked(result[0][2])}
|
||||
return user_detail
|
||||
else:
|
||||
user_detail = {'user_id': user_id,
|
||||
'user': '',
|
||||
'friendly_name': '',
|
||||
'do_notify': ''}
|
||||
return user_detail
|
||||
elif user:
|
||||
monitor_db = database.MonitorDatabase()
|
||||
query = 'select user_id, ' \
|
||||
'(CASE WHEN friendly_name IS NULL THEN username ELSE friendly_name END),' \
|
||||
'do_notify ' \
|
||||
'FROM users WHERE username = ?'
|
||||
result = monitor_db.select(query, args=[user])
|
||||
if result:
|
||||
user_detail = {'user_id': result[0][0],
|
||||
'user': user,
|
||||
'friendly_name': result[0][1],
|
||||
'do_notify': helpers.checked(result[0][2])}
|
||||
return user_detail
|
||||
else:
|
||||
user_detail = {'user_id': None,
|
||||
'user': user,
|
||||
'friendly_name': '',
|
||||
'do_notify': ''}
|
||||
return user_detail
|
||||
|
||||
return None
|
||||
|
||||
def get_user_id(self, user=None):
|
||||
if user:
|
||||
try:
|
||||
monitor_db = database.MonitorDatabase()
|
||||
query = 'select user_id FROM users WHERE username = ?'
|
||||
result = monitor_db.select_single(query, args=[user])
|
||||
if result:
|
||||
return result
|
||||
else:
|
||||
return None
|
||||
except:
|
||||
return None
|
||||
|
||||
return None
|
||||
|
||||
def get_user_details(self, user=None, user_id=None):
|
||||
from plexpy import plextv
|
||||
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
if user:
|
||||
query = 'SELECT user_id, username, friendly_name, email, ' \
|
||||
'thumb, is_home_user, is_allow_sync, is_restricted, do_notify ' \
|
||||
'FROM users ' \
|
||||
'WHERE username = ? ' \
|
||||
'UNION ALL ' \
|
||||
'SELECT null, user, null, null, null, null, null, null, null ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE user = ? ' \
|
||||
'GROUP BY user ' \
|
||||
'LIMIT 1'
|
||||
result = monitor_db.select(query, args=[user, user])
|
||||
elif user_id:
|
||||
query = 'SELECT user_id, username, friendly_name, email, ' \
|
||||
'thumb, is_home_user, is_allow_sync, is_restricted, do_notify ' \
|
||||
'FROM users ' \
|
||||
'WHERE user_id = ? ' \
|
||||
'UNION ALL ' \
|
||||
'SELECT user_id, user, null, null, null, null, null, null, null ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE user_id = ? ' \
|
||||
'GROUP BY user ' \
|
||||
'LIMIT 1'
|
||||
result = monitor_db.select(query, args=[user_id, user_id])
|
||||
else:
|
||||
result = None
|
||||
|
||||
if result:
|
||||
user_details = {}
|
||||
for item in result:
|
||||
if not item['friendly_name']:
|
||||
friendly_name = item['username']
|
||||
else:
|
||||
friendly_name = item['friendly_name']
|
||||
if not item['thumb'] or item['thumb'] == '':
|
||||
user_thumb = common.DEFAULT_USER_THUMB
|
||||
else:
|
||||
user_thumb = item['thumb']
|
||||
|
||||
user_details = {"user_id": item['user_id'],
|
||||
"username": item['username'],
|
||||
"friendly_name": friendly_name,
|
||||
"email": item['email'],
|
||||
"thumb": user_thumb,
|
||||
"is_home_user": item['is_home_user'],
|
||||
"is_allow_sync": item['is_allow_sync'],
|
||||
"is_restricted": item['is_restricted'],
|
||||
"do_notify": item['do_notify']
|
||||
}
|
||||
return user_details
|
||||
else:
|
||||
logger.warn(u"PlexPy :: Unable to retrieve user from local database. Requesting user list refresh.")
|
||||
# Let's first refresh the user list to make sure the user isn't newly added and not in the db yet
|
||||
if user:
|
||||
# Refresh users
|
||||
plextv.refresh_users()
|
||||
query = 'SELECT user_id, username, friendly_name, email, ' \
|
||||
'thumb, is_home_user, is_allow_sync, is_restricted, do_notify ' \
|
||||
'FROM users ' \
|
||||
'WHERE username = ? ' \
|
||||
'UNION ALL ' \
|
||||
'SELECT null, user, null, null, null, null, null, null, null ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE user = ? ' \
|
||||
'GROUP BY user ' \
|
||||
'LIMIT 1'
|
||||
result = monitor_db.select(query, args=[user, user])
|
||||
elif user_id:
|
||||
# Refresh users
|
||||
plextv.refresh_users()
|
||||
query = 'SELECT user_id, username, friendly_name, email, ' \
|
||||
'thumb, is_home_user, is_allow_sync, is_restricted, do_notify ' \
|
||||
'FROM users ' \
|
||||
'WHERE user_id = ? ' \
|
||||
'UNION ALL ' \
|
||||
'SELECT user_id, user, null, null, null, null, null, null, null ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE user_id = ? ' \
|
||||
'GROUP BY user ' \
|
||||
'LIMIT 1'
|
||||
result = monitor_db.select(query, args=[user_id, user_id])
|
||||
else:
|
||||
result = None
|
||||
|
||||
if result:
|
||||
user_details = {}
|
||||
for item in result:
|
||||
if not item['friendly_name']:
|
||||
friendly_name = item['username']
|
||||
else:
|
||||
friendly_name = item['friendly_name']
|
||||
if not item['thumb'] or item['thumb'] == '':
|
||||
user_thumb = common.DEFAULT_USER_THUMB
|
||||
else:
|
||||
user_thumb = item['thumb']
|
||||
|
||||
user_details = {"user_id": item['user_id'],
|
||||
"username": item['username'],
|
||||
"friendly_name": friendly_name,
|
||||
"email": item['email'],
|
||||
"thumb": user_thumb,
|
||||
"is_home_user": item['is_home_user'],
|
||||
"is_allow_sync": item['is_allow_sync'],
|
||||
"is_restricted": item['is_restricted'],
|
||||
"do_notify": item['do_notify']
|
||||
}
|
||||
return user_details
|
||||
else:
|
||||
# If there is no user data we must return something
|
||||
# Use "Local" user to retain compatibility with PlexWatch database value
|
||||
return {"user_id": None,
|
||||
"username": 'Local',
|
||||
"friendly_name": 'Local',
|
||||
"email": '',
|
||||
"thumb": '',
|
||||
"is_home_user": 0,
|
||||
"is_allow_sync": 0,
|
||||
"is_restricted": 0,
|
||||
"do_notify": 0
|
||||
}
|
||||
|
||||
def get_home_stats(self, time_range='30'):
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
if not time_range.isdigit():
|
||||
time_range = '30'
|
||||
|
||||
stats_queries = ["top_tv", "popular_tv", "top_users", "top_platforms"]
|
||||
# This actually determines the output order in the home page
|
||||
stats_queries = ["top_tv", "popular_tv", "top_movies", "top_users", "top_platforms"]
|
||||
home_stats = []
|
||||
|
||||
for stat in stats_queries:
|
||||
@@ -483,6 +161,46 @@ class DataFactory(object):
|
||||
home_stats.append({'stat_id': stat,
|
||||
'rows': top_tv})
|
||||
|
||||
elif 'top_movies' in stat:
|
||||
top_movies = []
|
||||
try:
|
||||
query = 'SELECT session_history_metadata.id, ' \
|
||||
'session_history_metadata.full_title, ' \
|
||||
'COUNT(session_history_metadata.full_title) as total_plays, ' \
|
||||
'session_history_metadata.rating_key, ' \
|
||||
'MAX(session_history.started) as last_watch,' \
|
||||
'session_history_metadata.thumb ' \
|
||||
'FROM session_history_metadata ' \
|
||||
'JOIN session_history on session_history_metadata.id = session_history.id ' \
|
||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||
'>= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND session_history_metadata.media_type = "movie" ' \
|
||||
'GROUP BY session_history_metadata.full_title ' \
|
||||
'ORDER BY total_plays DESC LIMIT 10' % time_range
|
||||
result = monitor_db.select(query)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
return None
|
||||
|
||||
for item in result:
|
||||
row = {'title': item[1],
|
||||
'total_plays': item[2],
|
||||
'users_watched': '',
|
||||
'rating_key': item[3],
|
||||
'last_play': item[4],
|
||||
'grandparent_thumb': '',
|
||||
'thumb': item[5],
|
||||
'user': '',
|
||||
'friendly_name': '',
|
||||
'platform_type': '',
|
||||
'platform': '',
|
||||
'row_id': item[0]
|
||||
}
|
||||
top_movies.append(row)
|
||||
|
||||
home_stats.append({'stat_id': stat,
|
||||
'rows': top_movies})
|
||||
|
||||
elif 'popular_tv' in stat:
|
||||
popular_tv = []
|
||||
try:
|
||||
@@ -533,7 +251,7 @@ class DataFactory(object):
|
||||
'users.friendly_name end) as friendly_name,' \
|
||||
'COUNT(session_history.id) as total_plays, ' \
|
||||
'MAX(session_history.started) as last_watch, ' \
|
||||
'users.thumb, ' \
|
||||
'users.custom_avatar_url as thumb, ' \
|
||||
'users.user_id ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN session_history_metadata ON session_history.id = session_history_metadata.id ' \
|
||||
@@ -707,91 +425,6 @@ class DataFactory(object):
|
||||
|
||||
return recently_watched
|
||||
|
||||
def get_user_watch_time_stats(self, user=None, user_id=None):
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
time_queries = [1, 7, 30, 0]
|
||||
user_watch_time_stats = []
|
||||
|
||||
for days in time_queries:
|
||||
if days > 0:
|
||||
if user_id:
|
||||
query = 'SELECT (SUM(stopped - started) - ' \
|
||||
'SUM(CASE WHEN paused_counter is null THEN 0 ELSE paused_counter END)) as total_time, ' \
|
||||
'COUNT(id) AS total_plays ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND user_id = ?' % days
|
||||
result = monitor_db.select(query, args=[user_id])
|
||||
elif user:
|
||||
query = 'SELECT (SUM(stopped - started) - ' \
|
||||
'SUM(CASE WHEN paused_counter is null THEN 0 ELSE paused_counter END)) as total_time, ' \
|
||||
'COUNT(id) AS total_plays ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND user = ?' % days
|
||||
result = monitor_db.select(query, args=[user])
|
||||
else:
|
||||
query = 'SELECT (SUM(stopped - started) - ' \
|
||||
'SUM(CASE WHEN paused_counter is null THEN 0 ELSE paused_counter END)) as total_time, ' \
|
||||
'COUNT(id) AS total_plays ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE user = ?'
|
||||
result = monitor_db.select(query, args=[user])
|
||||
|
||||
for item in result:
|
||||
if item[0]:
|
||||
total_time = item[0]
|
||||
total_plays = item[1]
|
||||
else:
|
||||
total_time = 0
|
||||
total_plays = 0
|
||||
|
||||
row = {'query_days': days,
|
||||
'total_time': total_time,
|
||||
'total_plays': total_plays
|
||||
}
|
||||
|
||||
user_watch_time_stats.append(row)
|
||||
|
||||
return user_watch_time_stats
|
||||
|
||||
def get_user_platform_stats(self, user=None, user_id=None):
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
platform_stats = []
|
||||
result_id = 0
|
||||
|
||||
try:
|
||||
if user_id:
|
||||
query = 'SELECT player, COUNT(player) as player_count, platform ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE user_id = ? ' \
|
||||
'GROUP BY player ' \
|
||||
'ORDER BY player_count DESC'
|
||||
result = monitor_db.select(query, args=[user_id])
|
||||
else:
|
||||
query = 'SELECT player, COUNT(player) as player_count, platform ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE user = ? ' \
|
||||
'GROUP BY player ' \
|
||||
'ORDER BY player_count DESC'
|
||||
result = monitor_db.select(query, args=[user])
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
return None
|
||||
|
||||
for item in result:
|
||||
row = {'platform_name': item[0],
|
||||
'platform_type': item[2],
|
||||
'total_plays': item[1],
|
||||
'result_id': result_id
|
||||
}
|
||||
platform_stats.append(row)
|
||||
result_id += 1
|
||||
|
||||
return platform_stats
|
||||
|
||||
def get_metadata_details(self, row_id):
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
|
@@ -52,7 +52,7 @@ class HTTPHandler(object):
|
||||
|
||||
if uri:
|
||||
if proto.upper() == 'HTTPS':
|
||||
if not self.ssl_verify:
|
||||
if not self.ssl_verify and hasattr(ssl, '_create_unverified_context'):
|
||||
context = ssl._create_unverified_context()
|
||||
handler = HTTPSConnection(host=self.host, port=self.port, timeout=10, context=context)
|
||||
logger.warn(u"PlexPy HTTP Handler :: Unverified HTTPS request made. This connection is not secure.")
|
||||
|
@@ -59,6 +59,11 @@ def check_active_sessions():
|
||||
# Push it on it's own thread so we don't hold up our db actions
|
||||
threading.Thread(target=notification_handler.notify,
|
||||
kwargs=dict(stream_data=stream, notify_action='pause')).start()
|
||||
if session['state'] == 'playing' and stream['state'] == 'paused':
|
||||
# Push any notifications -
|
||||
# Push it on it's own thread so we don't hold up our db actions
|
||||
threading.Thread(target=notification_handler.notify,
|
||||
kwargs=dict(stream_data=stream, notify_action='resume')).start()
|
||||
if stream['state'] == 'paused':
|
||||
# The stream is still paused so we need to increment the paused_counter
|
||||
# Using the set config parameter as the interval, probably not the most accurate but
|
||||
@@ -67,6 +72,53 @@ def check_active_sessions():
|
||||
monitor_db.action('UPDATE sessions SET paused_counter = ? '
|
||||
'WHERE session_key = ? AND rating_key = ?',
|
||||
[paused_counter, stream['session_key'], stream['rating_key']])
|
||||
if session['state'] == 'buffering' and plexpy.CONFIG.BUFFER_THRESHOLD > 0:
|
||||
# The stream is buffering so we need to increment the buffer_count
|
||||
# We're going just increment on every monitor ping,
|
||||
# would be difficult to keep track otherwise
|
||||
monitor_db.action('UPDATE sessions SET buffer_count = buffer_count + 1 '
|
||||
'WHERE session_key = ? AND rating_key = ?',
|
||||
[stream['session_key'], stream['rating_key']])
|
||||
|
||||
# Check the current buffer count and last buffer to determine if we should notify
|
||||
buffer_values = monitor_db.select('SELECT buffer_count, buffer_last_triggered '
|
||||
'FROM sessions '
|
||||
'WHERE session_key = ? AND rating_key = ?',
|
||||
[stream['session_key'], stream['rating_key']])
|
||||
|
||||
if buffer_values[0]['buffer_count'] >= plexpy.CONFIG.BUFFER_THRESHOLD:
|
||||
# Push any notifications -
|
||||
# Push it on it's own thread so we don't hold up our db actions
|
||||
# Our first buffer notification
|
||||
if buffer_values[0]['buffer_count'] == plexpy.CONFIG.BUFFER_THRESHOLD:
|
||||
logger.info(u"PlexPy Monitor :: User '%s' has triggered a buffer warning."
|
||||
% stream['user'])
|
||||
# Set the buffer trigger time
|
||||
monitor_db.action('UPDATE sessions '
|
||||
'SET buffer_last_triggered = strftime("%s","now") '
|
||||
'WHERE session_key = ? AND rating_key = ?',
|
||||
[stream['session_key'], stream['rating_key']])
|
||||
|
||||
threading.Thread(target=notification_handler.notify,
|
||||
kwargs=dict(stream_data=stream, notify_action='buffer')).start()
|
||||
else:
|
||||
# Subsequent buffer notifications after wait time
|
||||
if int(time.time()) > buffer_values[0]['buffer_last_triggered'] + \
|
||||
plexpy.CONFIG.BUFFER_WAIT:
|
||||
logger.info(u"PlexPy Monitor :: User '%s' has triggered multiple buffer warnings."
|
||||
% stream['user'])
|
||||
# Set the buffer trigger time
|
||||
monitor_db.action('UPDATE sessions '
|
||||
'SET buffer_last_triggered = strftime("%s","now") '
|
||||
'WHERE session_key = ? AND rating_key = ?',
|
||||
[stream['session_key'], stream['rating_key']])
|
||||
|
||||
threading.Thread(target=notification_handler.notify,
|
||||
kwargs=dict(stream_data=stream, notify_action='buffer')).start()
|
||||
|
||||
logger.debug(u"PlexPy Monitor :: Stream buffering. Count is now %s. Last triggered %s."
|
||||
% (buffer_values[0][0], buffer_values[0][1]))
|
||||
|
||||
# Check if the user has reached the offset in the media we defined as the "watched" percent
|
||||
# Don't trigger if state is buffer as some clients push the progress to the end when
|
||||
# buffering on start.
|
||||
@@ -179,6 +231,10 @@ class MonitorProcessing(object):
|
||||
self.db.upsert('sessions', timestamp, keys)
|
||||
|
||||
def write_session_history(self, session=None, import_metadata=None, is_import=False, import_ignore_interval=0):
|
||||
from plexpy import users
|
||||
|
||||
user_data = users.Users()
|
||||
user_details = user_data.get_user_friendly_name(user=session['user'])
|
||||
|
||||
if session:
|
||||
logging_enabled = False
|
||||
@@ -218,6 +274,10 @@ class MonitorProcessing(object):
|
||||
(session['rating_key'], str(int(stopped) - session['started']),
|
||||
import_ignore_interval))
|
||||
|
||||
if not user_details['keep_history'] and not is_import:
|
||||
logging_enabled = False
|
||||
logger.debug(u"PlexPy Monitor :: History logging for user '%s' is disabled." % session['user'])
|
||||
|
||||
if logging_enabled:
|
||||
# logger.debug(u"PlexPy Monitor :: Attempting to write to session_history table...")
|
||||
query = 'INSERT INTO session_history (started, stopped, rating_key, parent_rating_key, ' \
|
||||
|
@@ -20,12 +20,12 @@ import time
|
||||
|
||||
|
||||
def notify(stream_data=None, notify_action=None):
|
||||
from plexpy import datafactory
|
||||
from plexpy import users
|
||||
|
||||
if stream_data and notify_action:
|
||||
# Check if notifications enabled for user
|
||||
data_factory = datafactory.DataFactory()
|
||||
user_details = data_factory.get_user_friendly_name(user=stream_data['user'])
|
||||
user_data = users.Users()
|
||||
user_details = user_data.get_user_friendly_name(user=stream_data['user'])
|
||||
|
||||
if not user_details['do_notify']:
|
||||
return
|
||||
@@ -52,6 +52,33 @@ def notify(stream_data=None, notify_action=None):
|
||||
|
||||
set_notify_state(session=stream_data, state='stop', agent_info=agent)
|
||||
|
||||
elif agent['on_pause'] and notify_action == 'pause':
|
||||
# Build and send notification
|
||||
notify_strings = build_notify_text(session=stream_data, state=notify_action)
|
||||
notifiers.send_notification(config_id=agent['id'],
|
||||
subject=notify_strings[0],
|
||||
body=notify_strings[1])
|
||||
|
||||
set_notify_state(session=stream_data, state='pause', agent_info=agent)
|
||||
|
||||
elif agent['on_resume'] and notify_action == 'resume':
|
||||
# Build and send notification
|
||||
notify_strings = build_notify_text(session=stream_data, state=notify_action)
|
||||
notifiers.send_notification(config_id=agent['id'],
|
||||
subject=notify_strings[0],
|
||||
body=notify_strings[1])
|
||||
|
||||
set_notify_state(session=stream_data, state='resume', agent_info=agent)
|
||||
|
||||
elif agent['on_buffer'] and notify_action == 'buffer':
|
||||
# Build and send notification
|
||||
notify_strings = build_notify_text(session=stream_data, state=notify_action)
|
||||
notifiers.send_notification(config_id=agent['id'],
|
||||
subject=notify_strings[0],
|
||||
body=notify_strings[1])
|
||||
|
||||
set_notify_state(session=stream_data, state='buffer', agent_info=agent)
|
||||
|
||||
elif agent['on_watched'] and notify_action == 'watched':
|
||||
# Get the current states for notifications from our db
|
||||
notify_states = get_notify_state(session=stream_data)
|
||||
@@ -100,6 +127,33 @@ def notify(stream_data=None, notify_action=None):
|
||||
# Set the notification state in the db
|
||||
set_notify_state(session=stream_data, state='stop', agent_info=agent)
|
||||
|
||||
elif agent['on_pause'] and notify_action == 'pause':
|
||||
# Build and send notification
|
||||
notify_strings = build_notify_text(session=stream_data, state=notify_action)
|
||||
notifiers.send_notification(config_id=agent['id'],
|
||||
subject=notify_strings[0],
|
||||
body=notify_strings[1])
|
||||
# Set the notification state in the db
|
||||
set_notify_state(session=stream_data, state='pause', agent_info=agent)
|
||||
|
||||
elif agent['on_resume'] and notify_action == 'resume':
|
||||
# Build and send notification
|
||||
notify_strings = build_notify_text(session=stream_data, state=notify_action)
|
||||
notifiers.send_notification(config_id=agent['id'],
|
||||
subject=notify_strings[0],
|
||||
body=notify_strings[1])
|
||||
# Set the notification state in the db
|
||||
set_notify_state(session=stream_data, state='resume', agent_info=agent)
|
||||
|
||||
elif agent['on_buffer'] and notify_action == 'buffer':
|
||||
# Build and send notification
|
||||
notify_strings = build_notify_text(session=stream_data, state=notify_action)
|
||||
notifiers.send_notification(config_id=agent['id'],
|
||||
subject=notify_strings[0],
|
||||
body=notify_strings[1])
|
||||
# Set the notification state in the db
|
||||
set_notify_state(session=stream_data, state='buffer', agent_info=agent)
|
||||
|
||||
elif stream_data['media_type'] == 'clip':
|
||||
pass
|
||||
else:
|
||||
@@ -110,7 +164,7 @@ def notify(stream_data=None, notify_action=None):
|
||||
|
||||
def get_notify_state(session):
|
||||
monitor_db = database.MonitorDatabase()
|
||||
result = monitor_db.select('SELECT on_play, on_stop, on_watched, agent_id '
|
||||
result = monitor_db.select('SELECT on_play, on_stop, on_pause, on_resume, on_buffer, on_watched, agent_id '
|
||||
'FROM notify_log '
|
||||
'WHERE session_key = ? '
|
||||
'AND rating_key = ? '
|
||||
@@ -121,8 +175,11 @@ def get_notify_state(session):
|
||||
for item in result:
|
||||
notify_state = {'on_play': item[0],
|
||||
'on_stop': item[1],
|
||||
'on_watched': item[2],
|
||||
'agent_id': item[3]}
|
||||
'on_pause': item[2],
|
||||
'on_resume': item[3],
|
||||
'on_buffer': item[4],
|
||||
'on_watched': item[5],
|
||||
'agent_id': item[6]}
|
||||
notify_states.append(notify_state)
|
||||
|
||||
return notify_states
|
||||
@@ -136,6 +193,12 @@ def set_notify_state(session, state, agent_info):
|
||||
values = {'on_play': int(time.time())}
|
||||
elif state == 'stop':
|
||||
values = {'on_stop': int(time.time())}
|
||||
elif state == 'pause':
|
||||
values = {'on_pause': int(time.time())}
|
||||
elif state == 'resume':
|
||||
values = {'on_resume': int(time.time())}
|
||||
elif state == 'buffer':
|
||||
values = {'on_buffer': int(time.time())}
|
||||
elif state == 'watched':
|
||||
values = {'on_watched': int(time.time())}
|
||||
else:
|
||||
@@ -173,34 +236,28 @@ def build_notify_text(session, state):
|
||||
if session['media_type'] == 'episode':
|
||||
# Regex pattern to remove the text in the tags we don't want
|
||||
pattern = re.compile('<movie>[^>]+.</movie>|<music>[^>]+.</music>', re.IGNORECASE)
|
||||
|
||||
# Remove the unwanted tags and strip any unmatch tags too.
|
||||
on_start_subject = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_START_SUBJECT_TEXT))
|
||||
on_start_body = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_START_BODY_TEXT))
|
||||
on_stop_subject = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_STOP_SUBJECT_TEXT))
|
||||
on_stop_body = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_STOP_BODY_TEXT))
|
||||
on_watched_subject = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_WATCHED_SUBJECT_TEXT))
|
||||
on_watched_body = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_WATCHED_BODY_TEXT))
|
||||
elif session['media_type'] == 'movie':
|
||||
# Regex pattern to remove the text in the tags we don't want
|
||||
pattern = re.compile('<tv>[^>]+.</tv>|<music>[^>]+.</music>', re.IGNORECASE)
|
||||
|
||||
# Remove the unwanted tags and strip any unmatch tags too.
|
||||
on_start_subject = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_START_SUBJECT_TEXT))
|
||||
on_start_body = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_START_BODY_TEXT))
|
||||
on_stop_subject = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_STOP_SUBJECT_TEXT))
|
||||
on_stop_body = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_STOP_BODY_TEXT))
|
||||
on_watched_subject = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_WATCHED_SUBJECT_TEXT))
|
||||
on_watched_body = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_WATCHED_BODY_TEXT))
|
||||
elif session['media_type'] == 'track':
|
||||
# Regex pattern to remove the text in the tags we don't want
|
||||
pattern = re.compile('<tv>[^>]+.</tv>|<movie>[^>]+.</movie>', re.IGNORECASE)
|
||||
else:
|
||||
pattern = None
|
||||
|
||||
if session['media_type'] == 'episode' or session['media_type'] == 'movie' or session['media_type'] == 'track' \
|
||||
and pattern:
|
||||
# Remove the unwanted tags and strip any unmatch tags too.
|
||||
on_start_subject = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_START_SUBJECT_TEXT))
|
||||
on_start_body = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_START_BODY_TEXT))
|
||||
on_stop_subject = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_STOP_SUBJECT_TEXT))
|
||||
on_stop_body = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_STOP_BODY_TEXT))
|
||||
on_pause_subject = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_PAUSE_SUBJECT_TEXT))
|
||||
on_pause_body = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_PAUSE_BODY_TEXT))
|
||||
on_resume_subject = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_RESUME_SUBJECT_TEXT))
|
||||
on_resume_body = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_RESUME_BODY_TEXT))
|
||||
on_buffer_subject = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_BUFFER_SUBJECT_TEXT))
|
||||
on_buffer_body = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_BUFFER_BODY_TEXT))
|
||||
on_watched_subject = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_WATCHED_SUBJECT_TEXT))
|
||||
on_watched_body = strip_tag(re.sub(pattern, '', plexpy.CONFIG.NOTIFY_ON_WATCHED_BODY_TEXT))
|
||||
else:
|
||||
@@ -208,6 +265,12 @@ def build_notify_text(session, state):
|
||||
on_start_body = plexpy.CONFIG.NOTIFY_ON_START_BODY_TEXT
|
||||
on_stop_subject = plexpy.CONFIG.NOTIFY_ON_STOP_SUBJECT_TEXT
|
||||
on_stop_body = plexpy.CONFIG.NOTIFY_ON_STOP_BODY_TEXT
|
||||
on_pause_subject = plexpy.CONFIG.NOTIFY_ON_PAUSE_SUBJECT_TEXT
|
||||
on_pause_body = plexpy.CONFIG.NOTIFY_ON_PAUSE_BODY_TEXT
|
||||
on_resume_subject = plexpy.CONFIG.NOTIFY_ON_RESUME_SUBJECT_TEXT
|
||||
on_resume_body = plexpy.CONFIG.NOTIFY_ON_RESUME_BODY_TEXT
|
||||
on_buffer_subject = plexpy.CONFIG.NOTIFY_ON_BUFFER_SUBJECT_TEXT
|
||||
on_buffer_body = plexpy.CONFIG.NOTIFY_ON_BUFFER_BODY_TEXT
|
||||
on_watched_subject = plexpy.CONFIG.NOTIFY_ON_WATCHED_SUBJECT_TEXT
|
||||
on_watched_body = plexpy.CONFIG.NOTIFY_ON_WATCHED_BODY_TEXT
|
||||
|
||||
@@ -310,6 +373,78 @@ def build_notify_text(session, state):
|
||||
except:
|
||||
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
||||
|
||||
return [subject_text, body_text]
|
||||
else:
|
||||
return [subject_text, body_text]
|
||||
elif state == 'pause':
|
||||
# Default body text
|
||||
body_text = '%s (%s) has paused %s' % (session['friendly_name'],
|
||||
session['player'],
|
||||
full_title)
|
||||
|
||||
if on_pause_subject and on_pause_body:
|
||||
try:
|
||||
subject_text = on_pause_subject.format(**available_params)
|
||||
except LookupError, e:
|
||||
logger.error(u"PlexPy Notifier :: Unable to parse field %s in notification subject. Using fallback." % e)
|
||||
except:
|
||||
logger.error(u"PlexPy Notifier :: Unable to parse custom notification subject. Using fallback.")
|
||||
|
||||
try:
|
||||
body_text = on_pause_body.format(**available_params)
|
||||
except LookupError, e:
|
||||
logger.error(u"PlexPy Notifier :: Unable to parse field %s in notification body. Using fallback." % e)
|
||||
except:
|
||||
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
||||
|
||||
return [subject_text, body_text]
|
||||
else:
|
||||
return [subject_text, body_text]
|
||||
elif state == 'resume':
|
||||
# Default body text
|
||||
body_text = '%s (%s) has resumed %s' % (session['friendly_name'],
|
||||
session['player'],
|
||||
full_title)
|
||||
|
||||
if on_resume_subject and on_resume_body:
|
||||
try:
|
||||
subject_text = on_resume_subject.format(**available_params)
|
||||
except LookupError, e:
|
||||
logger.error(u"PlexPy Notifier :: Unable to parse field %s in notification subject. Using fallback." % e)
|
||||
except:
|
||||
logger.error(u"PlexPy Notifier :: Unable to parse custom notification subject. Using fallback.")
|
||||
|
||||
try:
|
||||
body_text = on_resume_body.format(**available_params)
|
||||
except LookupError, e:
|
||||
logger.error(u"PlexPy Notifier :: Unable to parse field %s in notification body. Using fallback." % e)
|
||||
except:
|
||||
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
||||
|
||||
return [subject_text, body_text]
|
||||
else:
|
||||
return [subject_text, body_text]
|
||||
elif state == 'buffer':
|
||||
# Default body text
|
||||
body_text = '%s (%s) is buffering %s' % (session['friendly_name'],
|
||||
session['player'],
|
||||
full_title)
|
||||
|
||||
if on_buffer_subject and on_buffer_body:
|
||||
try:
|
||||
subject_text = on_buffer_subject.format(**available_params)
|
||||
except LookupError, e:
|
||||
logger.error(u"PlexPy Notifier :: Unable to parse field %s in notification subject. Using fallback." % e)
|
||||
except:
|
||||
logger.error(u"PlexPy Notifier :: Unable to parse custom notification subject. Using fallback.")
|
||||
|
||||
try:
|
||||
body_text = on_buffer_body.format(**available_params)
|
||||
except LookupError, e:
|
||||
logger.error(u"PlexPy Notifier :: Unable to parse field %s in notification body. Using fallback." % e)
|
||||
except:
|
||||
logger.error(u"PlexPy Notifier :: Unable to parse custom notification body. Using fallback.")
|
||||
|
||||
return [subject_text, body_text]
|
||||
else:
|
||||
return [subject_text, body_text]
|
||||
|
@@ -59,6 +59,9 @@ def available_notification_agents():
|
||||
'state': checked(plexpy.CONFIG.GROWL_ENABLED),
|
||||
'on_play': plexpy.CONFIG.GROWL_ON_PLAY,
|
||||
'on_stop': plexpy.CONFIG.GROWL_ON_STOP,
|
||||
'on_pause': plexpy.CONFIG.GROWL_ON_PAUSE,
|
||||
'on_resume': plexpy.CONFIG.GROWL_ON_RESUME,
|
||||
'on_buffer': plexpy.CONFIG.GROWL_ON_BUFFER,
|
||||
'on_watched': plexpy.CONFIG.GROWL_ON_WATCHED
|
||||
},
|
||||
{'name': 'Prowl',
|
||||
@@ -68,6 +71,9 @@ def available_notification_agents():
|
||||
'state': checked(plexpy.CONFIG.PROWL_ENABLED),
|
||||
'on_play': plexpy.CONFIG.PROWL_ON_PLAY,
|
||||
'on_stop': plexpy.CONFIG.PROWL_ON_STOP,
|
||||
'on_pause': plexpy.CONFIG.PROWL_ON_PAUSE,
|
||||
'on_resume': plexpy.CONFIG.PROWL_ON_RESUME,
|
||||
'on_buffer': plexpy.CONFIG.PROWL_ON_BUFFER,
|
||||
'on_watched': plexpy.CONFIG.PROWL_ON_WATCHED
|
||||
},
|
||||
{'name': 'XBMC',
|
||||
@@ -77,6 +83,9 @@ def available_notification_agents():
|
||||
'state': checked(plexpy.CONFIG.XBMC_ENABLED),
|
||||
'on_play': plexpy.CONFIG.XBMC_ON_PLAY,
|
||||
'on_stop': plexpy.CONFIG.XBMC_ON_STOP,
|
||||
'on_pause': plexpy.CONFIG.XBMC_ON_PAUSE,
|
||||
'on_resume': plexpy.CONFIG.XBMC_ON_RESUME,
|
||||
'on_buffer': plexpy.CONFIG.XBMC_ON_BUFFER,
|
||||
'on_watched': plexpy.CONFIG.XBMC_ON_WATCHED
|
||||
},
|
||||
{'name': 'Plex',
|
||||
@@ -86,6 +95,9 @@ def available_notification_agents():
|
||||
'state': checked(plexpy.CONFIG.PLEX_ENABLED),
|
||||
'on_play': plexpy.CONFIG.PLEX_ON_PLAY,
|
||||
'on_stop': plexpy.CONFIG.PLEX_ON_STOP,
|
||||
'on_pause': plexpy.CONFIG.PLEX_ON_PAUSE,
|
||||
'on_resume': plexpy.CONFIG.PLEX_ON_RESUME,
|
||||
'on_buffer': plexpy.CONFIG.PLEX_ON_BUFFER,
|
||||
'on_watched': plexpy.CONFIG.PLEX_ON_WATCHED
|
||||
},
|
||||
{'name': 'NotifyMyAndroid',
|
||||
@@ -95,6 +107,9 @@ def available_notification_agents():
|
||||
'state': checked(plexpy.CONFIG.NMA_ENABLED),
|
||||
'on_play': plexpy.CONFIG.NMA_ON_PLAY,
|
||||
'on_stop': plexpy.CONFIG.NMA_ON_STOP,
|
||||
'on_pause': plexpy.CONFIG.NMA_ON_PAUSE,
|
||||
'on_resume': plexpy.CONFIG.NMA_ON_RESUME,
|
||||
'on_buffer': plexpy.CONFIG.NMA_ON_BUFFER,
|
||||
'on_watched': plexpy.CONFIG.NMA_ON_WATCHED
|
||||
},
|
||||
{'name': 'Pushalot',
|
||||
@@ -104,6 +119,9 @@ def available_notification_agents():
|
||||
'state': checked(plexpy.CONFIG.PUSHALOT_ENABLED),
|
||||
'on_play': plexpy.CONFIG.PUSHALOT_ON_PLAY,
|
||||
'on_stop': plexpy.CONFIG.PUSHALOT_ON_STOP,
|
||||
'on_pause': plexpy.CONFIG.PUSHALOT_ON_PAUSE,
|
||||
'on_resume': plexpy.CONFIG.PUSHALOT_ON_RESUME,
|
||||
'on_buffer': plexpy.CONFIG.PUSHALOT_ON_BUFFER,
|
||||
'on_watched': plexpy.CONFIG.PUSHALOT_ON_WATCHED
|
||||
},
|
||||
{'name': 'Pushbullet',
|
||||
@@ -113,6 +131,9 @@ def available_notification_agents():
|
||||
'state': checked(plexpy.CONFIG.PUSHBULLET_ENABLED),
|
||||
'on_play': plexpy.CONFIG.PUSHBULLET_ON_PLAY,
|
||||
'on_stop': plexpy.CONFIG.PUSHBULLET_ON_STOP,
|
||||
'on_pause': plexpy.CONFIG.PUSHBULLET_ON_PAUSE,
|
||||
'on_resume': plexpy.CONFIG.PUSHBULLET_ON_RESUME,
|
||||
'on_buffer': plexpy.CONFIG.PUSHBULLET_ON_BUFFER,
|
||||
'on_watched': plexpy.CONFIG.PUSHBULLET_ON_WATCHED
|
||||
},
|
||||
{'name': 'Pushover',
|
||||
@@ -122,6 +143,9 @@ def available_notification_agents():
|
||||
'state': checked(plexpy.CONFIG.PUSHOVER_ENABLED),
|
||||
'on_play': plexpy.CONFIG.PUSHOVER_ON_PLAY,
|
||||
'on_stop': plexpy.CONFIG.PUSHOVER_ON_STOP,
|
||||
'on_pause': plexpy.CONFIG.PUSHOVER_ON_PAUSE,
|
||||
'on_resume': plexpy.CONFIG.PUSHOVER_ON_RESUME,
|
||||
'on_buffer': plexpy.CONFIG.PUSHOVER_ON_BUFFER,
|
||||
'on_watched': plexpy.CONFIG.PUSHOVER_ON_WATCHED
|
||||
},
|
||||
{'name': 'Boxcar2',
|
||||
@@ -131,6 +155,9 @@ def available_notification_agents():
|
||||
'state': checked(plexpy.CONFIG.BOXCAR_ENABLED),
|
||||
'on_play': plexpy.CONFIG.BOXCAR_ON_PLAY,
|
||||
'on_stop': plexpy.CONFIG.BOXCAR_ON_STOP,
|
||||
'on_pause': plexpy.CONFIG.BOXCAR_ON_PAUSE,
|
||||
'on_resume': plexpy.CONFIG.BOXCAR_ON_RESUME,
|
||||
'on_buffer': plexpy.CONFIG.BOXCAR_ON_BUFFER,
|
||||
'on_watched': plexpy.CONFIG.BOXCAR_ON_WATCHED
|
||||
},
|
||||
{'name': 'E-mail',
|
||||
@@ -140,6 +167,9 @@ def available_notification_agents():
|
||||
'state': checked(plexpy.CONFIG.EMAIL_ENABLED),
|
||||
'on_play': plexpy.CONFIG.EMAIL_ON_PLAY,
|
||||
'on_stop': plexpy.CONFIG.EMAIL_ON_STOP,
|
||||
'on_pause': plexpy.CONFIG.EMAIL_ON_PAUSE,
|
||||
'on_resume': plexpy.CONFIG.EMAIL_ON_RESUME,
|
||||
'on_buffer': plexpy.CONFIG.EMAIL_ON_BUFFER,
|
||||
'on_watched': plexpy.CONFIG.EMAIL_ON_WATCHED
|
||||
}
|
||||
]
|
||||
@@ -154,6 +184,9 @@ def available_notification_agents():
|
||||
'state': checked(plexpy.CONFIG.OSX_NOTIFY_ENABLED),
|
||||
'on_play': plexpy.CONFIG.OSX_NOTIFY_ON_PLAY,
|
||||
'on_stop': plexpy.CONFIG.OSX_NOTIFY_ON_STOP,
|
||||
'on_pause': plexpy.CONFIG.OSX_NOTIFY_ON_PAUSE,
|
||||
'on_resume': plexpy.CONFIG.OSX_NOTIFY_ON_RESUME,
|
||||
'on_buffer': plexpy.CONFIG.OSX_NOTIFY_ON_BUFFER,
|
||||
'on_watched': plexpy.CONFIG.OSX_NOTIFY_ON_WATCHED
|
||||
})
|
||||
|
||||
|
@@ -13,7 +13,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from plexpy import logger, helpers, datafactory, http_handler, database
|
||||
from plexpy import logger, helpers, users, http_handler, database
|
||||
|
||||
from xml.dom import minidom
|
||||
|
||||
@@ -37,6 +37,18 @@ def refresh_users():
|
||||
"is_restricted": item['is_restricted']
|
||||
}
|
||||
|
||||
# Check if we've set a custom avatar if so don't overwrite it.
|
||||
if item['user_id']:
|
||||
avatar_urls = monitor_db.select('SELECT thumb, custom_avatar_url '
|
||||
'FROM users WHERE user_id = ?',
|
||||
[item['user_id']])
|
||||
if avatar_urls:
|
||||
if not avatar_urls[0]['custom_avatar_url'] or \
|
||||
avatar_urls[0]['custom_avatar_url'] == avatar_urls[0]['thumb']:
|
||||
new_value_dict['custom_avatar_url'] = item['thumb']
|
||||
else:
|
||||
new_value_dict['custom_avatar_url'] = item['thumb']
|
||||
|
||||
monitor_db.upsert('users', new_value_dict, control_value_dict)
|
||||
|
||||
logger.info("Users list refreshed.")
|
||||
@@ -244,7 +256,7 @@ class PlexTV(object):
|
||||
|
||||
def get_synced_items(self, machine_id=None, user_id=None):
|
||||
sync_list = self.get_plextv_sync_lists(machine_id)
|
||||
data_factory = datafactory.DataFactory()
|
||||
user_data = users.Users()
|
||||
|
||||
synced_items = []
|
||||
|
||||
@@ -268,8 +280,8 @@ class PlexTV(object):
|
||||
for device in sync_device:
|
||||
device_user_id = helpers.get_xml_attr(device, 'userID')
|
||||
try:
|
||||
device_username = data_factory.get_user_details(user_id=device_user_id)['username']
|
||||
device_friendly_name = data_factory.get_user_details(user_id=device_user_id)['friendly_name']
|
||||
device_username = user_data.get_user_details(user_id=device_user_id)['username']
|
||||
device_friendly_name = user_data.get_user_details(user_id=device_user_id)['friendly_name']
|
||||
except:
|
||||
device_username = ''
|
||||
device_friendly_name = ''
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
import sqlite3
|
||||
|
||||
from plexpy import logger, helpers, monitor, datafactory, plextv
|
||||
from plexpy import logger, helpers, monitor, users, plextv
|
||||
from xml.dom import minidom
|
||||
|
||||
import plexpy
|
||||
@@ -246,7 +246,7 @@ def import_from_plexwatch(database=None, table_name=None, import_ignore_interval
|
||||
plexpy.schedule_job(monitor.check_active_sessions, 'Check for active sessions', hours=0, minutes=0, seconds=0)
|
||||
|
||||
monitor_processing = monitor.MonitorProcessing()
|
||||
data_factory = datafactory.DataFactory()
|
||||
user_data = users.Users()
|
||||
|
||||
# Get the latest friends list so we can pull user id's
|
||||
try:
|
||||
@@ -292,8 +292,8 @@ def import_from_plexwatch(database=None, table_name=None, import_ignore_interval
|
||||
continue
|
||||
|
||||
# If the user_id no longer exists in the friends list, pull it from the xml.
|
||||
if data_factory.get_user_id(user=row['user']):
|
||||
user_id = data_factory.get_user_id(user=row['user'])
|
||||
if user_data.get_user_id(user=row['user']):
|
||||
user_id = user_data.get_user_id(user=row['user'])
|
||||
else:
|
||||
user_id = extracted_xml['user_id']
|
||||
|
||||
|
@@ -13,7 +13,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from plexpy import logger, helpers, datafactory, http_handler
|
||||
from plexpy import logger, helpers, users, http_handler
|
||||
from urlparse import urlparse
|
||||
|
||||
import plexpy
|
||||
@@ -218,6 +218,7 @@ class PmsConnect(object):
|
||||
recent_items = {'type': recent_type,
|
||||
'rating_key': helpers.get_xml_attr(item, 'ratingKey'),
|
||||
'title': helpers.get_xml_attr(item, 'title'),
|
||||
'parent_title': helpers.get_xml_attr(item, 'parentTitle'),
|
||||
'thumb': helpers.get_xml_attr(item, 'thumb'),
|
||||
'added_at': helpers.get_xml_attr(item, 'addedAt')
|
||||
}
|
||||
@@ -232,6 +233,7 @@ class PmsConnect(object):
|
||||
recent_items = {'type': recent_type,
|
||||
'rating_key': helpers.get_xml_attr(item, 'ratingKey'),
|
||||
'title': helpers.get_xml_attr(item, 'title'),
|
||||
'parent_title': helpers.get_xml_attr(item, 'parentTitle'),
|
||||
'year': helpers.get_xml_attr(item, 'year'),
|
||||
'thumb': helpers.get_xml_attr(item, 'thumb'),
|
||||
'added_at': helpers.get_xml_attr(item, 'addedAt')
|
||||
@@ -505,7 +507,7 @@ class PmsConnect(object):
|
||||
"""
|
||||
def get_session_each(self, stream_type='', session=None):
|
||||
session_output = None
|
||||
data_factory = datafactory.DataFactory()
|
||||
user_data = users.Users()
|
||||
if stream_type == 'track':
|
||||
|
||||
media_info = session.getElementsByTagName('Media')[0]
|
||||
@@ -531,7 +533,7 @@ class PmsConnect(object):
|
||||
transcode_container = ''
|
||||
transcode_protocol = ''
|
||||
|
||||
user_details = data_factory.get_user_details(
|
||||
user_details = user_data.get_user_details(
|
||||
user=helpers.get_xml_attr(session.getElementsByTagName('User')[0], 'title'))
|
||||
|
||||
if helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'machineIdentifier').endswith('_Track'):
|
||||
@@ -639,7 +641,7 @@ class PmsConnect(object):
|
||||
else:
|
||||
use_indexes = 0
|
||||
|
||||
user_details = data_factory.get_user_details(
|
||||
user_details = user_data.get_user_details(
|
||||
user=helpers.get_xml_attr(session.getElementsByTagName('User')[0], 'title'))
|
||||
|
||||
if helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'machineIdentifier').endswith('_Video'):
|
||||
|
463
plexpy/users.py
Normal file
463
plexpy/users.py
Normal file
@@ -0,0 +1,463 @@
|
||||
# This file is part of PlexPy.
|
||||
#
|
||||
# PlexPy is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# PlexPy is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from plexpy import logger, datatables, common, database, helpers
|
||||
|
||||
|
||||
class Users(object):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def get_user_list(self, kwargs=None):
|
||||
data_tables = datatables.DataTables()
|
||||
|
||||
columns = ['users.user_id as user_id',
|
||||
'users.custom_avatar_url as thumb',
|
||||
'(case when users.friendly_name is null then users.username else \
|
||||
users.friendly_name end) as friendly_name',
|
||||
'MAX(session_history.started) as last_seen',
|
||||
'session_history.ip_address as ip_address',
|
||||
'COUNT(session_history.id) as plays',
|
||||
'users.username as user'
|
||||
]
|
||||
try:
|
||||
query = data_tables.ssp_query(table_name='users',
|
||||
columns=columns,
|
||||
custom_where=[],
|
||||
group_by=['users.user_id'],
|
||||
join_types=['LEFT OUTER JOIN'],
|
||||
join_tables=['session_history'],
|
||||
join_evals=[['session_history.user_id', 'users.user_id']],
|
||||
kwargs=kwargs)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
return {'recordsFiltered': 0,
|
||||
'recordsTotal': 0,
|
||||
'draw': 0,
|
||||
'data': 'null',
|
||||
'error': 'Unable to execute database query.'}
|
||||
|
||||
users = query['result']
|
||||
|
||||
rows = []
|
||||
for item in users:
|
||||
if not item['thumb'] or item['thumb'] == '':
|
||||
user_thumb = common.DEFAULT_USER_THUMB
|
||||
else:
|
||||
user_thumb = item['thumb']
|
||||
|
||||
row = {"plays": item['plays'],
|
||||
"last_seen": item['last_seen'],
|
||||
"friendly_name": item["friendly_name"],
|
||||
"ip_address": item["ip_address"],
|
||||
"thumb": user_thumb,
|
||||
"user": item["user"],
|
||||
"user_id": item['user_id']
|
||||
}
|
||||
|
||||
rows.append(row)
|
||||
|
||||
dict = {'recordsFiltered': query['filteredCount'],
|
||||
'recordsTotal': query['totalCount'],
|
||||
'data': rows,
|
||||
'draw': query['draw']
|
||||
}
|
||||
|
||||
return dict
|
||||
|
||||
def get_user_unique_ips(self, kwargs=None, custom_where=None):
|
||||
data_tables = datatables.DataTables()
|
||||
|
||||
columns = ['session_history.started as last_seen',
|
||||
'session_history.ip_address as ip_address',
|
||||
'COUNT(session_history.id) as play_count',
|
||||
'session_history.player as platform',
|
||||
'session_history_metadata.full_title as last_watched',
|
||||
'session_history.user as user',
|
||||
'session_history.user_id as user_id'
|
||||
]
|
||||
|
||||
try:
|
||||
query = data_tables.ssp_query(table_name='session_history',
|
||||
columns=columns,
|
||||
custom_where=custom_where,
|
||||
group_by=['ip_address'],
|
||||
join_types=['JOIN'],
|
||||
join_tables=['session_history_metadata'],
|
||||
join_evals=[['session_history.id', 'session_history_metadata.id']],
|
||||
kwargs=kwargs)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
return {'recordsFiltered': 0,
|
||||
'recordsTotal': 0,
|
||||
'draw': 0,
|
||||
'data': 'null',
|
||||
'error': 'Unable to execute database query.'}
|
||||
|
||||
results = query['result']
|
||||
|
||||
rows = []
|
||||
for item in results:
|
||||
row = {"last_seen": item['last_seen'],
|
||||
"ip_address": item['ip_address'],
|
||||
"play_count": item['play_count'],
|
||||
"platform": item['platform'],
|
||||
"last_watched": item['last_watched']
|
||||
}
|
||||
|
||||
rows.append(row)
|
||||
|
||||
dict = {'recordsFiltered': query['filteredCount'],
|
||||
'recordsTotal': query['totalCount'],
|
||||
'data': rows,
|
||||
'draw': query['draw']
|
||||
}
|
||||
|
||||
return dict
|
||||
|
||||
# TODO: The getter and setter for this needs to become a config getter/setter for more than just friendlyname
|
||||
def set_user_friendly_name(self, user=None, user_id=None, friendly_name=None, do_notify=0, keep_history=1):
|
||||
if user_id:
|
||||
if friendly_name.strip() == '':
|
||||
friendly_name = None
|
||||
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
control_value_dict = {"user_id": user_id}
|
||||
new_value_dict = {"friendly_name": friendly_name,
|
||||
"do_notify": do_notify,
|
||||
"keep_history": keep_history}
|
||||
try:
|
||||
monitor_db.upsert('users', new_value_dict, control_value_dict)
|
||||
except Exception, e:
|
||||
logger.debug(u"Uncaught exception %s" % e)
|
||||
if user:
|
||||
if friendly_name.strip() == '':
|
||||
friendly_name = None
|
||||
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
control_value_dict = {"username": user}
|
||||
new_value_dict = {"friendly_name": friendly_name,
|
||||
"do_notify": do_notify,
|
||||
"keep_history": keep_history}
|
||||
try:
|
||||
monitor_db.upsert('users', new_value_dict, control_value_dict)
|
||||
except Exception, e:
|
||||
logger.debug(u"Uncaught exception %s" % e)
|
||||
|
||||
def set_user_profile_url(self, user=None, user_id=None, profile_url=None):
|
||||
if user_id:
|
||||
if profile_url.strip() == '':
|
||||
profile_url = None
|
||||
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
control_value_dict = {"user_id": user_id}
|
||||
new_value_dict = {"custom_avatar_url": profile_url}
|
||||
try:
|
||||
monitor_db.upsert('users', new_value_dict, control_value_dict)
|
||||
except Exception, e:
|
||||
logger.debug(u"Uncaught exception %s" % e)
|
||||
if user:
|
||||
if profile_url.strip() == '':
|
||||
profile_url = None
|
||||
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
control_value_dict = {"username": user}
|
||||
new_value_dict = {"custom_avatar_url": profile_url}
|
||||
try:
|
||||
monitor_db.upsert('users', new_value_dict, control_value_dict)
|
||||
except Exception, e:
|
||||
logger.debug(u"Uncaught exception %s" % e)
|
||||
|
||||
def get_user_friendly_name(self, user=None, user_id=None):
|
||||
if user_id:
|
||||
monitor_db = database.MonitorDatabase()
|
||||
query = 'select username, ' \
|
||||
'(CASE WHEN friendly_name IS NULL THEN username ELSE friendly_name END),' \
|
||||
'do_notify, keep_history, custom_avatar_url as thumb ' \
|
||||
'FROM users WHERE user_id = ?'
|
||||
result = monitor_db.select(query, args=[user_id])
|
||||
if result:
|
||||
user_detail = {'user_id': user_id,
|
||||
'user': result[0][0],
|
||||
'friendly_name': result[0][1],
|
||||
'thumb': result[0][4],
|
||||
'do_notify': helpers.checked(result[0][2]),
|
||||
'keep_history': helpers.checked(result[0][3])
|
||||
}
|
||||
return user_detail
|
||||
else:
|
||||
user_detail = {'user_id': user_id,
|
||||
'user': '',
|
||||
'friendly_name': '',
|
||||
'do_notify': '',
|
||||
'thumb': '',
|
||||
'keep_history': ''}
|
||||
return user_detail
|
||||
elif user:
|
||||
monitor_db = database.MonitorDatabase()
|
||||
query = 'select user_id, ' \
|
||||
'(CASE WHEN friendly_name IS NULL THEN username ELSE friendly_name END),' \
|
||||
'do_notify, keep_history, custom_avatar_url as thumb ' \
|
||||
'FROM users WHERE username = ?'
|
||||
result = monitor_db.select(query, args=[user])
|
||||
if result:
|
||||
user_detail = {'user_id': result[0][0],
|
||||
'user': user,
|
||||
'friendly_name': result[0][1],
|
||||
'thumb': result[0][4],
|
||||
'do_notify': helpers.checked(result[0][2]),
|
||||
'keep_history': helpers.checked(result[0][3])}
|
||||
return user_detail
|
||||
else:
|
||||
user_detail = {'user_id': None,
|
||||
'user': user,
|
||||
'friendly_name': '',
|
||||
'do_notify': '',
|
||||
'thumb': '',
|
||||
'keep_history': ''}
|
||||
return user_detail
|
||||
|
||||
return None
|
||||
|
||||
def get_user_id(self, user=None):
|
||||
if user:
|
||||
try:
|
||||
monitor_db = database.MonitorDatabase()
|
||||
query = 'select user_id FROM users WHERE username = ?'
|
||||
result = monitor_db.select_single(query, args=[user])
|
||||
if result:
|
||||
return result
|
||||
else:
|
||||
return None
|
||||
except:
|
||||
return None
|
||||
|
||||
return None
|
||||
|
||||
def get_user_details(self, user=None, user_id=None):
|
||||
from plexpy import plextv
|
||||
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
if user:
|
||||
query = 'SELECT user_id, username, friendly_name, email, ' \
|
||||
'custom_avatar_url as thumb, is_home_user, is_allow_sync, is_restricted, do_notify ' \
|
||||
'FROM users ' \
|
||||
'WHERE username = ? ' \
|
||||
'UNION ALL ' \
|
||||
'SELECT null, user, null, null, null, null, null, null, null ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE user = ? ' \
|
||||
'GROUP BY user ' \
|
||||
'LIMIT 1'
|
||||
result = monitor_db.select(query, args=[user, user])
|
||||
elif user_id:
|
||||
query = 'SELECT user_id, username, friendly_name, email, ' \
|
||||
'custom_avatar_url as thumb, is_home_user, is_allow_sync, is_restricted, do_notify ' \
|
||||
'FROM users ' \
|
||||
'WHERE user_id = ? ' \
|
||||
'UNION ALL ' \
|
||||
'SELECT user_id, user, null, null, null, null, null, null, null ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE user_id = ? ' \
|
||||
'GROUP BY user ' \
|
||||
'LIMIT 1'
|
||||
result = monitor_db.select(query, args=[user_id, user_id])
|
||||
else:
|
||||
result = None
|
||||
|
||||
if result:
|
||||
user_details = {}
|
||||
for item in result:
|
||||
if not item['friendly_name']:
|
||||
friendly_name = item['username']
|
||||
else:
|
||||
friendly_name = item['friendly_name']
|
||||
if not item['thumb'] or item['thumb'] == '':
|
||||
user_thumb = common.DEFAULT_USER_THUMB
|
||||
else:
|
||||
user_thumb = item['thumb']
|
||||
|
||||
user_details = {"user_id": item['user_id'],
|
||||
"username": item['username'],
|
||||
"friendly_name": friendly_name,
|
||||
"email": item['email'],
|
||||
"thumb": user_thumb,
|
||||
"is_home_user": item['is_home_user'],
|
||||
"is_allow_sync": item['is_allow_sync'],
|
||||
"is_restricted": item['is_restricted'],
|
||||
"do_notify": item['do_notify']
|
||||
}
|
||||
return user_details
|
||||
else:
|
||||
logger.warn(u"PlexPy :: Unable to retrieve user from local database. Requesting user list refresh.")
|
||||
# Let's first refresh the user list to make sure the user isn't newly added and not in the db yet
|
||||
if user:
|
||||
# Refresh users
|
||||
plextv.refresh_users()
|
||||
query = 'SELECT user_id, username, friendly_name, email, ' \
|
||||
'custom_avatar_url as thumb, is_home_user, is_allow_sync, is_restricted, do_notify ' \
|
||||
'FROM users ' \
|
||||
'WHERE username = ? ' \
|
||||
'UNION ALL ' \
|
||||
'SELECT null, user, null, null, null, null, null, null, null ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE user = ? ' \
|
||||
'GROUP BY user ' \
|
||||
'LIMIT 1'
|
||||
result = monitor_db.select(query, args=[user, user])
|
||||
elif user_id:
|
||||
# Refresh users
|
||||
plextv.refresh_users()
|
||||
query = 'SELECT user_id, username, friendly_name, email, ' \
|
||||
'custom_avatar_url as thumb, is_home_user, is_allow_sync, is_restricted, do_notify ' \
|
||||
'FROM users ' \
|
||||
'WHERE user_id = ? ' \
|
||||
'UNION ALL ' \
|
||||
'SELECT user_id, user, null, null, null, null, null, null, null ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE user_id = ? ' \
|
||||
'GROUP BY user ' \
|
||||
'LIMIT 1'
|
||||
result = monitor_db.select(query, args=[user_id, user_id])
|
||||
else:
|
||||
result = None
|
||||
|
||||
if result:
|
||||
user_details = {}
|
||||
for item in result:
|
||||
if not item['friendly_name']:
|
||||
friendly_name = item['username']
|
||||
else:
|
||||
friendly_name = item['friendly_name']
|
||||
if not item['thumb'] or item['thumb'] == '':
|
||||
user_thumb = common.DEFAULT_USER_THUMB
|
||||
else:
|
||||
user_thumb = item['thumb']
|
||||
|
||||
user_details = {"user_id": item['user_id'],
|
||||
"username": item['username'],
|
||||
"friendly_name": friendly_name,
|
||||
"email": item['email'],
|
||||
"thumb": user_thumb,
|
||||
"is_home_user": item['is_home_user'],
|
||||
"is_allow_sync": item['is_allow_sync'],
|
||||
"is_restricted": item['is_restricted'],
|
||||
"do_notify": item['do_notify']
|
||||
}
|
||||
return user_details
|
||||
else:
|
||||
# If there is no user data we must return something
|
||||
# Use "Local" user to retain compatibility with PlexWatch database value
|
||||
return {"user_id": None,
|
||||
"username": 'Local',
|
||||
"friendly_name": 'Local',
|
||||
"email": '',
|
||||
"thumb": '',
|
||||
"is_home_user": 0,
|
||||
"is_allow_sync": 0,
|
||||
"is_restricted": 0,
|
||||
"do_notify": 0
|
||||
}
|
||||
|
||||
def get_user_watch_time_stats(self, user=None, user_id=None):
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
time_queries = [1, 7, 30, 0]
|
||||
user_watch_time_stats = []
|
||||
|
||||
for days in time_queries:
|
||||
if days > 0:
|
||||
if user_id:
|
||||
query = 'SELECT (SUM(stopped - started) - ' \
|
||||
'SUM(CASE WHEN paused_counter is null THEN 0 ELSE paused_counter END)) as total_time, ' \
|
||||
'COUNT(id) AS total_plays ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND user_id = ?' % days
|
||||
result = monitor_db.select(query, args=[user_id])
|
||||
elif user:
|
||||
query = 'SELECT (SUM(stopped - started) - ' \
|
||||
'SUM(CASE WHEN paused_counter is null THEN 0 ELSE paused_counter END)) as total_time, ' \
|
||||
'COUNT(id) AS total_plays ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND user = ?' % days
|
||||
result = monitor_db.select(query, args=[user])
|
||||
else:
|
||||
query = 'SELECT (SUM(stopped - started) - ' \
|
||||
'SUM(CASE WHEN paused_counter is null THEN 0 ELSE paused_counter END)) as total_time, ' \
|
||||
'COUNT(id) AS total_plays ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE user = ?'
|
||||
result = monitor_db.select(query, args=[user])
|
||||
|
||||
for item in result:
|
||||
if item[0]:
|
||||
total_time = item[0]
|
||||
total_plays = item[1]
|
||||
else:
|
||||
total_time = 0
|
||||
total_plays = 0
|
||||
|
||||
row = {'query_days': days,
|
||||
'total_time': total_time,
|
||||
'total_plays': total_plays
|
||||
}
|
||||
|
||||
user_watch_time_stats.append(row)
|
||||
|
||||
return user_watch_time_stats
|
||||
|
||||
def get_user_platform_stats(self, user=None, user_id=None):
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
platform_stats = []
|
||||
result_id = 0
|
||||
|
||||
try:
|
||||
if user_id:
|
||||
query = 'SELECT player, COUNT(player) as player_count, platform ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE user_id = ? ' \
|
||||
'GROUP BY player ' \
|
||||
'ORDER BY player_count DESC'
|
||||
result = monitor_db.select(query, args=[user_id])
|
||||
else:
|
||||
query = 'SELECT player, COUNT(player) as player_count, platform ' \
|
||||
'FROM session_history ' \
|
||||
'WHERE user = ? ' \
|
||||
'GROUP BY player ' \
|
||||
'ORDER BY player_count DESC'
|
||||
result = monitor_db.select(query, args=[user])
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
return None
|
||||
|
||||
for item in result:
|
||||
row = {'platform_name': item[0],
|
||||
'platform_type': item[2],
|
||||
'total_plays': item[1],
|
||||
'result_id': result_id
|
||||
}
|
||||
platform_stats.append(row)
|
||||
result_id += 1
|
||||
|
||||
return platform_stats
|
@@ -13,7 +13,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from plexpy import logger, notifiers, plextv, pmsconnect, common, log_reader, datafactory, graphs
|
||||
from plexpy import logger, notifiers, plextv, pmsconnect, common, log_reader, datafactory, graphs, users
|
||||
from plexpy.helpers import checked, radio
|
||||
|
||||
from mako.lookup import TemplateLookup
|
||||
@@ -64,7 +64,10 @@ class WebInterface(object):
|
||||
|
||||
@cherrypy.expose
|
||||
def home(self):
|
||||
return serve_template(templatename="index.html", title="Home")
|
||||
config = {
|
||||
"home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH
|
||||
}
|
||||
return serve_template(templatename="index.html", title="Home", config=config)
|
||||
|
||||
@cherrypy.expose
|
||||
def welcome(self, **kwargs):
|
||||
@@ -139,16 +142,15 @@ class WebInterface(object):
|
||||
|
||||
@cherrypy.expose
|
||||
def user(self, user=None, user_id=None):
|
||||
user_data = users.Users()
|
||||
if user_id:
|
||||
try:
|
||||
data_factory = datafactory.DataFactory()
|
||||
user_details = data_factory.get_user_details(user_id=user_id)
|
||||
user_details = user_data.get_user_details(user_id=user_id)
|
||||
except:
|
||||
logger.warn("Unable to retrieve friendly name for user_id %s " % user_id)
|
||||
elif user:
|
||||
try:
|
||||
data_factory = datafactory.DataFactory()
|
||||
user_details = data_factory.get_user_details(user=user)
|
||||
user_details = user_data.get_user_details(user=user)
|
||||
except:
|
||||
logger.warn("Unable to retrieve friendly name for user %s " % user)
|
||||
else:
|
||||
@@ -159,13 +161,12 @@ class WebInterface(object):
|
||||
|
||||
@cherrypy.expose
|
||||
def edit_user_dialog(self, user=None, user_id=None, **kwargs):
|
||||
user_data = users.Users()
|
||||
if user_id:
|
||||
data_factory = datafactory.DataFactory()
|
||||
result = data_factory.get_user_friendly_name(user_id=user_id)
|
||||
result = user_data.get_user_friendly_name(user_id=user_id)
|
||||
status_message = ''
|
||||
elif user:
|
||||
data_factory = datafactory.DataFactory()
|
||||
result = data_factory.get_user_friendly_name(user=user)
|
||||
result = user_data.get_user_friendly_name(user=user)
|
||||
status_message = ''
|
||||
else:
|
||||
result = None
|
||||
@@ -179,10 +180,24 @@ class WebInterface(object):
|
||||
do_notify = kwargs.get('do_notify')
|
||||
else:
|
||||
do_notify = 0
|
||||
if 'keep_history' in kwargs:
|
||||
keep_history = kwargs.get('keep_history')
|
||||
else:
|
||||
keep_history = 0
|
||||
if 'thumb' in kwargs:
|
||||
custom_avatar = kwargs['thumb']
|
||||
else:
|
||||
custom_avatar = ''
|
||||
|
||||
user_data = users.Users()
|
||||
if user_id:
|
||||
try:
|
||||
data_factory = datafactory.DataFactory()
|
||||
data_factory.set_user_friendly_name(user_id=user_id, friendly_name=friendly_name, do_notify=do_notify)
|
||||
user_data.set_user_friendly_name(user_id=user_id,
|
||||
friendly_name=friendly_name,
|
||||
do_notify=do_notify,
|
||||
keep_history=keep_history)
|
||||
user_data.set_user_profile_url(user_id=user_id,
|
||||
profile_url=custom_avatar)
|
||||
|
||||
status_message = "Successfully updated user."
|
||||
return status_message
|
||||
@@ -191,8 +206,12 @@ class WebInterface(object):
|
||||
return status_message
|
||||
if user:
|
||||
try:
|
||||
data_factory = datafactory.DataFactory()
|
||||
data_factory.set_user_friendly_name(user=user, friendly_name=friendly_name, do_notify=do_notify)
|
||||
user_data.set_user_friendly_name(user=user,
|
||||
friendly_name=friendly_name,
|
||||
do_notify=do_notify,
|
||||
keep_history=keep_history)
|
||||
user_data.set_user_profile_url(user=user,
|
||||
profile_url=custom_avatar)
|
||||
|
||||
status_message = "Successfully updated user."
|
||||
return status_message
|
||||
@@ -222,11 +241,11 @@ class WebInterface(object):
|
||||
@cherrypy.expose
|
||||
def get_user_list(self, **kwargs):
|
||||
|
||||
data_factory = datafactory.DataFactory()
|
||||
users = data_factory.get_user_list(kwargs=kwargs)
|
||||
user_data = users.Users()
|
||||
user_list = user_data.get_user_list(kwargs=kwargs)
|
||||
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps(users)
|
||||
return json.dumps(user_list)
|
||||
|
||||
@cherrypy.expose
|
||||
def checkGithub(self):
|
||||
@@ -423,8 +442,17 @@ class WebInterface(object):
|
||||
"notify_on_start_body_text": plexpy.CONFIG.NOTIFY_ON_START_BODY_TEXT,
|
||||
"notify_on_stop_subject_text": plexpy.CONFIG.NOTIFY_ON_STOP_SUBJECT_TEXT,
|
||||
"notify_on_stop_body_text": plexpy.CONFIG.NOTIFY_ON_STOP_BODY_TEXT,
|
||||
"notify_on_pause_subject_text": plexpy.CONFIG.NOTIFY_ON_PAUSE_SUBJECT_TEXT,
|
||||
"notify_on_pause_body_text": plexpy.CONFIG.NOTIFY_ON_PAUSE_BODY_TEXT,
|
||||
"notify_on_resume_subject_text": plexpy.CONFIG.NOTIFY_ON_RESUME_SUBJECT_TEXT,
|
||||
"notify_on_resume_body_text": plexpy.CONFIG.NOTIFY_ON_RESUME_BODY_TEXT,
|
||||
"notify_on_buffer_subject_text": plexpy.CONFIG.NOTIFY_ON_BUFFER_SUBJECT_TEXT,
|
||||
"notify_on_buffer_body_text": plexpy.CONFIG.NOTIFY_ON_BUFFER_BODY_TEXT,
|
||||
"notify_on_watched_subject_text": plexpy.CONFIG.NOTIFY_ON_WATCHED_SUBJECT_TEXT,
|
||||
"notify_on_watched_body_text": plexpy.CONFIG.NOTIFY_ON_WATCHED_BODY_TEXT
|
||||
"notify_on_watched_body_text": plexpy.CONFIG.NOTIFY_ON_WATCHED_BODY_TEXT,
|
||||
"home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH,
|
||||
"buffer_threshold": plexpy.CONFIG.BUFFER_THRESHOLD,
|
||||
"buffer_wait": plexpy.CONFIG.BUFFER_WAIT
|
||||
}
|
||||
|
||||
return serve_template(templatename="settings.html", title="Settings", config=config)
|
||||
@@ -732,8 +760,8 @@ class WebInterface(object):
|
||||
@cherrypy.expose
|
||||
def get_user_watch_time_stats(self, user=None, user_id=None, **kwargs):
|
||||
|
||||
data_factory = datafactory.DataFactory()
|
||||
result = data_factory.get_user_watch_time_stats(user_id=user_id, user=user)
|
||||
user_data = users.Users()
|
||||
result = user_data.get_user_watch_time_stats(user_id=user_id, user=user)
|
||||
|
||||
if result:
|
||||
return serve_template(templatename="user_watch_time_stats.html", data=result, title="Watch Stats")
|
||||
@@ -744,8 +772,8 @@ class WebInterface(object):
|
||||
@cherrypy.expose
|
||||
def get_user_platform_stats(self, user=None, user_id=None, **kwargs):
|
||||
|
||||
data_factory = datafactory.DataFactory()
|
||||
result = data_factory.get_user_platform_stats(user_id=user_id, user=user)
|
||||
user_data = users.Users()
|
||||
result = user_data.get_user_platform_stats(user_id=user_id, user=user)
|
||||
|
||||
if result:
|
||||
return serve_template(templatename="user_platform_stats.html", data=result,
|
||||
@@ -823,9 +851,9 @@ class WebInterface(object):
|
||||
elif user:
|
||||
custom_where = [['user', user]]
|
||||
|
||||
data_factory = datafactory.DataFactory()
|
||||
history = data_factory.get_user_unique_ips(kwargs=kwargs,
|
||||
custom_where=custom_where)
|
||||
user_data = users.Users()
|
||||
history = user_data.get_user_unique_ips(kwargs=kwargs,
|
||||
custom_where=custom_where)
|
||||
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps(history)
|
||||
@@ -1212,3 +1240,19 @@ class WebInterface(object):
|
||||
|
||||
return serve_template(templatename="notification_config.html", title="Notification Configuration",
|
||||
data=config, checkboxes=checkboxes)
|
||||
|
||||
@cherrypy.expose
|
||||
def get_notification_agent_triggers(self, config_id, **kwargs):
|
||||
if config_id.isdigit():
|
||||
agents = notifiers.available_notification_agents()
|
||||
for agent in agents:
|
||||
if int(config_id) == agent['id']:
|
||||
this_agent = agent
|
||||
break
|
||||
else:
|
||||
this_agent = None
|
||||
else:
|
||||
return None
|
||||
|
||||
return serve_template(templatename="notification_triggers_modal.html", title="Notification Triggers",
|
||||
data=this_agent)
|
||||
|
Reference in New Issue
Block a user