From 198e7767dc7cff32832329289662d3bcfcdfd6b3 Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Fri, 10 Apr 2020 00:12:38 -0700 Subject: [PATCH] Add library is_active to database --- plexpy/__init__.py | 11 ++++++++++- plexpy/libraries.py | 9 +++++++++ plexpy/pmsconnect.py | 3 ++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/plexpy/__init__.py b/plexpy/__init__.py index 24b58f8e..b422c922 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -675,7 +675,7 @@ def dbcheck(): 'CREATE TABLE IF NOT EXISTS library_sections (id INTEGER PRIMARY KEY AUTOINCREMENT, ' 'server_id TEXT, section_id INTEGER, section_name TEXT, section_type TEXT, agent TEXT, ' 'thumb TEXT, custom_thumb_url TEXT, art TEXT, custom_art_url TEXT, ' - 'count INTEGER, parent_count INTEGER, child_count INTEGER, ' + 'count INTEGER, parent_count INTEGER, child_count INTEGER, is_active INTEGER DEFAULT 1, ' 'do_notify INTEGER DEFAULT 1, do_notify_created INTEGER DEFAULT 1, keep_history INTEGER DEFAULT 1, ' 'deleted_section INTEGER DEFAULT 0, UNIQUE(server_id, section_id))' ) @@ -1914,6 +1914,15 @@ def dbcheck(): 'ALTER TABLE library_sections ADD COLUMN custom_art_url TEXT' ) + # Upgrade library_sections table from earlier versions + try: + c_db.execute('SELECT is_active FROM library_sections') + except sqlite3.OperationalError: + logger.debug(u"Altering database. Updating database table library_sections.") + c_db.execute( + 'ALTER TABLE library_sections ADD COLUMN is_active INTEGER DEFAULT 1' + ) + # Upgrade users table from earlier versions (remove UNIQUE constraint on username) try: result = c_db.execute('SELECT SQL FROM sqlite_master WHERE type="table" AND name="users"').fetchone() diff --git a/plexpy/libraries.py b/plexpy/libraries.py index 91c27a33..b6461e3b 100644 --- a/plexpy/libraries.py +++ b/plexpy/libraries.py @@ -43,7 +43,12 @@ def refresh_libraries(): library_keys = [] new_keys = [] + # Keep track of section_id to update is_active status + section_ids = [common.LIVE_TV_SECTION_ID] # Live TV library always considered active + for section in library_sections: + section_ids.append(helpers.cast_to_int(section['section_id'])) + section_keys = {'server_id': server_id, 'section_id': section['section_id']} section_values = {'server_id': server_id, @@ -65,6 +70,10 @@ def refresh_libraries(): if result == 'insert': new_keys.append(section['section_id']) + query = 'UPDATE library_sections SET is_active = 0 WHERE server_id != ? OR ' \ + 'section_id NOT IN ({})'.format(', '.join(['?'] * len(section_ids))) + monitor_db.action(query=query, args=[plexpy.CONFIG.PMS_IDENTIFIER] + section_ids) + if plexpy.CONFIG.HOME_LIBRARY_CARDS == ['first_run_wizard']: plexpy.CONFIG.__setattr__('HOME_LIBRARY_CARDS', library_keys) plexpy.CONFIG.write() diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py index 58cbe02a..16cba489 100644 --- a/plexpy/pmsconnect.py +++ b/plexpy/pmsconnect.py @@ -2643,7 +2643,8 @@ class PmsConnect(object): 'agent': library['agent'], 'thumb': library['thumb'], 'art': library['art'], - 'count': children_list['library_count'] + 'count': children_list['library_count'], + 'is_active': 1 } if section_type == 'show':