Compare commits

...

57 Commits

Author SHA1 Message Date
Tim
49669dc7e0 Merge branch 'dev' 2015-12-06 16:16:39 +02:00
Tim
5bdf79606e v1.2.10 2015-12-06 16:16:03 +02:00
drzoidberg33
ff3a9e47df Merge pull request #335 from drzoidberg33/security-fixes
Fix count type graphs.
2015-12-06 16:12:28 +02:00
Tim
a18ba24f4a Fix count type graphs. 2015-12-06 16:07:57 +02:00
Tim
baeb744a7c Merge branch 'dev' 2015-12-06 14:53:04 +02:00
Tim
d07add383f v1.2.9 2015-12-06 14:52:19 +02:00
drzoidberg33
a1f18bc133 Merge pull request #334 from drzoidberg33/security-fixes
Escape input on friendy_name change.
2015-12-06 14:41:31 +02:00
Tim
e00c23bc49 Escape input on friendy_name change. 2015-12-06 14:39:50 +02:00
drzoidberg33
0228a356e4 Merge pull request #333 from drzoidberg33/security-fixes
Better sanitization on templates and datatables output.
2015-12-06 14:18:22 +02:00
Tim
b0fa0d534e Better sanitization on templates and datatables output. 2015-12-06 14:09:38 +02:00
Jonathan Wong
1157fda96c Hide Pushalot notifier message logging 2015-12-06 00:52:43 -08:00
Jonathan Wong
bbf774379d Merge branch 'dev' 2015-12-05 23:45:35 -08:00
Jonathan Wong
24c8c4319d v1.2.8 2015-12-05 23:44:02 -08:00
JonnyWong16
3b8f9f5892 Merge pull request #328 from JonnyWong16/miscellaneous-fixes
Fix recently added
2015-12-05 23:28:49 -08:00
Jonathan Wong
b47ccd06f9 Sanitize player name 2015-12-05 23:26:54 -08:00
Jonathan Wong
8c4292f9ac Fix recently added using added at time 2015-12-05 14:23:10 -08:00
JonnyWong16
a8fbf8ab1d Merge pull request #327 from zobe123/dev
add Microsoft Edge platform
2015-12-05 11:05:30 -08:00
zobe123
38e9938666 Add Microsoft Edge platform image. 2015-12-05 13:31:56 +01:00
zobe123
93c4a0652e Revert "Add Image for Microsoft Edge"
This reverts commit d12b57e1de.
2015-12-05 13:29:10 +01:00
zobe123
2fff6647fd Revert "Update msedge.png"
This reverts commit 36f0f60c49.
2015-12-05 13:29:01 +01:00
zobe123
36f0f60c49 Update msedge.png 2015-12-05 13:02:53 +01:00
zobe123
d12b57e1de Add Image for Microsoft Edge 2015-12-05 13:02:19 +01:00
zobe123
deb16428ed Update script.js 2015-12-05 12:57:26 +01:00
drzoidberg33
a75aba4aee Merge pull request #324 from JonnyWong16/miscellaneous-fixes
Only schedule job for recently added or monitor remote access if sett…
2015-12-04 20:12:44 +02:00
Jonathan Wong
bb5aa2be3d Remember previous recently added items
* Only pull metadata if there are new recently added items since the
last check
2015-12-03 19:50:46 -08:00
Jonathan Wong
ef6ef98541 Clean up settings help text and wording 2015-12-03 19:07:24 -08:00
Jonathan Wong
89f581f63e Only schedule job for recently added or monitor remote access if setting enabled 2015-12-03 18:40:18 -08:00
JonnyWong16
6081fa329b Merge pull request #321 from JonnyWong16/miscellaneous-fixes
Miscellaneous fixes
2015-12-03 10:39:12 -08:00
Jonathan Wong
112811f3e2 Fix subject UTF-8 encode for Prowl notifier 2015-12-02 19:18:04 -08:00
Jonathan Wong
ede07595c3 Match newline characters in notification text 2015-12-02 19:15:46 -08:00
JonnyWong16
08d65623dd Merge pull request #306 from JonnyWong16/miscellaneous-fixes
Delete users
2015-12-02 17:05:39 -08:00
Jonathan Wong
7540b5fb34 Fix recently added notification delay 2015-12-01 22:54:58 -08:00
Jonathan Wong
10c54c2d10 Only show IPv4 addresses 2015-12-01 21:57:02 -08:00
Jonathan Wong
b8d9c8cc47 Set blank metadata so recently added check continues when and item isn't found 2015-12-01 21:50:47 -08:00
Jonathan Wong
bac5018b27 Add channel support to Telegram notifier 2015-12-01 21:31:48 -08:00
Jonathan Wong
c65d9898c8 Add icon for Apple tvOS 2015-12-01 20:05:37 -08:00
Jonathan Wong
d7284c40bd Allow unicode in notification subject and body 2015-12-01 20:03:25 -08:00
Jonathan Wong
1c00f82097 Add ability to delete users 2015-11-27 21:13:17 -08:00
Jonathan Wong
c501923f2b Hide Pushalot notifier response logging 2015-11-27 18:13:20 -08:00
Jonathan Wong
81b22a8c36 Merge branch 'dev' 2015-11-27 06:38:31 -08:00
Jonathan Wong
beb66396fe v1.2.7 2015-11-27 06:33:03 -08:00
Jonathan Wong
aaf3de68cf Fix IP address in notifications 2015-11-27 06:29:41 -08:00
Jonathan Wong
c827c9e825 Fix IP logging again
* Really this time...
2015-11-27 12:33:34 +02:00
Tim van der Westhuizen
5100fdbc96 Merge branch 'dev' 2015-11-27 10:53:28 +02:00
Tim van der Westhuizen
fae3f38a88 v1.2.6 2015-11-27 10:52:29 +02:00
Tim van der Westhuizen
a8236222fb Catch null ratingKeys in plexWatch db importer.
Make sure we have a string when parsing the latinToAscii function.
2015-11-27 10:45:25 +02:00
Jonathan Wong
2be4d9b6c9 Merge branch 'dev' 2015-11-26 19:08:46 -08:00
Jonathan Wong
00934b04d2 Fix IP logging again
* Really this time...
2015-11-26 19:06:51 -08:00
Jonathan Wong
1e28b22c70 Merge branch 'dev' 2015-11-25 20:23:44 -08:00
Jonathan Wong
776061605f Fix IP logging again 2015-11-25 20:20:06 -08:00
Jonathan Wong
683e5663e1 Merge branch 'dev' 2015-11-25 19:16:50 -08:00
Jonathan Wong
090011c9a5 v1.2.5 2015-11-25 19:15:40 -08:00
Jonathan Wong
30b11bce98 Actually add video and audio decision to notifications 2015-11-25 19:13:08 -08:00
Jonathan Wong
2a91ec1560 Fix season and episode number notification option return at least one digit 2015-11-25 19:07:23 -08:00
Jonathan Wong
908ce1ff8d Fix IP address logging 2015-11-25 19:02:59 -08:00
Jonathan Wong
fac47ee68b Fix log spam if notifications turned off 2015-11-25 18:14:08 -08:00
Jonathan Wong
0f8c122ee3 Add video and audio decision to notification options 2015-11-25 18:12:20 -08:00
26 changed files with 654 additions and 392 deletions

View File

@@ -1,5 +1,48 @@
# Changelog # Changelog
## v1.2.10 (2015-12-06)
* Fix broken count graphs regression.
## v1.2.9 (2015-12-06)
* Fix and improve text sanitization.
## v1.2.8 (2015-12-06)
* Fix sanitize player names
* Fix recently added notification delay
* Fix recently added metadata queries
* Fix multiple lines in notification body text
* Fix UTF-8 encoding in Prowl notifications subject line
* Change to only log IPv4 addresses
* Add global toggle for recently added notifcations
* Add feature to delete users
* Add channel support for Telegram notification agent
* Add icon for Apple tvOS
* Add icon for Microsoft Edge
## v1.2.7 (2015-11-27)
* Fix IP address option in notifications
## v1.2.6 (2015-11-27)
* Fixes for IP logging in PMS < 0.9.14.x.
* Fix issue in plexWatch importer when trying to import item with no ratingKey.
## v1.2.5 (2015-11-25)
* Add video_decision and audio_decision to notification options
* Fix IP address logging
* Fix log spam if notifications disabled
## v1.2.4 (2015-11-24) ## v1.2.4 (2015-11-24)
* Add filtering by media type in the history table * Add filtering by media type in the history table

View File

@@ -2374,7 +2374,8 @@ a .home-platforms-instance-list-oval:hover,
top: 5px; top: 5px;
left: 12px; left: 12px;
} }
#users-to-delete > li { #users-to-delete > li,
#users-to-purge > li {
color: #e9a049; color: #e9a049;
} }
#updatebar { #updatebar {

View File

@@ -115,7 +115,7 @@ DOCUMENTATION :: END
success: function(data) { success: function(data) {
$("#edit-user-status-message").html(data); $("#edit-user-status-message").html(data);
if ($.trim(friendly_name) !== '') { if ($.trim(friendly_name) !== '') {
$(".set-username").html(friendly_name); $('.set-username').html(document.createTextNode(friendly_name));
} }
$("#user-profile-thumb").attr('src', thumb); $("#user-profile-thumb").attr('src', thumb);
} }

View File

@@ -39,7 +39,7 @@ user_id Returns the user id for the associated stat.
friendly_name Returns the friendly name of the user for the associated stat. friendly_name Returns the friendly name of the user for the associated stat.
== Only if 'stat_id' is 'top_platform' or 'last_watched' == == Only if 'stat_id' is 'top_platform' or 'last_watched' ==
platform_type Returns the platform name for the associated stat. player Returns the player name for the associated stat.
== Only if 'stat_id' is 'last_watched' == == Only if 'stat_id' is 'last_watched' ==
last_watch Returns the time the media item was last watched. last_watch Returns the time the media item was last watched.
@@ -709,7 +709,7 @@ DOCUMENTATION :: END
<script> <script>
$('#last-watch-stat').text(moment(${top_stat['rows'][0]['last_watch']},"X").format(date_format)); $('#last-watch-stat').text(moment(${top_stat['rows'][0]['last_watch']},"X").format(date_format));
</script> </script>
</span> - ${top_stat['rows'][0]['platform_type']} </span> - ${top_stat['rows'][0]['player']}
</p> </p>
</div> </div>
</div> </div>
@@ -755,7 +755,7 @@ DOCUMENTATION :: END
<script> <script>
$('#home-platforms-instance-list-last-watch-${loop.index + 1}').text(moment(${top_stat['rows'][loop.index]['last_watch']},"X").format(date_format)); $('#home-platforms-instance-list-last-watch-${loop.index + 1}').text(moment(${top_stat['rows'][loop.index]['last_watch']},"X").format(date_format));
</script> </script>
</span> - ${top_stat['rows'][loop.index]['platform_type']} </span> - ${top_stat['rows'][loop.index]['player']}
</p> </p>
</div> </div>
</div> </div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@@ -176,7 +176,9 @@ function getPlatformImagePath(platformName) {
if (platformName.indexOf("Roku") > -1) { if (platformName.indexOf("Roku") > -1) {
return 'interfaces/default/images/platforms/roku.png'; return 'interfaces/default/images/platforms/roku.png';
} else if (platformName.indexOf("Apple TV") > -1) { } else if (platformName.indexOf("Apple TV") > -1) {
return 'interfaces/default/images/platforms/appletv.png'; return 'interfaces/default/images/platforms/atv.png';
} else if (platformName.indexOf("tvOS") > -1) {
return 'interfaces/default/images/platforms/atv.png';
} else if (platformName.indexOf("Firefox") > -1) { } else if (platformName.indexOf("Firefox") > -1) {
return 'interfaces/default/images/platforms/firefox.png'; return 'interfaces/default/images/platforms/firefox.png';
} else if (platformName.indexOf("Chromecast") > -1) { } else if (platformName.indexOf("Chromecast") > -1) {
@@ -201,6 +203,8 @@ function getPlatformImagePath(platformName) {
return 'interfaces/default/images/platforms/safari.png'; return 'interfaces/default/images/platforms/safari.png';
} else if (platformName.indexOf("Internet Explorer") > -1) { } else if (platformName.indexOf("Internet Explorer") > -1) {
return 'interfaces/default/images/platforms/ie.png'; return 'interfaces/default/images/platforms/ie.png';
} else if (platformName.indexOf("Microsoft Edge") > -1) {
return 'interfaces/default/images/platforms/msedge.png';
} else if (platformName.indexOf("Unknown Browser") > -1) { } else if (platformName.indexOf("Unknown Browser") > -1) {
return 'interfaces/default/images/platforms/dafault.png'; return 'interfaces/default/images/platforms/dafault.png';
} else if (platformName.indexOf("Windows-XBMC") > -1) { } else if (platformName.indexOf("Windows-XBMC") > -1) {

View File

@@ -1,3 +1,4 @@
var users_to_delete = [];
var users_to_purge = []; var users_to_purge = [];
users_list_table_options = { users_list_table_options = {
@@ -22,7 +23,8 @@ users_list_table_options = {
"targets": [0], "targets": [0],
"data": null, "data": null,
"createdCell": function (td, cellData, rowData, row, col) { "createdCell": function (td, cellData, rowData, row, col) {
$(td).html('<div class="edit-user-toggles"><button class="btn btn-xs btn-warning" data-id="' + rowData['user_id'] + '" data-toggle="button"><i class="fa fa-eraser fa-fw"></i> Purge</button>&nbsp&nbsp&nbsp' + $(td).html('<div class="edit-user-toggles"><button class="btn btn-xs btn-warning delete-user" data-id="' + rowData['user_id'] + '" data-toggle="button"><i class="fa fa-trash-o fa-fw"></i> Delete</button>&nbsp' +
'<button class="btn btn-xs btn-warning purge-user" data-id="' + rowData['user_id'] + '" data-toggle="button"><i class="fa fa-eraser fa-fw"></i> Purge</button>&nbsp&nbsp&nbsp' +
'<input type="checkbox" id="do_notify-' + rowData['user_id'] + '" name="do_notify" value="1" ' + rowData['do_notify'] + '><label class="edit-tooltip" for="do_notify-' + rowData['user_id'] + '" data-toggle="tooltip" title="Toggle Notifications"><i class="fa fa-bell fa-lg fa-fw"></i></label>&nbsp' + '<input type="checkbox" id="do_notify-' + rowData['user_id'] + '" name="do_notify" value="1" ' + rowData['do_notify'] + '><label class="edit-tooltip" for="do_notify-' + rowData['user_id'] + '" data-toggle="tooltip" title="Toggle Notifications"><i class="fa fa-bell fa-lg fa-fw"></i></label>&nbsp' +
'<input type="checkbox" id="keep_history-' + rowData['user_id'] + '" name="keep_history" value="1" ' + rowData['keep_history'] + '><label class="edit-tooltip" for="keep_history-' + rowData['user_id'] + '" data-toggle="tooltip" title="Toggle History"><i class="fa fa-history fa-lg fa-fw"></i></label>&nbsp'); '<input type="checkbox" id="keep_history-' + rowData['user_id'] + '" name="keep_history" value="1" ' + rowData['keep_history'] + '><label class="edit-tooltip" for="keep_history-' + rowData['user_id'] + '" data-toggle="tooltip" title="Toggle History"><i class="fa fa-history fa-lg fa-fw"></i></label>&nbsp');
// Show/hide user currently doesn't work // Show/hide user currently doesn't work
@@ -286,16 +288,44 @@ $('#users_list_table').on('change', 'td.edit-control > .edit-user-toggles > inpu
}); });
}); });
$('#users_list_table').on('click', 'td.edit-control > .edit-user-toggles > button', function () { $('#users_list_table').on('click', 'td.edit-control > .edit-user-toggles > button.delete-user', function () {
var tr = $(this).parents('tr'); var tr = $(this).parents('tr');
var row = users_list_table.row(tr); var row = users_list_table.row(tr);
var rowData = row.data(); var rowData = row.data();
var index = $.inArray(rowData['user_id'], users_to_purge); var index_delete = $.inArray(rowData['user_id'], users_to_delete);
if (index === -1) { var index_purge = $.inArray(rowData['user_id'], users_to_purge);
if (index_delete === -1) {
users_to_delete.push(rowData['user_id']);
if (index_purge === -1) {
tr.find('button.purge-user').click();
}
} else {
users_to_delete.splice(index_delete, 1);
if (index_purge != -1) {
tr.find('button.purge-user').click();
}
}
$(this).toggleClass('btn-warning').toggleClass('btn-danger');
});
$('#users_list_table').on('click', 'td.edit-control > .edit-user-toggles > button.purge-user', function () {
var tr = $(this).parents('tr');
var row = users_list_table.row(tr);
var rowData = row.data();
var index_delete = $.inArray(rowData['user_id'], users_to_delete);
var index_purge = $.inArray(rowData['user_id'], users_to_purge);
if (index_purge === -1) {
users_to_purge.push(rowData['user_id']); users_to_purge.push(rowData['user_id']);
} else { } else {
users_to_purge.splice(index, 1); users_to_purge.splice(index_purge, 1);
if (index_delete != -1) {
tr.find('button.delete-user').click();
}
} }
$(this).toggleClass('btn-warning').toggleClass('btn-danger'); $(this).toggleClass('btn-warning').toggleClass('btn-danger');
}); });

View File

@@ -313,7 +313,8 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
<input type="text" class="form-control" id="pms_logs_folder" name="pms_logs_folder" value="${config['pms_logs_folder']}" size="30" data-parsley-trigger="change"> <input type="text" class="form-control" id="pms_logs_folder" name="pms_logs_folder" value="${config['pms_logs_folder']}" size="30" data-parsley-trigger="change">
</div> </div>
</div> </div>
<p class="help-block">Set the complete folder path where your Plex Server logs are, shortcuts are not recognized.<br /><a href="https://support.plex.tv/hc/en-us/articles/200250417-Plex-Media-Server-Log-Files" target="_blank">Click here</a> for help. This is required if you enable IP logging. </p> <p class="help-block">Set the complete folder path where your Plex Server logs are, shortcuts are not recognized.<br />
<a href="https://support.plex.tv/hc/en-us/articles/200250417-Plex-Media-Server-Log-Files" target="_blank">Click here</a> for help. This is required if you enable IP logging (for PMS 0.9.12 and below). </p>
</div> </div>
<input type="hidden" id="pms_identifier" name="pms_identifier" value="${config['pms_identifier']}"> <input type="hidden" id="pms_identifier" name="pms_identifier" value="${config['pms_identifier']}">
@@ -414,23 +415,21 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
<div class="padded-header"> <div class="padded-header">
<h3>History Logging</h3> <h3>History Logging</h3>
</div> </div>
<p class="help-block">Keep records of all movie, TV show, or music items played from your Plex Media Server.</p>
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" id="movie_logging_enable" name="movie_logging_enable" value="1" ${config['movie_logging_enable']}> Log Movies <input type="checkbox" id="movie_logging_enable" name="movie_logging_enable" value="1" ${config['movie_logging_enable']}> Enable Movie Logging
</label> </label>
<p class="help-block">Keep records of all movie items played from your Plex Media Server.</p>
</div> </div>
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" id="tv_logging_enable" name="tv_logging_enable" value="1" ${config['tv_logging_enable']}> Log TV Shows <input type="checkbox" id="tv_logging_enable" name="tv_logging_enable" value="1" ${config['tv_logging_enable']}> Enable TV Show Logging
</label> </label>
<p class="help-block">Keep records of all TV show items played from your Plex Media Server.</p>
</div> </div>
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" id="music_logging_enable" name="music_logging_enable" value="1" ${config['music_logging_enable']}> Log Music <input type="checkbox" id="music_logging_enable" name="music_logging_enable" value="1" ${config['music_logging_enable']}> Enable Music Logging
</label> </label>
<p class="help-block">Keep records of all music items played from your Plex Media Server.</p>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="logging_ignore_interval">Ignore Interval</label> <label for="logging_ignore_interval">Ignore Interval</label>
@@ -499,6 +498,11 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
<input type="checkbox" name="music_notify_enable" id="music_notify_enable" value="1" ${config['music_notify_enable']}> Enable Music Notifications <input type="checkbox" name="music_notify_enable" id="music_notify_enable" value="1" ${config['music_notify_enable']}> Enable Music Notifications
</label> </label>
</div> </div>
<div class="checkbox">
<label>
<input type="checkbox" name="notify_recently_added" id="notify_recently_added" value="1" ${config['notify_recently_added']}> Enable Recently Added Notifications
</label>
</div>
<div class="padded-header"> <div class="padded-header">
<h3>Current Activity Notifications</h3> <h3>Current Activity Notifications</h3>
@@ -529,7 +533,7 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
<label> <label>
<input type="checkbox" name="notify_recently_added_grandparent" id="notify_recently_added_grandparent" value="1" ${config['notify_recently_added_grandparent']}> Group notifications for recently added TV Shows or Music <input type="checkbox" name="notify_recently_added_grandparent" id="notify_recently_added_grandparent" value="1" ${config['notify_recently_added_grandparent']}> Group notifications for recently added TV Shows or Music
</label> </label>
<p class="help-block">Enable to only get one notification for recently added Episodes or Tracks. Movies are unaffected.</p> <p class="help-block">Enable to only get one TV Show or Artist notification for recently added Episodes or Tracks. Movies are unaffected.</p>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="notify_recently_added_delay">Notification Delay</label> <label for="notify_recently_added_delay">Notification Delay</label>
@@ -1001,9 +1005,17 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
<td width="150"><strong>{episode_num00}</strong></td> <td width="150"><strong>{episode_num00}</strong></td>
<td>The two digit episode number.</td> <td>The two digit episode number.</td>
</tr> </tr>
<tr>
<td width="150"><strong>{video_decision}</strong></td>
<td>The video transcode decisions for the media item.</td>
</tr>
<tr>
<td width="150"><strong>{audio_decision}</strong></td>
<td>The audio transcode decisions for the media item.</td>
</tr>
<tr> <tr>
<td width="150"><strong>{transcode_decision}</strong></td> <td width="150"><strong>{transcode_decision}</strong></td>
<td>The transcode decisions for the media item.</td> <td>The stream transcode decisions for the media item.</td>
</tr> </tr>
<tr> <tr>
<td width="150"><strong>{year}</strong></td> <td width="150"><strong>{year}</strong></td>

View File

@@ -16,7 +16,7 @@
<button class="btn btn-danger btn-edit" data-toggle="button" aria-pressed="false" autocomplete="off" id="row-edit-mode"> <button class="btn btn-danger btn-edit" data-toggle="button" aria-pressed="false" autocomplete="off" id="row-edit-mode">
<i class="fa fa-pencil"></i> Edit mode <i class="fa fa-pencil"></i> Edit mode
</button>&nbsp </button>&nbsp
<div class="alert alert-danger alert-edit" role="alert" id="row-edit-mode-alert"><i class="fa fa-exclamation-triangle"></i>&nbspSelect users to purge. Data is purged upon exiting edit mode.</div> <div class="alert alert-danger alert-edit" role="alert" id="row-edit-mode-alert"><i class="fa fa-exclamation-triangle"></i>&nbspSelect users to delete/purge. Data is deleted/purged upon exiting edit mode.</div>
</div> </div>
</div> </div>
<div class='table-card-back'> <div class='table-card-back'>
@@ -46,16 +46,16 @@
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-remove"></i></button> <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-remove"></i></button>
<h4 class="modal-title" id="myModalLabel">Confirm Purge</h4> <h4 class="modal-title" id="myModalLabel">Confirm Delete/Purge</h4>
</div> </div>
<div class="modal-body" style="text-align: center;"> <div class="modal-body" style="text-align: center;">
<p>Are you REALLY sure you want to purge all history for the following users:</p>
<ul id="users-to-delete" class="list-unstyled"></ul> <ul id="users-to-delete" class="list-unstyled"></ul>
<ul id="users-to-purge" class="list-unstyled"></ul>
<p>This is permanent and cannot be undone!</p> <p>This is permanent and cannot be undone!</p>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-dark" data-dismiss="modal">Cancel</button> <button type="button" class="btn btn-dark" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger btn-ok" data-dismiss="modal" id="confirm-purge">Purge</button> <button type="button" class="btn btn-danger btn-ok" data-dismiss="modal" id="confirm-delete">Confirm</button>
</div> </div>
</div> </div>
</div> </div>
@@ -74,8 +74,8 @@
<script> <script>
$(document).ready(function () { $(document).ready(function () {
users_list_table_options.ajax = { users_list_table_options.ajax = {
"url": "get_user_list", url: 'get_user_list',
type: "post", type: 'POST',
data: function ( d ) { data: function ( d ) {
return { 'json_data': JSON.stringify( d ) }; return { 'json_data': JSON.stringify( d ) };
} }
@@ -88,18 +88,46 @@
$('#row-edit-mode').on('click', function () { $('#row-edit-mode').on('click', function () {
$('#row-edit-mode-alert').fadeIn(200); $('#row-edit-mode-alert').fadeIn(200);
$('#users-to-delete').html(''); $('#users-to-delete').html('');
$('#users-to-purge').html('');
if ($(this).hasClass('active')) { if ($(this).hasClass('active')) {
if (users_to_purge.length > 0) { if (users_to_delete.length > 0 || users_to_purge.length > 0) {
$('.edit-control').each(function () { $('.edit-control').each(function () {
$(this).find('button.btn-danger').toggleClass('btn-warning').toggleClass('btn-danger'); $(this).find('button.btn-danger').toggleClass('btn-warning').toggleClass('btn-danger');
}); });
for (var i = 0; i < users_to_purge.length; i++) { users_to_purge = $.grep(users_to_purge, function (value) {
$('#users-to-delete').append('<li>' + $('div[data-id=' + users_to_purge[i] + '] > input').val() + '</li>'); return $.inArray(value, users_to_delete) < 0;
});
if (users_to_delete.length > 0) {
$('#users-to-delete').prepend('<p>Are you REALLY sure you want to delete the following users:</p>')
for (var i = 0; i < users_to_delete.length; i++) {
$('#users-to-delete').append('<li>' + $('div[data-id=' + users_to_delete[i] + '] > input').val() + '</li>');
}
} }
if (users_to_purge.length > 0) {
$('#users-to-purge').prepend('<p>Are you REALLY sure you want to purge all history for the following users:</p>')
for (var i = 0; i < users_to_purge.length; i++) {
$('#users-to-purge').append('<li>' + $('div[data-id=' + users_to_purge[i] + '] > input').val() + '</li>');
}
}
$('#confirm-modal').modal(); $('#confirm-modal').modal();
$('#confirm-modal').one('click', '#confirm-purge', function () { $('#confirm-modal').one('click', '#confirm-delete', function () {
for (var i = 0; i < users_to_delete.length; i++) {
$.ajax({
url: 'delete_user',
data: { user_id: users_to_delete[i] },
cache: false,
async: true,
success: function (data) {
var msg = "User deleted";
showMsg(msg, false, true, 2000);
}
});
}
for (var i = 0; i < users_to_purge.length; i++) { for (var i = 0; i < users_to_purge.length; i++) {
$.ajax({ $.ajax({
url: 'delete_all_user_history', url: 'delete_all_user_history',
@@ -129,6 +157,7 @@
}); });
} else { } else {
users_to_delete = [];
users_to_purge = []; users_to_purge = [];
$('.edit-control').each(function () { $('.edit-control').each(function () {
$(this).find('button.btn-danger').toggleClass('btn-warning').toggleClass('btn-danger'); $(this).find('button.btn-danger').toggleClass('btn-warning').toggleClass('btn-danger');
@@ -147,12 +176,12 @@
url: 'refresh_users_list', url: 'refresh_users_list',
cache: false, cache: false,
async: true, async: true,
success : function(data) { success: function(data) {
showMsg('<i class="fa fa-check"></i>&nbspUser list refresh started...',false,true,2000,false) showMsg('<i class="fa fa-check"></i>&nbspUser list refresh started...',false,true,2000,false)
}, },
error: function(jqXHR, textStatus, errorThrown) { error: function(jqXHR, textStatus, errorThrown) {
showMsg('<i class="fa fa-exclamation-circle"></i>&nbspUnable to refresh user list.',false,true,2000,true) showMsg('<i class="fa fa-exclamation-circle"></i>&nbspUnable to refresh user list.',false,true,2000,true)
}, }
}); });
}); });
</script> </script>

View File

@@ -106,13 +106,13 @@ from plexpy import common
<h3>Monitoring</h3> <h3>Monitoring</h3>
<p class="help-block">Keep records of all movie, TV show, or music items played from your Plex Media Server.</p> <p class="help-block">Keep records of all movie, TV show, or music items played from your Plex Media Server.</p>
<div class="wizard-input-section"> <div class="wizard-input-section">
<input type="checkbox" id="movie_logging_enable" name="movie_logging_enable" value="1" ${config['movie_logging_enable']}> Log Movies <input type="checkbox" id="movie_logging_enable" name="movie_logging_enable" value="1" ${config['movie_logging_enable']}> Enable Movie Logging
</div> </div>
<div class="wizard-input-section"> <div class="wizard-input-section">
<input type="checkbox" id="tv_logging_enable" name="tv_logging_enable" value="1" ${config['tv_logging_enable']}> Log TV Shows <input type="checkbox" id="tv_logging_enable" name="tv_logging_enable" value="1" ${config['tv_logging_enable']}> Enable TV Show Logging
</div> </div>
<div class="wizard-input-section"> <div class="wizard-input-section">
<input type="checkbox" id="music_logging_enable" name="music_logging_enable" value="1" ${config['music_logging_enable']}> Log Music <input type="checkbox" id="music_logging_enable" name="music_logging_enable" value="1" ${config['music_logging_enable']}> Enable Music Logging
</div> </div>
<div class="wizard-input-section"> <div class="wizard-input-section">
<label for="logging_ignore_interval">Ignore Interval</label> <label for="logging_ignore_interval">Ignore Interval</label>

View File

@@ -285,10 +285,20 @@ def initialize_scheduler():
hours=12, minutes=0, seconds=0) hours=12, minutes=0, seconds=0)
schedule_job(pmsconnect.get_server_friendly_name, 'Refresh Plex Server Name', schedule_job(pmsconnect.get_server_friendly_name, 'Refresh Plex Server Name',
hours=12, minutes=0, seconds=0) hours=12, minutes=0, seconds=0)
schedule_job(activity_pinger.check_recently_added, 'Check for recently added items',
hours=0, minutes=0, seconds=seconds) if CONFIG.NOTIFY_RECENTLY_ADDED:
schedule_job(activity_pinger.check_server_response, 'Check for server response', schedule_job(activity_pinger.check_recently_added, 'Check for recently added items',
hours=0, minutes=0, seconds=seconds) hours=0, minutes=0, seconds=seconds)
else:
schedule_job(activity_pinger.check_recently_added, 'Check for recently added items',
hours=0, minutes=0, seconds=0)
if CONFIG.MONITOR_REMOTE_ACCESS:
schedule_job(activity_pinger.check_server_response, 'Check for server response',
hours=0, minutes=0, seconds=seconds)
else:
schedule_job(activity_pinger.check_server_response, 'Check for server response',
hours=0, minutes=0, seconds=0)
# If we're not using websockets then fall back to polling # If we're not using websockets then fall back to polling
if not CONFIG.MONITORING_USE_WEBSOCKET or POLLING_FAILOVER: if not CONFIG.MONITORING_USE_WEBSOCKET or POLLING_FAILOVER:
@@ -406,9 +416,9 @@ def dbcheck():
c_db.execute( c_db.execute(
'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, ' 'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, '
'user_id INTEGER DEFAULT NULL UNIQUE, username TEXT NOT NULL UNIQUE, ' 'user_id INTEGER DEFAULT NULL UNIQUE, username TEXT NOT NULL UNIQUE, '
'friendly_name TEXT, thumb TEXT, email TEXT, is_home_user INTEGER DEFAULT NULL, ' 'friendly_name TEXT, thumb TEXT, email TEXT, custom_avatar_url 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)' 'keep_history INTEGER DEFAULT 1, deleted_user INTEGER DEFAULT 0)'
) )
# Upgrade sessions table from earlier versions # Upgrade sessions table from earlier versions
@@ -664,6 +674,15 @@ def dbcheck():
'WHERE t1.id = session_history.id) ' 'WHERE t1.id = session_history.id) '
) )
# Upgrade users table from earlier versions
try:
c_db.execute('SELECT deleted_user from users')
except sqlite3.OperationalError:
logger.debug(u"Altering database. Updating database table users.")
c_db.execute(
'ALTER TABLE users ADD COLUMN deleted_user INTEGER DEFAULT 0'
)
conn_db.commit() conn_db.commit()
c_db.close() c_db.close()

View File

@@ -33,7 +33,11 @@ def check_active_sessions(ws_request=False):
monitor_process = activity_processor.ActivityProcessor() monitor_process = activity_processor.ActivityProcessor()
# logger.debug(u"PlexPy Monitor :: Checking for active streams.") # logger.debug(u"PlexPy Monitor :: Checking for active streams.")
global int_ping_count
if session_list: if session_list:
int_ping_count = 0
media_container = session_list['sessions'] media_container = session_list['sessions']
# Check our temp table for what we must do with the new streams # Check our temp table for what we must do with the new streams
@@ -165,6 +169,16 @@ def check_active_sessions(ws_request=False):
else: else:
logger.debug(u"PlexPy Monitor :: Unable to read session list.") logger.debug(u"PlexPy Monitor :: Unable to read session list.")
int_ping_count += 1
logger.warn(u"PlexPy Monitor :: Unable to get an internal response from the server, ping attempt %s." \
% str(int_ping_count))
if int_ping_count == 3:
# Fire off notifications
threading.Thread(target=notification_handler.notify_timeline,
kwargs=dict(notify_action='intdown')).start()
def check_recently_added(): def check_recently_added():
with monitor_lock: with monitor_lock:
@@ -180,26 +194,29 @@ def check_recently_added():
recently_added = recently_added_list['recently_added'] recently_added = recently_added_list['recently_added']
for item in recently_added: for item in recently_added:
if item['media_type'] == 'movie': metadata = []
metadata_list = pms_connect.get_metadata_details(item['rating_key'])
if metadata_list: if 0 < time_threshold - int(item['added_at']) <= time_interval:
metadata = [metadata_list['metadata']] if item['media_type'] == 'movie':
else: metadata_list = pms_connect.get_metadata_details(item['rating_key'])
logger.error(u"PlexPy Monitor :: Unable to retrieve metadata for rating_key %s" \ if metadata_list:
% str(item['rating_key'])) metadata = [metadata_list['metadata']]
else:
logger.error(u"PlexPy Monitor :: Unable to retrieve metadata for rating_key %s" \
% str(item['rating_key']))
else:
metadata_list = pms_connect.get_metadata_children_details(item['rating_key'])
if metadata_list:
metadata = metadata_list['metadata']
else: else:
logger.error(u"PlexPy Monitor :: Unable to retrieve children metadata for rating_key %s" \ metadata_list = pms_connect.get_metadata_children_details(item['rating_key'])
% str(item['rating_key'])) if metadata_list:
metadata = metadata_list['metadata']
else:
logger.error(u"PlexPy Monitor :: Unable to retrieve children metadata for rating_key %s" \
% str(item['rating_key']))
if metadata: if metadata:
if not plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT: if not plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT:
for item in metadata: for item in metadata:
if 0 < int(item['added_at']) - time_threshold <= time_interval: if 0 < time_threshold - int(item['added_at']) <= time_interval:
logger.debug(u"PlexPy Monitor :: Library item %s has been added to Plex." % str(item['rating_key'])) logger.debug(u"PlexPy Monitor :: Library item %s has been added to Plex." % str(item['rating_key']))
# Fire off notifications # Fire off notifications
threading.Thread(target=notification_handler.notify_timeline, threading.Thread(target=notification_handler.notify_timeline,
@@ -208,7 +225,7 @@ def check_recently_added():
else: else:
item = max(metadata, key=lambda x:x['added_at']) item = max(metadata, key=lambda x:x['added_at'])
if 0 < int(item['added_at']) - time_threshold <= time_interval: if 0 < time_threshold - int(item['added_at']) <= time_interval:
if item['media_type'] == 'episode' or item['media_type'] == 'track': if item['media_type'] == 'episode' or item['media_type'] == 'track':
metadata_list = pms_connect.get_metadata_details(item['grandparent_rating_key']) metadata_list = pms_connect.get_metadata_details(item['grandparent_rating_key'])
@@ -229,20 +246,10 @@ def check_server_response():
pms_connect = pmsconnect.PmsConnect() pms_connect = pmsconnect.PmsConnect()
server_response = pms_connect.get_server_response() server_response = pms_connect.get_server_response()
global int_ping_count
global ext_ping_count global ext_ping_count
# Check for internal server response
if not server_response:
int_ping_count += 1
logger.warn(u"PlexPy Monitor :: Unable to get an internal response from the server, ping attempt %s." \
% str(int_ping_count))
# Reset internal ping counter
else:
int_ping_count = 0
# Check for remote access # Check for remote access
if server_response and plexpy.CONFIG.MONITOR_REMOTE_ACCESS: if server_response:
mapping_state = server_response['mapping_state'] mapping_state = server_response['mapping_state']
mapping_error = server_response['mapping_error'] mapping_error = server_response['mapping_error']
@@ -261,11 +268,6 @@ def check_server_response():
else: else:
ext_ping_count = 0 ext_ping_count = 0
if int_ping_count == 3:
# Fire off notifications
threading.Thread(target=notification_handler.notify_timeline,
kwargs=dict(notify_action='intdown')).start()
if ext_ping_count == 3: if ext_ping_count == 3:
# Fire off notifications # Fire off notifications
threading.Thread(target=notification_handler.notify_timeline, threading.Thread(target=notification_handler.notify_timeline,

View File

@@ -39,7 +39,7 @@ class ActivityProcessor(object):
'parent_title': session['parent_title'], 'parent_title': session['parent_title'],
'grandparent_title': session['grandparent_title'], 'grandparent_title': session['grandparent_title'],
'friendly_name': session['friendly_name'], 'friendly_name': session['friendly_name'],
'ip_address': session['ip_address'], #'ip_address': session['ip_address'],
'player': session['player'], 'player': session['player'],
'platform': session['platform'], 'platform': session['platform'],
'parent_rating_key': session['parent_rating_key'], 'parent_rating_key': session['parent_rating_key'],
@@ -67,6 +67,10 @@ class ActivityProcessor(object):
'transcode_height': session['transcode_height'] 'transcode_height': session['transcode_height']
} }
# Add ip_address back into values
if session['ip_address']:
values.update({'ip_address': session['ip_address']})
keys = {'session_key': session['session_key'], keys = {'session_key': session['session_key'],
'rating_key': session['rating_key']} 'rating_key': session['rating_key']}
@@ -75,23 +79,22 @@ class ActivityProcessor(object):
if result == 'insert': if result == 'insert':
# Push any notifications - Push it on it's own thread so we don't hold up our db actions # Push any notifications - Push it on it's own thread so we don't hold up our db actions
if notify: if notify:
values.update({'ip_address': session['ip_address']})
threading.Thread(target=notification_handler.notify, threading.Thread(target=notification_handler.notify,
kwargs=dict(stream_data=values, notify_action='play')).start() kwargs=dict(stream_data=values, notify_action='play')).start()
# If it's our first write then time stamp it.
started = int(time.time()) started = int(time.time())
timestamp = {'started': started} timestamp = {'started': started}
self.db.upsert('sessions', timestamp, keys)
# Try and grab IP address from logs (fallback if not on PMS 0.9.14 and above) # Try and grab IP address from logs (fallback if not on PMS 0.9.14 and above)
if not session['ip_address']: if not session['ip_address']:
if plexpy.CONFIG.IP_LOGGING_ENABLE and plexpy.CONFIG.PMS_LOGS_FOLDER: if plexpy.CONFIG.IP_LOGGING_ENABLE and plexpy.CONFIG.PMS_LOGS_FOLDER:
ip_address = self.find_session_ip(rating_key=session['rating_key'], ip_address = self.find_session_ip(rating_key=session['rating_key'],
machine_id=session['machine_id']) machine_id=session['machine_id'])
timestamp.update({'ip_address': ip_address}) ip_address = {'ip_address': ip_address}
else: self.db.upsert('sessions', ip_address, keys)
timestamp.update({'ip_address': None})
# If it's our first write then time stamp it.
self.db.upsert('sessions', timestamp, keys)
def write_session_history(self, session=None, import_metadata=None, is_import=False, import_ignore_interval=0): def write_session_history(self, session=None, import_metadata=None, is_import=False, import_ignore_interval=0):
from plexpy import users from plexpy import users
@@ -283,16 +286,16 @@ class ActivityProcessor(object):
# The logged IP will always be the first match and we don't want localhost entries # The logged IP will always be the first match and we don't want localhost entries
if ipv4[0] != '127.0.0.1': if ipv4[0] != '127.0.0.1':
# check if IPv4 mapped IPv6 address (::ffff:xxx.xxx.xxx.xxx) # check if IPv4 mapped IPv6 address (::ffff:xxx.xxx.xxx.xxx)
if '::ffff:' + ipv4[0] in line: #if '::ffff:' + ipv4[0] in line:
logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s " # logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s "
u"and machineIdentifier %s." # u"and machineIdentifier %s."
% ('::ffff:' + ipv4[0], rating_key, machine_id)) # % ('::ffff:' + ipv4[0], rating_key, machine_id))
return '::ffff:' + ipv4[0] # return '::ffff:' + ipv4[0]
else: #else:
logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s " logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s "
u"and machineIdentifier %s." u"and machineIdentifier %s."
% (ipv4[0], rating_key, machine_id)) % (ipv4[0], rating_key, machine_id))
return ipv4[0] return ipv4[0]
logger.debug(u"PlexPy ActivityProcessor :: Unable to find IP address on first pass. " logger.debug(u"PlexPy ActivityProcessor :: Unable to find IP address on first pass. "
u"Attempting fallback check in 5 seconds...") u"Attempting fallback check in 5 seconds...")
@@ -312,14 +315,14 @@ class ActivityProcessor(object):
if ipv4: if ipv4:
# The logged IP will always be the first match and we don't want localhost entries # The logged IP will always be the first match and we don't want localhost entries
if ipv4[0] != '127.0.0.1': if ipv4[0] != '127.0.0.1':
if '::ffff:' + ipv4[0] in line: #if '::ffff:' + ipv4[0] in line:
logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s." % # logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s." %
('::ffff:' + ipv4[0], rating_key)) # ('::ffff:' + ipv4[0], rating_key))
return '::ffff:' + ipv4[0] # return '::ffff:' + ipv4[0]
else: #else:
logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s." % logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s." %
(ipv4[0], rating_key)) (ipv4[0], rating_key))
return ipv4[0] return ipv4[0]
logger.debug(u"PlexPy ActivityProcessor :: Unable to find IP address on fallback search. Not logging IP address.") logger.debug(u"PlexPy ActivityProcessor :: Unable to find IP address on fallback search. Not logging IP address.")

View File

@@ -151,27 +151,28 @@ _CONFIG_DEFINITIONS = {
'NMA_ON_EXTDOWN': (int, 'NMA', 0), 'NMA_ON_EXTDOWN': (int, 'NMA', 0),
'NMA_ON_INTDOWN': (int, 'NMA', 0), 'NMA_ON_INTDOWN': (int, 'NMA', 0),
'NOTIFY_CONSECUTIVE': (int, 'Monitoring', 1), 'NOTIFY_CONSECUTIVE': (int, 'Monitoring', 1),
'NOTIFY_RECENTLY_ADDED': (int, 'Monitoring', 0),
'NOTIFY_RECENTLY_ADDED_GRANDPARENT': (int, 'Monitoring', 0), 'NOTIFY_RECENTLY_ADDED_GRANDPARENT': (int, 'Monitoring', 0),
'NOTIFY_RECENTLY_ADDED_DELAY': (int, 'Monitoring', 60), 'NOTIFY_RECENTLY_ADDED_DELAY': (int, 'Monitoring', 60),
'NOTIFY_WATCHED_PERCENT': (int, 'Monitoring', 85), 'NOTIFY_WATCHED_PERCENT': (int, 'Monitoring', 85),
'NOTIFY_ON_START_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_START_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_START_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) started playing {title}.'), 'NOTIFY_ON_START_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) started playing {title}.'),
'NOTIFY_ON_STOP_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_STOP_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_STOP_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has stopped {title}.'), 'NOTIFY_ON_STOP_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) has stopped {title}.'),
'NOTIFY_ON_PAUSE_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_PAUSE_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_PAUSE_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has paused {title}.'), 'NOTIFY_ON_PAUSE_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) has paused {title}.'),
'NOTIFY_ON_RESUME_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_RESUME_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_RESUME_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has resumed {title}.'), 'NOTIFY_ON_RESUME_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) has resumed {title}.'),
'NOTIFY_ON_BUFFER_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_BUFFER_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_BUFFER_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) is buffering {title}.'), 'NOTIFY_ON_BUFFER_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) is buffering {title}.'),
'NOTIFY_ON_WATCHED_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_WATCHED_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_WATCHED_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has watched {title}.'), 'NOTIFY_ON_WATCHED_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) has watched {title}.'),
'NOTIFY_ON_CREATED_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_CREATED_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_CREATED_BODY_TEXT': (str, 'Monitoring', '{title} was recently added to Plex.'), 'NOTIFY_ON_CREATED_BODY_TEXT': (unicode, 'Monitoring', '{title} was recently added to Plex.'),
'NOTIFY_ON_EXTDOWN_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_EXTDOWN_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_EXTDOWN_BODY_TEXT': (str, 'Monitoring', 'The Plex Media Server remote access is down.'), 'NOTIFY_ON_EXTDOWN_BODY_TEXT': (unicode, 'Monitoring', 'The Plex Media Server remote access is down.'),
'NOTIFY_ON_INTDOWN_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'), 'NOTIFY_ON_INTDOWN_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
'NOTIFY_ON_INTDOWN_BODY_TEXT': (str, 'Monitoring', 'The Plex Media Server is down.'), 'NOTIFY_ON_INTDOWN_BODY_TEXT': (unicode, 'Monitoring', 'The Plex Media Server is down.'),
'OSX_NOTIFY_APP': (str, 'OSX_Notify', '/Applications/PlexPy'), 'OSX_NOTIFY_APP': (str, 'OSX_Notify', '/Applications/PlexPy'),
'OSX_NOTIFY_ENABLED': (int, 'OSX_Notify', 0), 'OSX_NOTIFY_ENABLED': (int, 'OSX_Notify', 0),
'OSX_NOTIFY_ON_PLAY': (int, 'OSX_Notify', 0), 'OSX_NOTIFY_ON_PLAY': (int, 'OSX_Notify', 0),
@@ -250,7 +251,7 @@ _CONFIG_DEFINITIONS = {
'REFRESH_USERS_ON_STARTUP': (int, 'Monitoring', 1), 'REFRESH_USERS_ON_STARTUP': (int, 'Monitoring', 1),
'TELEGRAM_BOT_TOKEN': (str, 'Telegram', ''), 'TELEGRAM_BOT_TOKEN': (str, 'Telegram', ''),
'TELEGRAM_ENABLED': (int, 'Telegram', 0), 'TELEGRAM_ENABLED': (int, 'Telegram', 0),
'TELEGRAM_CHAT_ID': (int, 'Telegram', 0), 'TELEGRAM_CHAT_ID': (str, 'Telegram', ''),
'TELEGRAM_ON_PLAY': (int, 'Telegram', 0), 'TELEGRAM_ON_PLAY': (int, 'Telegram', 0),
'TELEGRAM_ON_STOP': (int, 'Telegram', 0), 'TELEGRAM_ON_STOP': (int, 'Telegram', 0),
'TELEGRAM_ON_PAUSE': (int, 'Telegram', 0), 'TELEGRAM_ON_PAUSE': (int, 'Telegram', 0),

View File

@@ -58,7 +58,14 @@ class MonitorDatabase(object):
self.connection.execute("PRAGMA journal_mode = %s" % plexpy.CONFIG.JOURNAL_MODE) self.connection.execute("PRAGMA journal_mode = %s" % plexpy.CONFIG.JOURNAL_MODE)
# 64mb of cache memory, probably need to make it user configurable # 64mb of cache memory, probably need to make it user configurable
self.connection.execute("PRAGMA cache_size=-%s" % (get_cache_size() * 1024)) self.connection.execute("PRAGMA cache_size=-%s" % (get_cache_size() * 1024))
self.connection.row_factory = sqlite3.Row self.connection.row_factory = self.dict_factory
def dict_factory(self, cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
def action(self, query, args=None, return_last_id=False): def action(self, query, args=None, return_last_id=False):
if query is None: if query is None:

View File

@@ -28,7 +28,7 @@ class DataFactory(object):
def get_history(self, kwargs=None, custom_where=None, grouping=0, watched_percent=85): def get_history(self, kwargs=None, custom_where=None, grouping=0, watched_percent=85):
data_tables = datatables.DataTables() data_tables = datatables.DataTables()
group_by = ['session_history.reference_id'] if grouping else ['session_history.id'] group_by = ['session_history.reference_id'] if grouping else ['session_history.id']
columns = ['session_history.reference_id', columns = ['session_history.reference_id',
@@ -37,8 +37,8 @@ class DataFactory(object):
'MIN(started) AS started', 'MIN(started) AS started',
'MAX(stopped) AS stopped', 'MAX(stopped) AS stopped',
'SUM(CASE WHEN stopped > 0 THEN (stopped - started) ELSE 0 END) - \ 'SUM(CASE WHEN stopped > 0 THEN (stopped - started) ELSE 0 END) - \
SUM(CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) AS duration', SUM(CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) AS duration',
'SUM(CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) AS paused_counter', 'SUM(CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) AS paused_counter',
'session_history.user_id', 'session_history.user_id',
'session_history.user', 'session_history.user',
'(CASE WHEN users.friendly_name IS NULL THEN users.username ELSE users.friendly_name END) as friendly_name', '(CASE WHEN users.friendly_name IS NULL THEN users.username ELSE users.friendly_name END) as friendly_name',
@@ -88,7 +88,7 @@ class DataFactory(object):
'error': 'Unable to execute database query.'} 'error': 'Unable to execute database query.'}
history = query['result'] history = query['result']
rows = [] rows = []
for item in history: for item in history:
if item["media_type"] == 'episode' and item["parent_thumb"]: if item["media_type"] == 'episode' and item["parent_thumb"]:
@@ -108,6 +108,9 @@ class DataFactory(object):
# Rename Mystery platform names # Rename Mystery platform names
platform = common.PLATFORM_NAME_OVERRIDES.get(item["platform"], item["platform"]) platform = common.PLATFORM_NAME_OVERRIDES.get(item["platform"], item["platform"])
# Sanitize player name
player = helpers.sanitize(item["player"])
row = {"reference_id": item["reference_id"], row = {"reference_id": item["reference_id"],
"id": item["id"], "id": item["id"],
"date": item["date"], "date": item["date"],
@@ -119,7 +122,7 @@ class DataFactory(object):
"user": item["user"], "user": item["user"],
"friendly_name": item["friendly_name"], "friendly_name": item["friendly_name"],
"platform": platform, "platform": platform,
"player": item["player"], "player": player,
"ip_address": item["ip_address"], "ip_address": item["ip_address"],
"media_type": item["media_type"], "media_type": item["media_type"],
"rating_key": item["rating_key"], "rating_key": item["rating_key"],
@@ -140,7 +143,7 @@ class DataFactory(object):
} }
rows.append(row) rows.append(row)
dict = {'recordsFiltered': query['filteredCount'], dict = {'recordsFiltered': query['filteredCount'],
'recordsTotal': query['totalCount'], 'recordsTotal': query['totalCount'],
'data': rows, 'data': rows,
@@ -183,19 +186,19 @@ class DataFactory(object):
return None return None
for item in result: for item in result:
row = {'title': item[1], row = {'title': item['grandparent_title'],
'total_plays': item[2], 'total_plays': item['total_plays'],
'total_duration': item[3], 'total_duration': item['total_duration'],
'users_watched': '', 'users_watched': '',
'rating_key': item[4], 'rating_key': item['grandparent_rating_key'],
'last_play': item[5], 'last_play': item['last_watch'],
'grandparent_thumb': item[6], 'grandparent_thumb': item['grandparent_thumb'],
'thumb': '', 'thumb': '',
'user': '', 'user': '',
'friendly_name': '', 'friendly_name': '',
'platform_type': '', 'platform_type': '',
'platform': '', 'platform': '',
'row_id': item[0] 'row_id': item['id']
} }
top_tv.append(row) top_tv.append(row)
@@ -231,18 +234,18 @@ class DataFactory(object):
return None return None
for item in result: for item in result:
row = {'title': item[1], row = {'title': item['grandparent_title'],
'users_watched': item[2], 'users_watched': item['users_watched'],
'rating_key': item[3], 'rating_key': item['grandparent_rating_key'],
'last_play': item[4], 'last_play': item['last_watch'],
'total_plays': item[5], 'total_plays': item['total_plays'],
'grandparent_thumb': item[7], 'grandparent_thumb': item['grandparent_thumb'],
'thumb': '', 'thumb': '',
'user': '', 'user': '',
'friendly_name': '', 'friendly_name': '',
'platform_type': '', 'platform_type': '',
'platform': '', 'platform': '',
'row_id': item[0] 'row_id': item['id']
} }
popular_tv.append(row) popular_tv.append(row)
@@ -275,19 +278,19 @@ class DataFactory(object):
return None return None
for item in result: for item in result:
row = {'title': item[1], row = {'title': item['full_title'],
'total_plays': item[2], 'total_plays': item['total_plays'],
'total_duration': item[3], 'total_duration': item['total_duration'],
'users_watched': '', 'users_watched': '',
'rating_key': item[4], 'rating_key': item['rating_key'],
'last_play': item[5], 'last_play': item['last_watch'],
'grandparent_thumb': '', 'grandparent_thumb': '',
'thumb': item[6], 'thumb': item['thumb'],
'user': '', 'user': '',
'friendly_name': '', 'friendly_name': '',
'platform_type': '', 'platform_type': '',
'platform': '', 'platform': '',
'row_id': item[0] 'row_id': item['id']
} }
top_movies.append(row) top_movies.append(row)
@@ -323,18 +326,18 @@ class DataFactory(object):
return None return None
for item in result: for item in result:
row = {'title': item[1], row = {'title': item['full_title'],
'users_watched': item[2], 'users_watched': item['users_watched'],
'rating_key': item[3], 'rating_key': item['rating_key'],
'last_play': item[4], 'last_play': item['last_watch'],
'total_plays': item[5], 'total_plays': item['total_plays'],
'grandparent_thumb': '', 'grandparent_thumb': '',
'thumb': item[7], 'thumb': item['thumb'],
'user': '', 'user': '',
'friendly_name': '', 'friendly_name': '',
'platform_type': '', 'platform_type': '',
'platform': '', 'platform': '',
'row_id': item[0] 'row_id': item['id']
} }
popular_movies.append(row) popular_movies.append(row)
@@ -367,19 +370,19 @@ class DataFactory(object):
return None return None
for item in result: for item in result:
row = {'title': item[1], row = {'title': item['grandparent_title'],
'total_plays': item[2], 'total_plays': item['total_plays'],
'total_duration': item[3], 'total_duration': item['total_duration'],
'users_watched': '', 'users_watched': '',
'rating_key': item[4], 'rating_key': item['grandparent_rating_key'],
'last_play': item[5], 'last_play': item['last_watch'],
'grandparent_thumb': item[6], 'grandparent_thumb': item['grandparent_thumb'],
'thumb': '', 'thumb': '',
'user': '', 'user': '',
'friendly_name': '', 'friendly_name': '',
'platform_type': '', 'platform_type': '',
'platform': '', 'platform': '',
'row_id': item[0] 'row_id': item['id']
} }
top_music.append(row) top_music.append(row)
@@ -415,18 +418,18 @@ class DataFactory(object):
return None return None
for item in result: for item in result:
row = {'title': item[1], row = {'title': item['grandparent_title'],
'users_watched': item[2], 'users_watched': item['users_watched'],
'rating_key': item[3], 'rating_key': item['grandparent_rating_key'],
'last_play': item[4], 'last_play': item['last_watch'],
'total_plays': item[5], 'total_plays': item['total_plays'],
'grandparent_thumb': item[7], 'grandparent_thumb': item['grandparent_thumb'],
'thumb': '', 'thumb': '',
'user': '', 'user': '',
'friendly_name': '', 'friendly_name': '',
'platform_type': '', 'platform_type': '',
'platform': '', 'platform': '',
'row_id': item[0] 'row_id': item['id']
} }
popular_music.append(row) popular_music.append(row)
@@ -460,17 +463,17 @@ class DataFactory(object):
return None return None
for item in result: for item in result:
if not item[5] or item[5] == '': if not item['thumb'] or item['thumb'] == '':
user_thumb = common.DEFAULT_USER_THUMB user_thumb = common.DEFAULT_USER_THUMB
else: else:
user_thumb = item[5] user_thumb = item['thumb']
row = {'user': item[0], row = {'user': item['user'],
'user_id': item[6], 'user_id': item['user_id'],
'friendly_name': item[1], 'friendly_name': item['friendly_name'],
'total_plays': item[2], 'total_plays': item['total_plays'],
'total_duration': item[3], 'total_duration': item['total_duration'],
'last_play': item[4], 'last_play': item['last_watch'],
'user_thumb': user_thumb, 'user_thumb': user_thumb,
'grandparent_thumb': '', 'grandparent_thumb': '',
'users_watched': '', 'users_watched': '',
@@ -509,12 +512,12 @@ class DataFactory(object):
for item in result: for item in result:
# Rename Mystery platform names # Rename Mystery platform names
platform_type = common.PLATFORM_NAME_OVERRIDES.get(item[0], item[0]) platform_type = common.PLATFORM_NAME_OVERRIDES.get(item['platform'], item['platform'])
row = {'platform': item[0], row = {'platform': item['platform'],
'total_plays': item[1], 'total_plays': item['total_plays'],
'total_duration': item[2], 'total_duration': item['total_duration'],
'last_play': item[3], 'last_play': item['last_watch'],
'platform_type': platform_type, 'platform_type': platform_type,
'title': '', 'title': '',
'thumb': '', 'thumb': '',
@@ -545,7 +548,7 @@ class DataFactory(object):
'session_history_metadata.thumb, ' \ 'session_history_metadata.thumb, ' \
'session_history_metadata.grandparent_thumb, ' \ 'session_history_metadata.grandparent_thumb, ' \
'MAX(session_history.started) as last_watch, ' \ 'MAX(session_history.started) as last_watch, ' \
'session_history.player as platform, ' \ 'session_history.player, ' \
'((CASE WHEN session_history.view_offset IS NULL THEN 0.1 ELSE \ '((CASE WHEN session_history.view_offset IS NULL THEN 0.1 ELSE \
session_history.view_offset * 1.0 END) / \ session_history.view_offset * 1.0 END) / \
(CASE WHEN session_history_metadata.duration IS NULL THEN 1.0 ELSE \ (CASE WHEN session_history_metadata.duration IS NULL THEN 1.0 ELSE \
@@ -567,22 +570,25 @@ class DataFactory(object):
return None return None
for item in result: for item in result:
if not item[8] or item[8] == '': if not item['grandparent_thumb'] or item['grandparent_thumb'] == '':
thumb = item[7] thumb = item['thumb']
else: else:
thumb = item[8] thumb = item['grandparent_thumb']
row = {'row_id': item[0], # Sanitize player name
'user': item[1], player = helpers.sanitize(item["player"])
'friendly_name': item[2],
'user_id': item[3], row = {'row_id': item['id'],
'user_thumb': item[4], 'user': item['user'],
'title': item[5], 'friendly_name': item['friendly_name'],
'rating_key': item[6], 'user_id': item['user_id'],
'user_thumb': item['user_thumb'],
'title': item['full_title'],
'rating_key': item['rating_key'],
'thumb': thumb, 'thumb': thumb,
'grandparent_thumb': item[8], 'grandparent_thumb': item['grandparent_thumb'],
'last_watch': item[9], 'last_watch': item['last_watch'],
'platform_type': item[10], 'player': player,
} }
last_watched.append(row) last_watched.append(row)
@@ -609,26 +615,26 @@ class DataFactory(object):
stream_output = {} stream_output = {}
for item in result: for item in result:
stream_output = {'container': item[0], stream_output = {'container': item['container'],
'bitrate': item[1], 'bitrate': item['bitrate'],
'video_resolution': item[2], 'video_resolution': item['video_resolution'],
'width': item[3], 'width': item['width'],
'height': item[4], 'height': item['height'],
'aspect_ratio': item[5], 'aspect_ratio': item['aspect_ratio'],
'video_framerate': item[6], 'video_framerate': item['video_framerate'],
'video_codec': item[7], 'video_codec': item['video_codec'],
'audio_codec': item[8], 'audio_codec': item['audio_codec'],
'audio_channels': item[9], 'audio_channels': item['audio_channels'],
'transcode_video_dec': item[10], 'transcode_video_dec': item['video_decision'],
'transcode_video_codec': item[11], 'transcode_video_codec': item['transcode_video_codec'],
'transcode_height': item[12], 'transcode_height': item['transcode_height'],
'transcode_width': item[13], 'transcode_width': item['transcode_width'],
'transcode_audio_dec': item[14], 'transcode_audio_dec': item['audio_decision'],
'transcode_audio_codec': item[15], 'transcode_audio_codec': item['transcode_audio_codec'],
'transcode_audio_channels': item[16], 'transcode_audio_channels': item['transcode_audio_channels'],
'media_type': item[17], 'media_type': item['media_type'],
'title': item[18], 'title': item['title'],
'grandparent_title': item[19] 'grandparent_title': item['grandparent_title']
} }
return stream_output return stream_output
@@ -678,25 +684,25 @@ class DataFactory(object):
return None return None
for row in result: for row in result:
if row[1] == 'episode' and row[8]: if row['media_type'] == 'episode' and row['parent_thumb']:
thumb = row[8] thumb = row['parent_thumb']
elif row[1] == 'episode': elif row['media_type'] == 'episode':
thumb = row[9] thumb = row['grandparent_thumb']
else: else:
thumb = row[7] thumb = row['thumb']
recent_output = {'row_id': row[0], recent_output = {'row_id': row['id'],
'type': row[1], 'type': row['media_type'],
'rating_key': row[2], 'rating_key': row['rating_key'],
'title': row[4], 'title': row['title'],
'parent_title': row[5], 'parent_title': row['parent_title'],
'grandparent_title': row[6], 'grandparent_title': row['grandparent_title'],
'thumb': thumb, 'thumb': thumb,
'index': row[10], 'index': row['media_index'],
'parent_index': row[11], 'parent_index': row['parent_media_index'],
'year': row[12], 'year': row['year'],
'time': row[13], 'time': row['started'],
'user': row[14] 'user': row['user']
} }
recently_watched.append(recent_output) recently_watched.append(recent_output)
@@ -800,6 +806,40 @@ class DataFactory(object):
else: else:
return 'Unable to delete items. Input user_id not valid.' return 'Unable to delete items. Input user_id not valid.'
def delete_user(self, user_id=None):
monitor_db = database.MonitorDatabase()
if user_id.isdigit():
self.delete_all_user_history(user_id)
logger.info(u"PlexPy DataFactory :: Deleting user with id %s from database." % user_id)
monitor_db.action('UPDATE users SET deleted_user = 1 WHERE user_id = ?', [user_id])
monitor_db.action('UPDATE users SET keep_history = 0 WHERE user_id = ?', [user_id])
monitor_db.action('UPDATE users SET do_notify = 0 WHERE user_id = ?', [user_id])
return 'Deleted user with id %s.' % user_id
else:
return 'Unable to delete user. Input user_id not valid.'
def undelete_user(self, user_id=None, username=None):
monitor_db = database.MonitorDatabase()
if user_id and user_id.isdigit():
logger.info(u"PlexPy DataFactory :: Re-adding user with id %s to database." % user_id)
monitor_db.action('UPDATE users SET deleted_user = 0 WHERE user_id = ?', [user_id])
monitor_db.action('UPDATE users SET keep_history = 1 WHERE user_id = ?', [user_id])
monitor_db.action('UPDATE users SET do_notify = 1 WHERE user_id = ?', [user_id])
return 'Re-added user with id %s.' % user_id
elif username:
logger.info(u"PlexPy DataFactory :: Re-adding user with username %s to database." % username)
monitor_db.action('UPDATE users SET deleted_user = 0 WHERE username = ?', [username])
monitor_db.action('UPDATE users SET keep_history = 1 WHERE username = ?', [username])
monitor_db.action('UPDATE users SET do_notify = 1 WHERE username = ?', [username])
return 'Re-added user with username %s.' % username
else:
return 'Unable to re-add user. Input user_id or username not valid.'
def get_search_query(self, rating_key=''): def get_search_query(self, rating_key=''):
monitor_db = database.MonitorDatabase() monitor_db = database.MonitorDatabase()
@@ -928,7 +968,7 @@ class DataFactory(object):
}) })
key_list = grandparents key_list = grandparents
return key_list return key_list
def update_rating_key(self, old_key_list='', new_key_list='', media_type=''): def update_rating_key(self, old_key_list='', new_key_list='', media_type=''):
@@ -950,48 +990,48 @@ class DataFactory(object):
mapping = {} mapping = {}
if old_key_list and new_key_list: if old_key_list and new_key_list:
mapping = get_pairs(old_key_list, new_key_list) mapping = get_pairs(old_key_list, new_key_list)
if mapping: if mapping:
logger.info(u"PlexPy DataFactory :: Updating rating keys in the database.") logger.info(u"PlexPy DataFactory :: Updating rating keys in the database.")
for old_key, new_key in mapping.iteritems(): for old_key, new_key in mapping.iteritems():
# check rating_key (3 tables) # check rating_key (3 tables)
monitor_db.action('UPDATE session_history SET rating_key = ? WHERE rating_key = ?', monitor_db.action('UPDATE session_history SET rating_key = ? WHERE rating_key = ?',
[new_key, old_key]) [new_key, old_key])
monitor_db.action('UPDATE session_history_media_info SET rating_key = ? WHERE rating_key = ?', monitor_db.action('UPDATE session_history_media_info SET rating_key = ? WHERE rating_key = ?',
[new_key, old_key]) [new_key, old_key])
monitor_db.action('UPDATE session_history_metadata SET rating_key = ? WHERE rating_key = ?', monitor_db.action('UPDATE session_history_metadata SET rating_key = ? WHERE rating_key = ?',
[new_key, old_key]) [new_key, old_key])
# check parent_rating_key (2 tables) # check parent_rating_key (2 tables)
monitor_db.action('UPDATE session_history SET parent_rating_key = ? WHERE parent_rating_key = ?', monitor_db.action('UPDATE session_history SET parent_rating_key = ? WHERE parent_rating_key = ?',
[new_key, old_key]) [new_key, old_key])
monitor_db.action('UPDATE session_history_metadata SET parent_rating_key = ? WHERE parent_rating_key = ?', monitor_db.action('UPDATE session_history_metadata SET parent_rating_key = ? WHERE parent_rating_key = ?',
[new_key, old_key]) [new_key, old_key])
# check grandparent_rating_key (2 tables) # check grandparent_rating_key (2 tables)
monitor_db.action('UPDATE session_history SET grandparent_rating_key = ? WHERE grandparent_rating_key = ?', monitor_db.action('UPDATE session_history SET grandparent_rating_key = ? WHERE grandparent_rating_key = ?',
[new_key, old_key]) [new_key, old_key])
monitor_db.action('UPDATE session_history_metadata SET grandparent_rating_key = ? WHERE grandparent_rating_key = ?', monitor_db.action('UPDATE session_history_metadata SET grandparent_rating_key = ? WHERE grandparent_rating_key = ?',
[new_key, old_key]) [new_key, old_key])
# check thumb (1 table) # check thumb (1 table)
monitor_db.action('UPDATE session_history_metadata SET thumb = replace(thumb, ?, ?) \ monitor_db.action('UPDATE session_history_metadata SET thumb = replace(thumb, ?, ?) \
WHERE thumb LIKE "/library/metadata/%s/thumb/%%"' % old_key, WHERE thumb LIKE "/library/metadata/%s/thumb/%%"' % old_key,
[old_key, new_key]) [old_key, new_key])
# check parent_thumb (1 table) # check parent_thumb (1 table)
monitor_db.action('UPDATE session_history_metadata SET parent_thumb = replace(parent_thumb, ?, ?) \ monitor_db.action('UPDATE session_history_metadata SET parent_thumb = replace(parent_thumb, ?, ?) \
WHERE parent_thumb LIKE "/library/metadata/%s/thumb/%%"' % old_key, WHERE parent_thumb LIKE "/library/metadata/%s/thumb/%%"' % old_key,
[old_key, new_key]) [old_key, new_key])
# check grandparent_thumb (1 table) # check grandparent_thumb (1 table)
monitor_db.action('UPDATE session_history_metadata SET grandparent_thumb = replace(grandparent_thumb, ?, ?) \ monitor_db.action('UPDATE session_history_metadata SET grandparent_thumb = replace(grandparent_thumb, ?, ?) \
WHERE grandparent_thumb LIKE "/library/metadata/%s/thumb/%%"' % old_key, WHERE grandparent_thumb LIKE "/library/metadata/%s/thumb/%%"' % old_key,
[old_key, new_key]) [old_key, new_key])
# check art (1 table) # check art (1 table)
monitor_db.action('UPDATE session_history_metadata SET art = replace(art, ?, ?) \ monitor_db.action('UPDATE session_history_metadata SET art = replace(art, ?, ?) \
WHERE art LIKE "/library/metadata/%s/art/%%"' % old_key, WHERE art LIKE "/library/metadata/%s/art/%%"' % old_key,
[old_key, new_key]) [old_key, new_key])
return 'Updated rating key in database.' return 'Updated rating key in database.'

View File

@@ -178,12 +178,18 @@ class DataTables(object):
filtered = self.ssp_db.select(query, args=args) filtered = self.ssp_db.select(query, args=args)
# Build grand totals # Build grand totals
totalcount = self.ssp_db.select('SELECT COUNT(id) from %s' % table_name)[0][0] totalcount = self.ssp_db.select('SELECT COUNT(id) as total_count from %s' % table_name)[0]['total_count']
# Get draw counter # Get draw counter
draw_counter = int(parameters['draw']) draw_counter = int(parameters['draw'])
# Paginate results
result = filtered[parameters['start']:(parameters['start'] + parameters['length'])] result = filtered[parameters['start']:(parameters['start'] + parameters['length'])]
# Sanitize on the way out
result = [{k: helpers.sanitize(v) if isinstance(v, basestring) else v for k, v in row.iteritems()}
for row in result]
output = {'result': result, output = {'result': result,
'draw': draw_counter, 'draw': draw_counter,
'filteredCount': len(filtered), 'filteredCount': len(filtered),

View File

@@ -44,11 +44,11 @@ class Graphs(object):
else: else:
query = 'SELECT date(started, "unixepoch", "localtime") as date_played, ' \ query = 'SELECT date(started, "unixepoch", "localtime") as date_played, ' \
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_count, ' \
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_count, ' \
'SUM(case when media_type = "track" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "track" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as music_duration ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as music_count ' \
'FROM session_history ' \ 'FROM session_history ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \ 'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
'GROUP BY date_played ' \ 'GROUP BY date_played ' \
@@ -76,10 +76,10 @@ class Graphs(object):
series_2_value = 0 series_2_value = 0
series_3_value = 0 series_3_value = 0
for item in result: for item in result:
if date_string == item[0]: if date_string == item['date_played']:
series_1_value = item[1] series_1_value = item['tv_count']
series_2_value = item[2] series_2_value = item['movie_count']
series_3_value = item[3] series_3_value = item['music_count']
break break
else: else:
series_1_value = 0 series_1_value = 0
@@ -138,11 +138,11 @@ class Graphs(object):
'when 5 then "Friday" ' \ 'when 5 then "Friday" ' \
'else "Saturday" end as dayofweek, ' \ 'else "Saturday" end as dayofweek, ' \
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_count, ' \
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_count, ' \
'SUM(case when media_type = "track" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "track" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as music_duration ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as music_count ' \
'FROM session_history ' \ 'FROM session_history ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \ 'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \
'datetime("now", "-' + time_range + ' days", "localtime") ' \ 'datetime("now", "-' + time_range + ' days", "localtime") ' \
@@ -165,10 +165,10 @@ class Graphs(object):
series_2_value = 0 series_2_value = 0
series_3_value = 0 series_3_value = 0
for item in result: for item in result:
if day_item == item[1]: if day_item == item['dayofweek']:
series_1_value = item[2] series_1_value = item['tv_count']
series_2_value = item[3] series_2_value = item['movie_count']
series_3_value = item[4] series_3_value = item['music_count']
break break
else: else:
series_1_value = 0 series_1_value = 0
@@ -211,11 +211,11 @@ class Graphs(object):
else: else:
query = 'select strftime("%H", datetime(started, "unixepoch", "localtime")) as hourofday, ' \ query = 'select strftime("%H", datetime(started, "unixepoch", "localtime")) as hourofday, ' \
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_count, ' \
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_count, ' \
'SUM(case when media_type = "track" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "track" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as music_duration ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as music_count ' \
'FROM session_history ' \ 'FROM session_history ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \ 'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \
'datetime("now", "-' + time_range + ' days", "localtime") ' \ 'datetime("now", "-' + time_range + ' days", "localtime") ' \
@@ -240,10 +240,10 @@ class Graphs(object):
series_2_value = 0 series_2_value = 0
series_3_value = 0 series_3_value = 0
for item in result: for item in result:
if hour_item == item[0]: if hour_item == item['hourofday']:
series_1_value = item[1] series_1_value = item['tv_count']
series_2_value = item[2] series_2_value = item['movie_count']
series_3_value = item[3] series_3_value = item['music_count']
break break
else: else:
series_1_value = 0 series_1_value = 0
@@ -283,11 +283,11 @@ class Graphs(object):
else: else:
query = 'SELECT strftime("%Y-%m", datetime(started, "unixepoch", "localtime")) as datestring, ' \ query = 'SELECT strftime("%Y-%m", datetime(started, "unixepoch", "localtime")) as datestring, ' \
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_count, ' \
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_count, ' \
'SUM(case when media_type = "track" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "track" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as music_duration ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as music_count ' \
'FROM session_history ' \ 'FROM session_history ' \
'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-12 months", "localtime") ' \ 'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-12 months", "localtime") ' \
'GROUP BY strftime("%Y-%m", datetime(started, "unixepoch", "localtime")) ' \ 'GROUP BY strftime("%Y-%m", datetime(started, "unixepoch", "localtime")) ' \
@@ -316,10 +316,10 @@ class Graphs(object):
series_2_value = 0 series_2_value = 0
series_3_value = 0 series_3_value = 0
for item in result: for item in result:
if date_string == item[0]: if date_string == item['datestring']:
series_1_value = item[1] series_1_value = item['tv_count']
series_2_value = item[2] series_2_value = item['movie_count']
series_3_value = item[3] series_3_value = item['music_count']
break break
else: else:
series_1_value = 0 series_1_value = 0
@@ -364,11 +364,11 @@ class Graphs(object):
else: else:
query = 'SELECT platform, ' \ query = 'SELECT platform, ' \
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_count, ' \
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_count, ' \
'SUM(case when media_type = "track" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "track" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as music_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as music_count, ' \
'SUM(case when stopped > 0 then (stopped - started) ' \ 'SUM(case when stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \
'FROM session_history ' \ 'FROM session_history ' \
@@ -386,10 +386,10 @@ class Graphs(object):
series_3 = [] series_3 = []
for item in result: for item in result:
categories.append(common.PLATFORM_NAME_OVERRIDES.get(item[0], item[0])) categories.append(common.PLATFORM_NAME_OVERRIDES.get(item['platform'], item['platform']))
series_1.append(item[1]) series_1.append(item['tv_count'])
series_2.append(item[2]) series_2.append(item['movie_count'])
series_3.append(item[3]) series_3.append(item['music_count'])
series_1_output = {'name': 'TV', series_1_output = {'name': 'TV',
'data': series_1} 'data': series_1}
@@ -430,11 +430,11 @@ class Graphs(object):
'(case when users.friendly_name is null then users.username else ' \ '(case when users.friendly_name is null then users.username else ' \
'users.friendly_name end) as friendly_name,' \ 'users.friendly_name end) as friendly_name,' \
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_count, ' \
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_count, ' \
'SUM(case when media_type = "track" and stopped > 0 then (stopped - started) ' \ 'SUM(case when media_type = "track" and stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as music_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as music_count, ' \
'SUM(case when stopped > 0 then (stopped - started) ' \ 'SUM(case when stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \
'FROM session_history ' \ 'FROM session_history ' \
@@ -453,10 +453,10 @@ class Graphs(object):
series_3 = [] series_3 = []
for item in result: for item in result:
categories.append(item[0]) categories.append(item['friendly_name'])
series_1.append(item[1]) series_1.append(item['tv_count'])
series_2.append(item[2]) series_2.append(item['movie_count'])
series_3.append(item[3]) series_3.append(item['music_count'])
series_1_output = {'name': 'TV', series_1_output = {'name': 'TV',
'data': series_1} 'data': series_1}
@@ -501,15 +501,15 @@ class Graphs(object):
'SUM(case when (session_history_media_info.video_decision = "direct play" ' \ 'SUM(case when (session_history_media_info.video_decision = "direct play" ' \
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play")) ' \ 'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play")) ' \
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \ 'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_count, ' \
'SUM(case when (session_history_media_info.video_decision = "copy" ' \ 'SUM(case when (session_history_media_info.video_decision = "copy" ' \
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy")) ' \ 'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy")) ' \
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \ 'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_count, ' \
'SUM(case when (session_history_media_info.video_decision = "transcode" ' \ 'SUM(case when (session_history_media_info.video_decision = "transcode" ' \
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode")) ' \ 'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode")) ' \
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \ 'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_duration ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_count ' \
'FROM session_history ' \ 'FROM session_history ' \
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \ 'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") >= ' \ 'WHERE datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
@@ -540,10 +540,10 @@ class Graphs(object):
series_2_value = 0 series_2_value = 0
series_3_value = 0 series_3_value = 0
for item in result: for item in result:
if date_string == item[0]: if date_string == item['date_played']:
series_1_value = item[1] series_1_value = item['dp_count']
series_2_value = item[2] series_2_value = item['ds_count']
series_3_value = item[3] series_3_value = item['tc_count']
break break
else: else:
series_1_value = 0 series_1_value = 0
@@ -598,15 +598,15 @@ class Graphs(object):
'SUM(case when (session_history_media_info.video_decision = "direct play" ' \ 'SUM(case when (session_history_media_info.video_decision = "direct play" ' \
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play")) ' \ 'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play")) ' \
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \ 'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_count, ' \
'SUM(case when (session_history_media_info.video_decision = "copy" ' \ 'SUM(case when (session_history_media_info.video_decision = "copy" ' \
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy")) ' \ 'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy")) ' \
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \ 'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_count, ' \
'SUM(case when (session_history_media_info.video_decision = "transcode" ' \ 'SUM(case when (session_history_media_info.video_decision = "transcode" ' \
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode")) ' \ 'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode")) ' \
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \ 'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_count, ' \
'SUM(case when stopped > 0 then (stopped - started) ' \ 'SUM(case when stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \
'FROM session_history ' \ 'FROM session_history ' \
@@ -626,10 +626,10 @@ class Graphs(object):
series_3 = [] series_3 = []
for item in result: for item in result:
categories.append(item[0]) categories.append(item['resolution'])
series_1.append(item[1]) series_1.append(item['dp_count'])
series_2.append(item[2]) series_2.append(item['ds_count'])
series_3.append(item[3]) series_3.append(item['tc_count'])
series_1_output = {'name': 'Direct Play', series_1_output = {'name': 'Direct Play',
'data': series_1} 'data': series_1}
@@ -695,15 +695,15 @@ class Graphs(object):
'SUM(case when (session_history_media_info.video_decision = "direct play" ' \ 'SUM(case when (session_history_media_info.video_decision = "direct play" ' \
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play")) ' \ 'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play")) ' \
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \ 'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_count, ' \
'SUM(case when (session_history_media_info.video_decision = "copy" ' \ 'SUM(case when (session_history_media_info.video_decision = "copy" ' \
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy")) ' \ 'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy")) ' \
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \ 'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_count, ' \
'SUM(case when (session_history_media_info.video_decision = "transcode" ' \ 'SUM(case when (session_history_media_info.video_decision = "transcode" ' \
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode")) ' \ 'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode")) ' \
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \ 'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_count, ' \
'SUM(case when stopped > 0 then (stopped - started) ' \ 'SUM(case when stopped > 0 then (stopped - started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \
'FROM session_history ' \ 'FROM session_history ' \
@@ -723,10 +723,10 @@ class Graphs(object):
series_3 = [] series_3 = []
for item in result: for item in result:
categories.append(item[0]) categories.append(item['resolution'])
series_1.append(item[1]) series_1.append(item['dp_count'])
series_2.append(item[2]) series_2.append(item['ds_count'])
series_3.append(item[3]) series_3.append(item['tc_count'])
series_1_output = {'name': 'Direct Play', series_1_output = {'name': 'Direct Play',
'data': series_1} 'data': series_1}
@@ -773,15 +773,15 @@ class Graphs(object):
'SUM(case when (session_history_media_info.video_decision = "direct play" ' \ 'SUM(case when (session_history_media_info.video_decision = "direct play" ' \
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play")) ' \ 'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play")) ' \
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \ 'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_count, ' \
'SUM(case when (session_history_media_info.video_decision = "copy" ' \ 'SUM(case when (session_history_media_info.video_decision = "copy" ' \
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy")) ' \ 'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy")) ' \
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \ 'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_count, ' \
'SUM(case when (session_history_media_info.video_decision = "transcode" ' \ 'SUM(case when (session_history_media_info.video_decision = "transcode" ' \
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode")) ' \ 'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode")) ' \
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \ 'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_count, ' \
'SUM(case when session_history.stopped > 0 ' \ 'SUM(case when session_history.stopped > 0 ' \
'then (session_history.stopped - session_history.started) ' \ 'then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \
@@ -801,10 +801,10 @@ class Graphs(object):
series_3 = [] series_3 = []
for item in result: for item in result:
categories.append(common.PLATFORM_NAME_OVERRIDES.get(item[0], item[0])) categories.append(common.PLATFORM_NAME_OVERRIDES.get(item['platform'], item['platform']))
series_1.append(item[1]) series_1.append(item['dp_count'])
series_2.append(item[2]) series_2.append(item['ds_count'])
series_3.append(item[3]) series_3.append(item['tc_count'])
series_1_output = {'name': 'Direct Play', series_1_output = {'name': 'Direct Play',
'data': series_1} 'data': series_1}
@@ -853,15 +853,15 @@ class Graphs(object):
'SUM(case when (session_history_media_info.video_decision = "direct play" ' \ 'SUM(case when (session_history_media_info.video_decision = "direct play" ' \
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play")) ' \ 'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play")) ' \
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \ 'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_count, ' \
'SUM(case when (session_history_media_info.video_decision = "copy" ' \ 'SUM(case when (session_history_media_info.video_decision = "copy" ' \
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy")) ' \ 'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy")) ' \
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \ 'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_count, ' \
'SUM(case when (session_history_media_info.video_decision = "transcode" ' \ 'SUM(case when (session_history_media_info.video_decision = "transcode" ' \
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode")) ' \ 'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode")) ' \
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \ 'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_duration, ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_count, ' \
'SUM(case when session_history.stopped > 0 ' \ 'SUM(case when session_history.stopped > 0 ' \
'then (session_history.stopped - session_history.started) ' \ 'then (session_history.stopped - session_history.started) ' \
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \ ' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \
@@ -882,10 +882,10 @@ class Graphs(object):
series_3 = [] series_3 = []
for item in result: for item in result:
categories.append(item[0]) categories.append(item['username'])
series_1.append(item[1]) series_1.append(item['dp_count'])
series_2.append(item[2]) series_2.append(item['ds_count'])
series_3.append(item[3]) series_3.append(item['tc_count'])
series_1_output = {'name': 'Direct Play', series_1_output = {'name': 'Direct Play',
'data': series_1} 'data': series_1}

View File

@@ -92,13 +92,15 @@ def latinToAscii(unicrap):
} }
r = '' r = ''
for i in unicrap: if unicrap:
if ord(i) in xlate: for i in unicrap:
r += xlate[ord(i)] if ord(i) in xlate:
elif ord(i) >= 0x80: r += xlate[ord(i)]
pass elif ord(i) >= 0x80:
else: pass
r += str(i) else:
r += str(i)
return r return r
@@ -153,7 +155,7 @@ def human_duration(s):
h = int((s % 84600) / 3600) h = int((s % 84600) / 3600)
m = int(((s % 84600) % 3600) / 60) m = int(((s % 84600) % 3600) / 60)
s = int(((s % 84600) % 3600) % 60) s = int(((s % 84600) % 3600) % 60)
hd_list = [] hd_list = []
if d > 0: if d > 0:
hd_list.append(str(d) + ' days') hd_list.append(str(d) + ' days')
@@ -163,7 +165,7 @@ def human_duration(s):
hd_list.append(str(m) + ' mins') hd_list.append(str(m) + ' mins')
if s > 0: if s > 0:
hd_list.append(str(s) + ' secs') hd_list.append(str(s) + ' secs')
hd = ' '.join(hd_list) hd = ' '.join(hd_list)
return hd return hd
@@ -202,7 +204,7 @@ def piratesize(size):
split = size.split(" ") split = size.split(" ")
factor = float(split[0]) factor = float(split[0])
unit = split[1].upper() unit = split[1].upper()
if unit == 'MiB': if unit == 'MiB':
size = factor * 1048576 size = factor * 1048576
elif unit == 'MB': elif unit == 'MB':
@@ -428,3 +430,9 @@ def process_json_kwargs(json_kwargs):
params = json.loads(json_kwargs) params = json.loads(json_kwargs)
return params return params
def sanitize(string):
if string:
return unicode(string).replace('<','&lt;').replace('>','&gt;')
else:
return ''

View File

@@ -161,7 +161,7 @@ def notify(stream_data=None, notify_action=None):
elif stream_data['media_type'] == 'clip': elif stream_data['media_type'] == 'clip':
pass pass
else: else:
logger.debug(u"PlexPy Notifier :: Notify called with unsupported media type.") #logger.debug(u"PlexPy Notifier :: Notify called with unsupported media type.")
pass pass
else: else:
logger.debug(u"PlexPy Notifier :: Notify called but incomplete data received.") logger.debug(u"PlexPy Notifier :: Notify called but incomplete data received.")
@@ -315,13 +315,13 @@ def build_notify_text(session=None, timeline=None, state=None):
# Check for exclusion tags # Check for exclusion tags
if metadata['media_type'] == 'movie': if metadata['media_type'] == 'movie':
# Regex pattern to remove the text in the tags we don't want # Regex pattern to remove the text in the tags we don't want
pattern = re.compile('<tv>[^>]+.</tv>|<music>[^>]+.</music>', re.IGNORECASE) pattern = re.compile('<tv>[^>]+.</tv>|<music>[^>]+.</music>', re.IGNORECASE|re.DOTALL)
elif metadata['media_type'] == 'show' or metadata['media_type'] == 'episode': elif metadata['media_type'] == 'show' or metadata['media_type'] == 'episode':
# Regex pattern to remove the text in the tags we don't want # Regex pattern to remove the text in the tags we don't want
pattern = re.compile('<movie>[^>]+.</movie>|<music>[^>]+.</music>', re.IGNORECASE) pattern = re.compile('<movie>[^>]+.</movie>|<music>[^>]+.</music>', re.IGNORECASE|re.DOTALL)
elif metadata['media_type'] == 'artist' or metadata['media_type'] == 'track': elif metadata['media_type'] == 'artist' or metadata['media_type'] == 'track':
# Regex pattern to remove the text in the tags we don't want # Regex pattern to remove the text in the tags we don't want
pattern = re.compile('<tv>[^>]+.</tv>|<movie>[^>]+.</movie>', re.IGNORECASE) pattern = re.compile('<tv>[^>]+.</tv>|<movie>[^>]+.</movie>', re.IGNORECASE|re.DOTALL)
else: else:
pattern = None pattern = None
@@ -370,6 +370,8 @@ def build_notify_text(session=None, timeline=None, state=None):
duration = helpers.convert_milliseconds_to_minutes(metadata['duration']) duration = helpers.convert_milliseconds_to_minutes(metadata['duration'])
# Default values # Default values
video_decision = ''
audio_decision = ''
transcode_decision = '' transcode_decision = ''
stream_duration = 0 stream_duration = 0
view_offset = 0 view_offset = 0
@@ -381,18 +383,15 @@ def build_notify_text(session=None, timeline=None, state=None):
# Session values # Session values
if session: if session:
# Generate a combined transcode decision value # Generate a combined transcode decision value
if session['video_decision']: video_decision = session['video_decision'].title()
if session['video_decision'] == 'transcode': audio_decision = session['audio_decision'].title()
transcode_decision = 'Transcode'
elif session['video_decision'] == 'copy' or session['audio_decision'] == 'copy': if session['video_decision'] == 'transcode' or session['audio_decision'] == 'transcode':
transcode_decision = 'Direct Stream' transcode_decision = 'Transcode'
else: elif session['video_decision'] == 'copy' or session['audio_decision'] == 'copy':
transcode_decision = 'Direct Play' transcode_decision = 'Direct Stream'
elif session['audio_decision']: else:
if session['audio_decision'] == 'transcode': transcode_decision = 'Direct Play'
transcode_decision = 'Transcode'
else:
transcode_decision = 'Direct Play'
if state != 'play': if state != 'play':
if session['paused_counter']: if session['paused_counter']:
@@ -405,7 +404,7 @@ def build_notify_text(session=None, timeline=None, state=None):
user = session['friendly_name'] user = session['friendly_name']
platform = session['platform'] platform = session['platform']
player = session['player'] player = session['player']
ip_address = session['ip_address'] if session['ip_address'] != '' else 'N/A' ip_address = session['ip_address'] if session['ip_address'] else 'N/A'
progress_percent = helpers.get_percent(view_offset, duration) progress_percent = helpers.get_percent(view_offset, duration)
@@ -422,10 +421,12 @@ def build_notify_text(session=None, timeline=None, state=None):
'artist_name': metadata['grandparent_title'], 'artist_name': metadata['grandparent_title'],
'album_name': metadata['parent_title'], 'album_name': metadata['parent_title'],
'track_name': metadata['title'], 'track_name': metadata['title'],
'season_num': metadata['parent_index'], 'season_num': metadata['parent_index'].zfill(1),
'season_num00': metadata['parent_index'].zfill(2), 'season_num00': metadata['parent_index'].zfill(2),
'episode_num': metadata['index'], 'episode_num': metadata['index'].zfill(1),
'episode_num00': metadata['index'].zfill(2), 'episode_num00': metadata['index'].zfill(2),
'video_decision': video_decision,
'audio_decision': audio_decision,
'transcode_decision': transcode_decision, 'transcode_decision': transcode_decision,
'year': metadata['year'], 'year': metadata['year'],
'studio': metadata['studio'], 'studio': metadata['studio'],

View File

@@ -505,7 +505,7 @@ class PROWL(object):
data = {'apikey': plexpy.CONFIG.PROWL_KEYS, data = {'apikey': plexpy.CONFIG.PROWL_KEYS,
'application': 'PlexPy', 'application': 'PlexPy',
'event': event, 'event': event.encode("utf-8"),
'description': message.encode("utf-8"), 'description': message.encode("utf-8"),
'priority': plexpy.CONFIG.PROWL_PRIORITY} 'priority': plexpy.CONFIG.PROWL_PRIORITY}
@@ -879,9 +879,9 @@ class PUSHALOT(object):
pushalot_authorizationtoken = plexpy.CONFIG.PUSHALOT_APIKEY pushalot_authorizationtoken = plexpy.CONFIG.PUSHALOT_APIKEY
logger.debug(u"Pushalot event: " + event) #logger.debug(u"Pushalot event: " + event)
logger.debug(u"Pushalot message: " + message) #logger.debug(u"Pushalot message: " + message)
logger.debug(u"Pushalot api: " + pushalot_authorizationtoken) #logger.debug(u"Pushalot api: " + pushalot_authorizationtoken)
http_handler = HTTPSConnection("pushalot.com") http_handler = HTTPSConnection("pushalot.com")
@@ -896,9 +896,9 @@ class PUSHALOT(object):
response = http_handler.getresponse() response = http_handler.getresponse()
request_status = response.status request_status = response.status
logger.debug(u"Pushalot response status: %r" % request_status) #logger.debug(u"Pushalot response status: %r" % request_status)
logger.debug(u"Pushalot response headers: %r" % response.getheaders()) #logger.debug(u"Pushalot response headers: %r" % response.getheaders())
logger.debug(u"Pushalot response body: %r" % response.read()) #logger.debug(u"Pushalot response body: %r" % response.read())
if request_status == 200: if request_status == 200:
logger.info(u"Pushalot notifications sent.") logger.info(u"Pushalot notifications sent.")
@@ -1526,7 +1526,7 @@ class TELEGRAM(object):
{'label': 'Telegram Chat ID', {'label': 'Telegram Chat ID',
'value': self.chat_id, 'value': self.chat_id,
'name': 'telegram_chat_id', 'name': 'telegram_chat_id',
'description': 'Your Telegram Chat ID or Group ID. Contact <a href="http://telegram.me/myidbot" target="_blank">@myidbot</a> on Telegram to get an ID.', 'description': 'Your Telegram Chat ID, Group ID, or channel username. Contact <a href="http://telegram.me/myidbot" target="_blank">@myidbot</a> on Telegram to get an ID.',
'input_type': 'text' 'input_type': 'text'
} }
] ]

View File

@@ -292,10 +292,15 @@ def import_from_plexwatch(database=None, table_name=None, import_ignore_interval
# If we get back None from our xml extractor skip over the record and log error. # If we get back None from our xml extractor skip over the record and log error.
if not extracted_xml: if not extracted_xml:
logger.error(u"PlexPy Importer :: Skipping line with ratingKey %s due to malformed xml." logger.error(u"PlexPy Importer :: Skipping record with ratingKey %s due to malformed xml."
% str(row['rating_key'])) % str(row['rating_key']))
continue continue
# Skip line if we don't have a ratingKey to work with
if not row['rating_key']:
logger.error(u"PlexPy Importer :: Skipping record due to null ratingRey.")
continue
# If the user_id no longer exists in the friends list, pull it from the xml. # If the user_id no longer exists in the friends list, pull it from the xml.
if user_data.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']) user_id = user_data.get_user_id(user=row['user'])

View File

@@ -803,7 +803,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'], 'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'], 'friendly_name': user_details['friendly_name'],
'user_thumb': user_details['thumb'], 'user_thumb': user_details['thumb'],
'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address'), 'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address').split(':')[-1],
'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'), 'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'), 'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id, 'machine_id': machine_id,
@@ -924,7 +924,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'], 'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'], 'friendly_name': user_details['friendly_name'],
'user_thumb': user_details['thumb'], 'user_thumb': user_details['thumb'],
'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address'), 'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address').split(':')[-1],
'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'), 'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'), 'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id, 'machine_id': machine_id,
@@ -981,7 +981,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'], 'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'], 'friendly_name': user_details['friendly_name'],
'user_thumb': user_details['thumb'], 'user_thumb': user_details['thumb'],
'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address'), 'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address').split(':')[-1],
'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'), 'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'), 'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id, 'machine_id': machine_id,
@@ -1038,7 +1038,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'], 'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'], 'friendly_name': user_details['friendly_name'],
'user_thumb': user_details['thumb'], 'user_thumb': user_details['thumb'],
'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address'), 'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address').split(':')[-1],
'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'), 'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'), 'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id, 'machine_id': machine_id,
@@ -1128,7 +1128,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'], 'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'], 'friendly_name': user_details['friendly_name'],
'user_thumb': user_details['thumb'], 'user_thumb': user_details['thumb'],
'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address'), 'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address').split(':')[-1],
'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'), 'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'), 'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id, 'machine_id': machine_id,

View File

@@ -24,6 +24,8 @@ class Users(object):
def get_user_list(self, kwargs=None): def get_user_list(self, kwargs=None):
data_tables = datatables.DataTables() data_tables = datatables.DataTables()
custom_where = ['users.deleted_user', 0]
columns = ['session_history.id', columns = ['session_history.id',
'users.user_id as user_id', 'users.user_id as user_id',
'users.custom_avatar_url as user_thumb', 'users.custom_avatar_url as user_thumb',
@@ -48,7 +50,7 @@ class Users(object):
try: try:
query = data_tables.ssp_query(table_name='users', query = data_tables.ssp_query(table_name='users',
columns=columns, columns=columns,
custom_where=[], custom_where=[custom_where],
group_by=['users.user_id'], group_by=['users.user_id'],
join_types=['LEFT OUTER JOIN', join_types=['LEFT OUTER JOIN',
'LEFT OUTER JOIN', 'LEFT OUTER JOIN',
@@ -87,13 +89,16 @@ class Users(object):
# Rename Mystery platform names # Rename Mystery platform names
platform = common.PLATFORM_NAME_OVERRIDES.get(item["platform"], item["platform"]) platform = common.PLATFORM_NAME_OVERRIDES.get(item["platform"], item["platform"])
# Sanitize player name
player = helpers.sanitize(item["player"])
row = {"id": item['id'], row = {"id": item['id'],
"plays": item['plays'], "plays": item['plays'],
"last_seen": item['last_seen'], "last_seen": item['last_seen'],
"friendly_name": item['friendly_name'], "friendly_name": item['friendly_name'],
"ip_address": item['ip_address'], "ip_address": item['ip_address'],
"platform": platform, "platform": platform,
"player": item['player'], "player": player,
"last_watched": item['last_watched'], "last_watched": item['last_watched'],
"thumb": thumb, "thumb": thumb,
"media_type": item['media_type'], "media_type": item['media_type'],
@@ -178,12 +183,15 @@ class Users(object):
# Rename Mystery platform names # Rename Mystery platform names
platform = common.PLATFORM_NAME_OVERRIDES.get(item["platform"], item["platform"]) platform = common.PLATFORM_NAME_OVERRIDES.get(item["platform"], item["platform"])
# Sanitize player name
player = helpers.sanitize(item["player"])
row = {"id": item['id'], row = {"id": item['id'],
"last_seen": item['last_seen'], "last_seen": item['last_seen'],
"ip_address": item['ip_address'], "ip_address": item['ip_address'],
"play_count": item['play_count'], "play_count": item['play_count'],
"platform": platform, "platform": platform,
"player": item['player'], "player": player,
"last_watched": item['last_watched'], "last_watched": item['last_watched'],
"thumb": thumb, "thumb": thumb,
"media_type": item['media_type'], "media_type": item['media_type'],
@@ -263,17 +271,17 @@ class Users(object):
if user_id: if user_id:
monitor_db = database.MonitorDatabase() monitor_db = database.MonitorDatabase()
query = 'select username, ' \ query = 'select username, ' \
'(CASE WHEN friendly_name IS NULL THEN username ELSE friendly_name END),' \ '(CASE WHEN friendly_name IS NULL THEN username ELSE friendly_name END) as friendly_name,' \
'do_notify, keep_history, custom_avatar_url as thumb ' \ 'do_notify, keep_history, custom_avatar_url as thumb ' \
'FROM users WHERE user_id = ?' 'FROM users WHERE user_id = ?'
result = monitor_db.select(query, args=[user_id]) result = monitor_db.select(query, args=[user_id])
if result: if result:
user_detail = {'user_id': user_id, user_detail = {'user_id': user_id,
'user': result[0][0], 'user': result[0]['username'],
'friendly_name': result[0][1], 'friendly_name': result[0]['friendly_name'],
'thumb': result[0][4], 'thumb': result[0]['thumb'],
'do_notify': helpers.checked(result[0][2]), 'do_notify': helpers.checked(result[0]['do_notify']),
'keep_history': helpers.checked(result[0][3]) 'keep_history': helpers.checked(result[0]['keep_history'])
} }
return user_detail return user_detail
else: else:
@@ -287,17 +295,17 @@ class Users(object):
elif user: elif user:
monitor_db = database.MonitorDatabase() monitor_db = database.MonitorDatabase()
query = 'select user_id, ' \ query = 'select user_id, ' \
'(CASE WHEN friendly_name IS NULL THEN username ELSE friendly_name END),' \ '(CASE WHEN friendly_name IS NULL THEN username ELSE friendly_name END) as friendly_name,' \
'do_notify, keep_history, custom_avatar_url as thumb ' \ 'do_notify, keep_history, custom_avatar_url as thumb ' \
'FROM users WHERE username = ?' 'FROM users WHERE username = ?'
result = monitor_db.select(query, args=[user]) result = monitor_db.select(query, args=[user])
if result: if result:
user_detail = {'user_id': result[0][0], user_detail = {'user_id': result[0]['user_id'],
'user': user, 'user': user,
'friendly_name': result[0][1], 'friendly_name': result[0]['friendly_name'],
'thumb': result[0][4], 'thumb': result[0]['thumb'],
'do_notify': helpers.checked(result[0][2]), 'do_notify': helpers.checked(result[0]['do_notify']),
'keep_history': helpers.checked(result[0][3])} 'keep_history': helpers.checked(result[0]['keep_history'])}
return user_detail return user_detail
else: else:
user_detail = {'user_id': None, user_detail = {'user_id': None,
@@ -484,9 +492,9 @@ class Users(object):
result = monitor_db.select(query, args=[user]) result = monitor_db.select(query, args=[user])
for item in result: for item in result:
if item[0]: if item['total_time']:
total_time = item[0] total_time = item['total_time']
total_plays = item[1] total_plays = item['total_plays']
else: else:
total_time = 0 total_time = 0
total_plays = 0 total_plays = 0
@@ -527,14 +535,14 @@ class Users(object):
for item in result: for item in result:
# Rename Mystery platform names # Rename Mystery platform names
platform_type = common.PLATFORM_NAME_OVERRIDES.get(item[2], item[2]) platform_type = common.PLATFORM_NAME_OVERRIDES.get(item['platform'], item['platform'])
row = {'player_name': item[0], row = {'player_name': item['player'],
'platform_type': platform_type, 'platform_type': platform_type,
'total_plays': item[1], 'total_plays': item['player_count'],
'result_id': result_id 'result_id': result_id
} }
player_stats.append(row) player_stats.append(row)
result_id += 1 result_id += 1
return player_stats return player_stats

View File

@@ -1,2 +1,2 @@
PLEXPY_VERSION = "master" PLEXPY_VERSION = "master"
PLEXPY_RELEASE_VERSION = "1.2.4" PLEXPY_RELEASE_VERSION = "1.2.10"

View File

@@ -1,7 +1,4 @@
#!/usr/bin/env python # This file is part of PlexPy.
# -*- coding: utf-8 -*-
# This file is part of PlexPy.
# #
# PlexPy is free software: you can redistribute it and/or modify # PlexPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -16,7 +13,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>. # along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
from plexpy import logger, notifiers, plextv, pmsconnect, common, log_reader, datafactory, graphs, users from plexpy import logger, notifiers, plextv, pmsconnect, common, log_reader, datafactory, graphs, users, helpers
from plexpy.helpers import checked, radio from plexpy.helpers import checked, radio
from mako.lookup import TemplateLookup from mako.lookup import TemplateLookup
@@ -44,7 +41,7 @@ def serve_template(templatename, **kwargs):
interface_dir = os.path.join(str(plexpy.PROG_DIR), 'data/interfaces/') interface_dir = os.path.join(str(plexpy.PROG_DIR), 'data/interfaces/')
template_dir = os.path.join(str(interface_dir), plexpy.CONFIG.INTERFACE) template_dir = os.path.join(str(interface_dir), plexpy.CONFIG.INTERFACE)
_hplookup = TemplateLookup(directories=[template_dir]) _hplookup = TemplateLookup(directories=[template_dir], default_filters=['unicode', 'h'])
server_name = plexpy.CONFIG.PMS_NAME server_name = plexpy.CONFIG.PMS_NAME
@@ -448,6 +445,7 @@ class WebInterface(object):
"logging_ignore_interval": plexpy.CONFIG.LOGGING_IGNORE_INTERVAL, "logging_ignore_interval": plexpy.CONFIG.LOGGING_IGNORE_INTERVAL,
"pms_is_remote": checked(plexpy.CONFIG.PMS_IS_REMOTE), "pms_is_remote": checked(plexpy.CONFIG.PMS_IS_REMOTE),
"notify_consecutive": checked(plexpy.CONFIG.NOTIFY_CONSECUTIVE), "notify_consecutive": checked(plexpy.CONFIG.NOTIFY_CONSECUTIVE),
"notify_recently_added": checked(plexpy.CONFIG.NOTIFY_RECENTLY_ADDED),
"notify_recently_added_grandparent": checked(plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT), "notify_recently_added_grandparent": checked(plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT),
"notify_recently_added_delay": plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_DELAY, "notify_recently_added_delay": plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_DELAY,
"notify_watched_percent": plexpy.CONFIG.NOTIFY_WATCHED_PERCENT, "notify_watched_percent": plexpy.CONFIG.NOTIFY_WATCHED_PERCENT,
@@ -494,7 +492,7 @@ class WebInterface(object):
"tv_notify_on_pause", "movie_notify_on_pause", "music_notify_on_pause", "refresh_users_on_startup", "tv_notify_on_pause", "movie_notify_on_pause", "music_notify_on_pause", "refresh_users_on_startup",
"ip_logging_enable", "movie_logging_enable", "tv_logging_enable", "music_logging_enable", "ip_logging_enable", "movie_logging_enable", "tv_logging_enable", "music_logging_enable",
"pms_is_remote", "home_stats_type", "group_history_tables", "notify_consecutive", "pms_is_remote", "home_stats_type", "group_history_tables", "notify_consecutive",
"notify_recently_added_grandparent", "monitor_remote_access" "notify_recently_added", "notify_recently_added_grandparent", "monitor_remote_access"
] ]
for checked_config in checked_configs: for checked_config in checked_configs:
if checked_config not in kwargs: if checked_config not in kwargs:
@@ -519,6 +517,14 @@ class WebInterface(object):
if (kwargs['monitoring_interval'] != str(plexpy.CONFIG.MONITORING_INTERVAL)) or \ if (kwargs['monitoring_interval'] != str(plexpy.CONFIG.MONITORING_INTERVAL)) or \
(kwargs['refresh_users_interval'] != str(plexpy.CONFIG.REFRESH_USERS_INTERVAL)): (kwargs['refresh_users_interval'] != str(plexpy.CONFIG.REFRESH_USERS_INTERVAL)):
reschedule = True reschedule = True
if 'notify_recently_added' in kwargs and \
(kwargs['notify_recently_added'] != plexpy.CONFIG.NOTIFY_RECENTLY_ADDED):
reschedule = True
if 'monitor_remote_access' in kwargs and \
(kwargs['monitor_remote_access'] != plexpy.CONFIG.MONITOR_REMOTE_ACCESS):
reschedule = True
if 'pms_ip' in kwargs: if 'pms_ip' in kwargs:
if kwargs['pms_ip'] != plexpy.CONFIG.PMS_IP: if kwargs['pms_ip'] != plexpy.CONFIG.PMS_IP:
@@ -729,6 +735,9 @@ class WebInterface(object):
if not session['ip_address']: if not session['ip_address']:
ip_address = data_factory.get_session_ip(session['session_key']) ip_address = data_factory.get_session_ip(session['session_key'])
session['ip_address'] = ip_address session['ip_address'] = ip_address
# Sanitize player name
session['player'] = helpers.sanitize(session['player'])
except: except:
return serve_template(templatename="current_activity.html", data=None) return serve_template(templatename="current_activity.html", data=None)
@@ -1397,6 +1406,40 @@ class WebInterface(object):
cherrypy.response.headers['Content-type'] = 'application/json' cherrypy.response.headers['Content-type'] = 'application/json'
return json.dumps({'message': 'no data received'}) return json.dumps({'message': 'no data received'})
@cherrypy.expose
def delete_user(self, user_id, **kwargs):
data_factory = datafactory.DataFactory()
if user_id:
delete_row = data_factory.delete_user(user_id=user_id)
if delete_row:
cherrypy.response.headers['Content-type'] = 'application/json'
return json.dumps({'message': delete_row})
else:
cherrypy.response.headers['Content-type'] = 'application/json'
return json.dumps({'message': 'no data received'})
@cherrypy.expose
def undelete_user(self, user_id=None, username=None, **kwargs):
data_factory = datafactory.DataFactory()
if user_id:
delete_row = data_factory.undelete_user(user_id=user_id)
if delete_row:
cherrypy.response.headers['Content-type'] = 'application/json'
return json.dumps({'message': delete_row})
elif username:
delete_row = data_factory.undelete_user(username=username)
if delete_row:
cherrypy.response.headers['Content-type'] = 'application/json'
return json.dumps({'message': delete_row})
else:
cherrypy.response.headers['Content-type'] = 'application/json'
return json.dumps({'message': 'no data received'})
@cherrypy.expose @cherrypy.expose
def search(self, query=''): def search(self, query=''):