' +
+ '   ' +
' ' +
' ');
// 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 row = users_list_table.row(tr);
var rowData = row.data();
- var index = $.inArray(rowData['user_id'], users_to_purge);
- if (index === -1) {
+ var index_delete = $.inArray(rowData['user_id'], users_to_delete);
+ 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']);
} 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');
});
\ No newline at end of file
diff --git a/data/interfaces/default/users.html b/data/interfaces/default/users.html
index f4bc65c2..c97c46e8 100644
--- a/data/interfaces/default/users.html
+++ b/data/interfaces/default/users.html
@@ -16,7 +16,7 @@
 
-
 Select users to purge. Data is purged upon exiting edit mode.
+
 Select users to delete/purge. Data is deleted/purged upon exiting edit mode.
@@ -46,16 +46,16 @@
-
Confirm Purge
+
Confirm Delete/Purge
-
Are you REALLY sure you want to purge all history for the following users:
+
This is permanent and cannot be undone!
@@ -74,8 +74,8 @@
diff --git a/plexpy/__init__.py b/plexpy/__init__.py
index 9e3e25c6..88fb73f7 100644
--- a/plexpy/__init__.py
+++ b/plexpy/__init__.py
@@ -406,9 +406,9 @@ def dbcheck():
c_db.execute(
'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, '
'user_id INTEGER DEFAULT NULL UNIQUE, username TEXT NOT NULL UNIQUE, '
- 'friendly_name TEXT, thumb TEXT, email TEXT, is_home_user INTEGER DEFAULT NULL, '
+ '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, '
- '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
@@ -664,6 +664,15 @@ def dbcheck():
'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()
c_db.close()
diff --git a/plexpy/datafactory.py b/plexpy/datafactory.py
index 948b8fa4..544df9f7 100644
--- a/plexpy/datafactory.py
+++ b/plexpy/datafactory.py
@@ -800,6 +800,40 @@ class DataFactory(object):
else:
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=''):
monitor_db = database.MonitorDatabase()
diff --git a/plexpy/users.py b/plexpy/users.py
index 1c0c23a7..bccda2f7 100644
--- a/plexpy/users.py
+++ b/plexpy/users.py
@@ -24,6 +24,8 @@ class Users(object):
def get_user_list(self, kwargs=None):
data_tables = datatables.DataTables()
+ custom_where = ['users.deleted_user', 0]
+
columns = ['session_history.id',
'users.user_id as user_id',
'users.custom_avatar_url as user_thumb',
@@ -48,7 +50,7 @@ class Users(object):
try:
query = data_tables.ssp_query(table_name='users',
columns=columns,
- custom_where=[],
+ custom_where=[custom_where],
group_by=['users.user_id'],
join_types=['LEFT OUTER JOIN',
'LEFT OUTER JOIN',
diff --git a/plexpy/webserve.py b/plexpy/webserve.py
index 62b16cc5..85be241f 100644
--- a/plexpy/webserve.py
+++ b/plexpy/webserve.py
@@ -1397,6 +1397,40 @@ class WebInterface(object):
cherrypy.response.headers['Content-type'] = 'application/json'
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
def search(self, query=''):
From d7284c40bd4cd0b9e63f75242ac4c8ebd70691b6 Mon Sep 17 00:00:00 2001
From: Jonathan Wong
Date: Tue, 1 Dec 2015 20:03:25 -0800
Subject: [PATCH 03/22] Allow unicode in notification subject and body
---
plexpy/config.py | 36 ++++++++++++++++++------------------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/plexpy/config.py b/plexpy/config.py
index 08054742..3064af10 100644
--- a/plexpy/config.py
+++ b/plexpy/config.py
@@ -154,24 +154,24 @@ _CONFIG_DEFINITIONS = {
'NOTIFY_RECENTLY_ADDED_GRANDPARENT': (int, 'Monitoring', 0),
'NOTIFY_RECENTLY_ADDED_DELAY': (int, 'Monitoring', 60),
'NOTIFY_WATCHED_PERCENT': (int, 'Monitoring', 85),
- 'NOTIFY_ON_START_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
- 'NOTIFY_ON_START_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) started playing {title}.'),
- 'NOTIFY_ON_STOP_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
- 'NOTIFY_ON_STOP_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has stopped {title}.'),
- 'NOTIFY_ON_PAUSE_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
- 'NOTIFY_ON_PAUSE_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has paused {title}.'),
- 'NOTIFY_ON_RESUME_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
- 'NOTIFY_ON_RESUME_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has resumed {title}.'),
- 'NOTIFY_ON_BUFFER_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
- 'NOTIFY_ON_BUFFER_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) is buffering {title}.'),
- 'NOTIFY_ON_WATCHED_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
- 'NOTIFY_ON_WATCHED_BODY_TEXT': (str, 'Monitoring', '{user} ({player}) has watched {title}.'),
- 'NOTIFY_ON_CREATED_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
- 'NOTIFY_ON_CREATED_BODY_TEXT': (str, 'Monitoring', '{title} was recently added to Plex.'),
- 'NOTIFY_ON_EXTDOWN_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
- 'NOTIFY_ON_EXTDOWN_BODY_TEXT': (str, 'Monitoring', 'The Plex Media Server remote access is down.'),
- 'NOTIFY_ON_INTDOWN_SUBJECT_TEXT': (str, 'Monitoring', 'PlexPy ({server_name})'),
- 'NOTIFY_ON_INTDOWN_BODY_TEXT': (str, 'Monitoring', 'The Plex Media Server is down.'),
+ 'NOTIFY_ON_START_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
+ 'NOTIFY_ON_START_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) started playing {title}.'),
+ 'NOTIFY_ON_STOP_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
+ 'NOTIFY_ON_STOP_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) has stopped {title}.'),
+ 'NOTIFY_ON_PAUSE_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
+ 'NOTIFY_ON_PAUSE_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) has paused {title}.'),
+ 'NOTIFY_ON_RESUME_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
+ 'NOTIFY_ON_RESUME_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) has resumed {title}.'),
+ 'NOTIFY_ON_BUFFER_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
+ 'NOTIFY_ON_BUFFER_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) is buffering {title}.'),
+ 'NOTIFY_ON_WATCHED_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
+ 'NOTIFY_ON_WATCHED_BODY_TEXT': (unicode, 'Monitoring', '{user} ({player}) has watched {title}.'),
+ 'NOTIFY_ON_CREATED_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
+ 'NOTIFY_ON_CREATED_BODY_TEXT': (unicode, 'Monitoring', '{title} was recently added to Plex.'),
+ 'NOTIFY_ON_EXTDOWN_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
+ 'NOTIFY_ON_EXTDOWN_BODY_TEXT': (unicode, 'Monitoring', 'The Plex Media Server remote access is down.'),
+ 'NOTIFY_ON_INTDOWN_SUBJECT_TEXT': (unicode, 'Monitoring', 'PlexPy ({server_name})'),
+ 'NOTIFY_ON_INTDOWN_BODY_TEXT': (unicode, 'Monitoring', 'The Plex Media Server is down.'),
'OSX_NOTIFY_APP': (str, 'OSX_Notify', '/Applications/PlexPy'),
'OSX_NOTIFY_ENABLED': (int, 'OSX_Notify', 0),
'OSX_NOTIFY_ON_PLAY': (int, 'OSX_Notify', 0),
From c65d9898c8202f8450557fb760d111dc9130196f Mon Sep 17 00:00:00 2001
From: Jonathan Wong
Date: Tue, 1 Dec 2015 20:05:37 -0800
Subject: [PATCH 04/22] Add icon for Apple tvOS
---
data/interfaces/default/js/script.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/data/interfaces/default/js/script.js b/data/interfaces/default/js/script.js
index 50348c46..4332ecc2 100644
--- a/data/interfaces/default/js/script.js
+++ b/data/interfaces/default/js/script.js
@@ -176,7 +176,9 @@ function getPlatformImagePath(platformName) {
if (platformName.indexOf("Roku") > -1) {
return 'interfaces/default/images/platforms/roku.png';
} 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) {
return 'interfaces/default/images/platforms/firefox.png';
} else if (platformName.indexOf("Chromecast") > -1) {
From bac5018b275b5908053e7b92f8a40ca15f2c0058 Mon Sep 17 00:00:00 2001
From: Jonathan Wong
Date: Tue, 1 Dec 2015 21:31:48 -0800
Subject: [PATCH 05/22] Add channel support to Telegram notifier
---
plexpy/config.py | 2 +-
plexpy/notifiers.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/plexpy/config.py b/plexpy/config.py
index 3064af10..381fe064 100644
--- a/plexpy/config.py
+++ b/plexpy/config.py
@@ -250,7 +250,7 @@ _CONFIG_DEFINITIONS = {
'REFRESH_USERS_ON_STARTUP': (int, 'Monitoring', 1),
'TELEGRAM_BOT_TOKEN': (str, 'Telegram', ''),
'TELEGRAM_ENABLED': (int, 'Telegram', 0),
- 'TELEGRAM_CHAT_ID': (int, 'Telegram', 0),
+ 'TELEGRAM_CHAT_ID': (str, 'Telegram', ''),
'TELEGRAM_ON_PLAY': (int, 'Telegram', 0),
'TELEGRAM_ON_STOP': (int, 'Telegram', 0),
'TELEGRAM_ON_PAUSE': (int, 'Telegram', 0),
diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py
index a933c840..23bf66b1 100644
--- a/plexpy/notifiers.py
+++ b/plexpy/notifiers.py
@@ -1526,7 +1526,7 @@ class TELEGRAM(object):
{'label': 'Telegram Chat ID',
'value': self.chat_id,
'name': 'telegram_chat_id',
- 'description': 'Your Telegram Chat ID or Group ID. Contact @myidbot on Telegram to get an ID.',
+ 'description': 'Your Telegram Chat ID, Group ID, or channel username. Contact @myidbot on Telegram to get an ID.',
'input_type': 'text'
}
]
From b8d9c8cc47b8165c3f54d936858bf9c422d4dd5d Mon Sep 17 00:00:00 2001
From: Jonathan Wong
Date: Tue, 1 Dec 2015 21:50:47 -0800
Subject: [PATCH 06/22] Set blank metadata so recently added check continues
when and item isn't found
---
plexpy/activity_pinger.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/plexpy/activity_pinger.py b/plexpy/activity_pinger.py
index aa41d1fe..e57a0c91 100644
--- a/plexpy/activity_pinger.py
+++ b/plexpy/activity_pinger.py
@@ -180,6 +180,8 @@ def check_recently_added():
recently_added = recently_added_list['recently_added']
for item in recently_added:
+ metadata = []
+
if item['media_type'] == 'movie':
metadata_list = pms_connect.get_metadata_details(item['rating_key'])
if metadata_list:
From 10c54c2d108e8caf8bcfc201c034999b3013d9ee Mon Sep 17 00:00:00 2001
From: Jonathan Wong
Date: Tue, 1 Dec 2015 21:57:02 -0800
Subject: [PATCH 07/22] Only show IPv4 addresses
---
plexpy/activity_processor.py | 36 ++++++++++++++++++------------------
plexpy/pmsconnect.py | 10 +++++-----
2 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/plexpy/activity_processor.py b/plexpy/activity_processor.py
index bdc2b83d..fb1a2376 100644
--- a/plexpy/activity_processor.py
+++ b/plexpy/activity_processor.py
@@ -286,16 +286,16 @@ class ActivityProcessor(object):
# The logged IP will always be the first match and we don't want localhost entries
if ipv4[0] != '127.0.0.1':
# check if IPv4 mapped IPv6 address (::ffff:xxx.xxx.xxx.xxx)
- if '::ffff:' + ipv4[0] in line:
- logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s "
- u"and machineIdentifier %s."
- % ('::ffff:' + ipv4[0], rating_key, machine_id))
- return '::ffff:' + ipv4[0]
- else:
- logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s "
- u"and machineIdentifier %s."
- % (ipv4[0], rating_key, machine_id))
- return ipv4[0]
+ #if '::ffff:' + ipv4[0] in line:
+ # logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s "
+ # u"and machineIdentifier %s."
+ # % ('::ffff:' + ipv4[0], rating_key, machine_id))
+ # return '::ffff:' + ipv4[0]
+ #else:
+ logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s "
+ u"and machineIdentifier %s."
+ % (ipv4[0], rating_key, machine_id))
+ return ipv4[0]
logger.debug(u"PlexPy ActivityProcessor :: Unable to find IP address on first pass. "
u"Attempting fallback check in 5 seconds...")
@@ -315,14 +315,14 @@ class ActivityProcessor(object):
if ipv4:
# The logged IP will always be the first match and we don't want localhost entries
if ipv4[0] != '127.0.0.1':
- if '::ffff:' + ipv4[0] in line:
- logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s." %
- ('::ffff:' + ipv4[0], rating_key))
- return '::ffff:' + ipv4[0]
- else:
- logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s." %
- (ipv4[0], rating_key))
- return ipv4[0]
+ #if '::ffff:' + ipv4[0] in line:
+ # logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s." %
+ # ('::ffff:' + ipv4[0], rating_key))
+ # return '::ffff:' + ipv4[0]
+ #else:
+ logger.debug(u"PlexPy ActivityProcessor :: Matched IP address (%s) for stream ratingKey %s." %
+ (ipv4[0], rating_key))
+ return ipv4[0]
logger.debug(u"PlexPy ActivityProcessor :: Unable to find IP address on fallback search. Not logging IP address.")
diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py
index a313813a..d52ff65a 100644
--- a/plexpy/pmsconnect.py
+++ b/plexpy/pmsconnect.py
@@ -803,7 +803,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'],
'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'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id,
@@ -924,7 +924,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'],
'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'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id,
@@ -981,7 +981,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'],
'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'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id,
@@ -1038,7 +1038,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'],
'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'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id,
@@ -1128,7 +1128,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'],
'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'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id,
From 7540b5fb3463aa175addb332cdc094b458a9eca8 Mon Sep 17 00:00:00 2001
From: Jonathan Wong
Date: Tue, 1 Dec 2015 22:54:58 -0800
Subject: [PATCH 08/22] Fix recently added notification delay
---
plexpy/activity_pinger.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/plexpy/activity_pinger.py b/plexpy/activity_pinger.py
index e57a0c91..4063a7dd 100644
--- a/plexpy/activity_pinger.py
+++ b/plexpy/activity_pinger.py
@@ -201,7 +201,7 @@ def check_recently_added():
if metadata:
if not plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT:
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']))
# Fire off notifications
threading.Thread(target=notification_handler.notify_timeline,
@@ -210,7 +210,7 @@ def check_recently_added():
else:
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':
metadata_list = pms_connect.get_metadata_details(item['grandparent_rating_key'])
From ede07595c3d6f50fd496291092d1f1eb9fcbccb1 Mon Sep 17 00:00:00 2001
From: Jonathan Wong
Date: Wed, 2 Dec 2015 19:15:46 -0800
Subject: [PATCH 09/22] Match newline characters in notification text
---
plexpy/notification_handler.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/plexpy/notification_handler.py b/plexpy/notification_handler.py
index 29d65097..2f91a5df 100644
--- a/plexpy/notification_handler.py
+++ b/plexpy/notification_handler.py
@@ -315,13 +315,13 @@ def build_notify_text(session=None, timeline=None, state=None):
# Check for exclusion tags
if metadata['media_type'] == 'movie':
# Regex pattern to remove the text in the tags we don't want
- pattern = re.compile('[^>]+.|[^>]+.', re.IGNORECASE)
+ pattern = re.compile('[^>]+.|[^>]+.', re.IGNORECASE|re.DOTALL)
elif metadata['media_type'] == 'show' or metadata['media_type'] == 'episode':
# Regex pattern to remove the text in the tags we don't want
- pattern = re.compile('[^>]+.|[^>]+.', re.IGNORECASE)
+ pattern = re.compile('[^>]+.|[^>]+.', re.IGNORECASE|re.DOTALL)
elif metadata['media_type'] == 'artist' or metadata['media_type'] == 'track':
# Regex pattern to remove the text in the tags we don't want
- pattern = re.compile('[^>]+.|[^>]+.', re.IGNORECASE)
+ pattern = re.compile('[^>]+.|[^>]+.', re.IGNORECASE|re.DOTALL)
else:
pattern = None
From 112811f3e20845394c38f433abd6887c3351eba0 Mon Sep 17 00:00:00 2001
From: Jonathan Wong
Date: Wed, 2 Dec 2015 19:18:04 -0800
Subject: [PATCH 10/22] Fix subject UTF-8 encode for Prowl notifier
---
plexpy/notifiers.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py
index 23bf66b1..d8124917 100644
--- a/plexpy/notifiers.py
+++ b/plexpy/notifiers.py
@@ -505,7 +505,7 @@ class PROWL(object):
data = {'apikey': plexpy.CONFIG.PROWL_KEYS,
'application': 'PlexPy',
- 'event': event,
+ 'event': event.encode("utf-8"),
'description': message.encode("utf-8"),
'priority': plexpy.CONFIG.PROWL_PRIORITY}
From 89f581f63ec4579bfd341f6ec740320830cd10bf Mon Sep 17 00:00:00 2001
From: Jonathan Wong
Date: Thu, 3 Dec 2015 18:40:18 -0800
Subject: [PATCH 11/22] Only schedule job for recently added or monitor remote
access if setting enabled
---
data/interfaces/default/settings.html | 5 +++++
plexpy/__init__.py | 18 ++++++++++++----
plexpy/activity_pinger.py | 31 +++++++++++++--------------
plexpy/config.py | 1 +
plexpy/webserve.py | 11 +++++++++-
5 files changed, 45 insertions(+), 21 deletions(-)
diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html
index fd3dd1c5..e8d3dfa4 100644
--- a/data/interfaces/default/settings.html
+++ b/data/interfaces/default/settings.html
@@ -499,6 +499,11 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
Enable Music Notifications
+
+
+
Current Activity Notifications
diff --git a/plexpy/__init__.py b/plexpy/__init__.py
index 88fb73f7..bbd234da 100644
--- a/plexpy/__init__.py
+++ b/plexpy/__init__.py
@@ -285,10 +285,20 @@ def initialize_scheduler():
hours=12, minutes=0, seconds=0)
schedule_job(pmsconnect.get_server_friendly_name, 'Refresh Plex Server Name',
hours=12, minutes=0, seconds=0)
- schedule_job(activity_pinger.check_recently_added, 'Check for recently added items',
- hours=0, minutes=0, seconds=seconds)
- schedule_job(activity_pinger.check_server_response, 'Check for server response',
- hours=0, minutes=0, seconds=seconds)
+
+ if CONFIG.NOTIFY_RECENTLY_ADDED:
+ schedule_job(activity_pinger.check_recently_added, 'Check for recently added items',
+ 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 not CONFIG.MONITORING_USE_WEBSOCKET or POLLING_FAILOVER:
diff --git a/plexpy/activity_pinger.py b/plexpy/activity_pinger.py
index 4063a7dd..28a340e7 100644
--- a/plexpy/activity_pinger.py
+++ b/plexpy/activity_pinger.py
@@ -33,7 +33,11 @@ def check_active_sessions(ws_request=False):
monitor_process = activity_processor.ActivityProcessor()
# logger.debug(u"PlexPy Monitor :: Checking for active streams.")
+ global int_ping_count
+
if session_list:
+ int_ping_count = 0
+
media_container = session_list['sessions']
# 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:
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():
with monitor_lock:
@@ -231,20 +245,10 @@ def check_server_response():
pms_connect = pmsconnect.PmsConnect()
server_response = pms_connect.get_server_response()
- global int_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
- if server_response and plexpy.CONFIG.MONITOR_REMOTE_ACCESS:
+ if server_response:
mapping_state = server_response['mapping_state']
mapping_error = server_response['mapping_error']
@@ -263,11 +267,6 @@ def check_server_response():
else:
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:
# Fire off notifications
threading.Thread(target=notification_handler.notify_timeline,
diff --git a/plexpy/config.py b/plexpy/config.py
index 381fe064..491f2081 100644
--- a/plexpy/config.py
+++ b/plexpy/config.py
@@ -151,6 +151,7 @@ _CONFIG_DEFINITIONS = {
'NMA_ON_EXTDOWN': (int, 'NMA', 0),
'NMA_ON_INTDOWN': (int, 'NMA', 0),
'NOTIFY_CONSECUTIVE': (int, 'Monitoring', 1),
+ 'NOTIFY_RECENTLY_ADDED': (int, 'Monitoring', 0),
'NOTIFY_RECENTLY_ADDED_GRANDPARENT': (int, 'Monitoring', 0),
'NOTIFY_RECENTLY_ADDED_DELAY': (int, 'Monitoring', 60),
'NOTIFY_WATCHED_PERCENT': (int, 'Monitoring', 85),
diff --git a/plexpy/webserve.py b/plexpy/webserve.py
index 85be241f..89065bf5 100644
--- a/plexpy/webserve.py
+++ b/plexpy/webserve.py
@@ -448,6 +448,7 @@ class WebInterface(object):
"logging_ignore_interval": plexpy.CONFIG.LOGGING_IGNORE_INTERVAL,
"pms_is_remote": checked(plexpy.CONFIG.PMS_IS_REMOTE),
"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_delay": plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_DELAY,
"notify_watched_percent": plexpy.CONFIG.NOTIFY_WATCHED_PERCENT,
@@ -494,7 +495,7 @@ class WebInterface(object):
"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",
"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:
if checked_config not in kwargs:
@@ -519,6 +520,14 @@ class WebInterface(object):
if (kwargs['monitoring_interval'] != str(plexpy.CONFIG.MONITORING_INTERVAL)) or \
(kwargs['refresh_users_interval'] != str(plexpy.CONFIG.REFRESH_USERS_INTERVAL)):
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 kwargs['pms_ip'] != plexpy.CONFIG.PMS_IP:
From ef6ef9854131dd6d0a0aac143b0921dd304a230d Mon Sep 17 00:00:00 2001
From: Jonathan Wong
Date: Thu, 3 Dec 2015 19:07:24 -0800
Subject: [PATCH 12/22] Clean up settings help text and wording
---
data/interfaces/default/settings.html | 15 +++++++--------
data/interfaces/default/welcome.html | 6 +++---
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html
index e8d3dfa4..6cef6983 100644
--- a/data/interfaces/default/settings.html
+++ b/data/interfaces/default/settings.html
@@ -313,7 +313,8 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
-
Set the complete folder path where your Plex Server logs are, shortcuts are not recognized. Click here for help. This is required if you enable IP logging.
+
Set the complete folder path where your Plex Server logs are, shortcuts are not recognized.
+ Click here for help. This is required if you enable IP logging (for PMS 0.9.12 and below).