diff --git a/plexpy/__init__.py b/plexpy/__init__.py index 7d5fb00d..a7313b49 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -714,8 +714,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, friendly_name TEXT, ' - 'thumb TEXT, custom_avatar_url TEXT, email TEXT, is_active INTEGER DEFAULT 1, is_admin INTEGER DEFAULT 0, ' - 'is_home_user INTEGER DEFAULT NULL, is_allow_sync INTEGER DEFAULT NULL, is_restricted INTEGER DEFAULT NULL, ' + 'thumb TEXT, custom_avatar_url TEXT, title TEXT, email TEXT, ' + 'is_active INTEGER DEFAULT 1, is_admin INTEGER DEFAULT 0, 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, deleted_user INTEGER DEFAULT 0, ' 'allow_guest INTEGER DEFAULT 0, user_token TEXT, server_token TEXT, shared_libraries TEXT, ' 'filter_all TEXT, filter_movies TEXT, filter_tv TEXT, filter_music TEXT, filter_photos TEXT)' @@ -1909,6 +1910,15 @@ def dbcheck(): 'ALTER TABLE users ADD COLUMN is_active INTEGER DEFAULT 1' ) + # Upgrade users table from earlier versions + try: + c_db.execute('SELECT title FROM users') + except sqlite3.OperationalError: + logger.debug("Altering database. Updating database table users.") + c_db.execute( + 'ALTER TABLE users ADD COLUMN title TEXT' + ) + # Upgrade notify_log table from earlier versions try: c_db.execute('SELECT poster_url FROM notify_log') diff --git a/plexpy/plextv.py b/plexpy/plextv.py index d95f8d16..1cb53dd5 100644 --- a/plexpy/plextv.py +++ b/plexpy/plextv.py @@ -357,6 +357,7 @@ class PlexTV(object): for a in xml_head: own_details = {"user_id": helpers.get_xml_attr(a, 'id'), "username": helpers.get_xml_attr(a, 'username'), + "title": helpers.get_xml_attr(a, 'title'), "thumb": helpers.get_xml_attr(a, 'thumb'), "email": helpers.get_xml_attr(a, 'email'), "is_active": 1, @@ -384,7 +385,8 @@ class PlexTV(object): for a in xml_head: friend = {"user_id": helpers.get_xml_attr(a, 'id'), - "username": helpers.get_xml_attr(a, 'title'), + "username": helpers.get_xml_attr(a, 'username'), + "title": helpers.get_xml_attr(a, 'title'), "thumb": helpers.get_xml_attr(a, 'thumb'), "email": helpers.get_xml_attr(a, 'email'), "is_active": 1, diff --git a/plexpy/users.py b/plexpy/users.py index c79b62d5..81276e08 100644 --- a/plexpy/users.py +++ b/plexpy/users.py @@ -84,6 +84,10 @@ def refresh_users(): else: item['custom_avatar_url'] = item['thumb'] + # Check if title is the same as the username + if item['title'] == item['username']: + item['title'] = None + monitor_db.upsert('users', key_dict=keys_dict, value_dict=item) query = 'UPDATE users SET is_active = 0 WHERE user_id NOT IN ({})'.format(', '.join(['?'] * len(user_ids)))