From 4a8748e32239e6f516b52dd69fb5a0bc13c988b8 Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Tue, 7 Jul 2020 18:14:00 -0700 Subject: [PATCH] Live TV library not being recreated after server identifier is changed * Fixes Tautulli/Tautulli-Issues#261 --- plexpy/config.py | 1 - plexpy/libraries.py | 20 +++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/plexpy/config.py b/plexpy/config.py index 6bba8648..a685338b 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -75,7 +75,6 @@ _CONFIG_DEFINITIONS = { 'PMS_UPDATE_CHECK_INTERVAL': (int, 'Advanced', 24), 'PMS_WEB_URL': (str, 'PMS', 'https://app.plex.tv/desktop'), 'TIME_FORMAT': (str, 'General', 'HH:mm'), - 'ADD_LIVE_TV_LIBRARY': (int, 'Advanced', 1), 'ANON_REDIRECT': (str, 'General', 'http://www.nullrefer.com/?'), 'API_ENABLED': (int, 'General', 1), 'API_KEY': (str, 'General', ''), diff --git a/plexpy/libraries.py b/plexpy/libraries.py index 0abf5491..881ff2e3 100644 --- a/plexpy/libraries.py +++ b/plexpy/libraries.py @@ -88,6 +88,8 @@ def refresh_libraries(): if result == 'insert': new_keys.append(section['section_id']) + add_live_tv_library(refresh=True) + 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) @@ -115,28 +117,28 @@ def refresh_libraries(): return False -def add_live_tv_library(): - if not plexpy.CONFIG.ADD_LIVE_TV_LIBRARY: +def add_live_tv_library(refresh=False): + monitor_db = database.MonitorDatabase() + result = monitor_db.select_single('SELECT * FROM library_sections ' + 'WHERE section_id = ? and server_id = ?', + [common.LIVE_TV_SECTION_ID, plexpy.CONFIG.PMS_IDENTIFIER]) + + if result and not refresh or not result and refresh: return logger.info("Tautulli Libraries :: Adding Live TV library to the database.") - monitor_db = database.MonitorDatabase() - section_keys = {'server_id': plexpy.CONFIG.PMS_IDENTIFIER, 'section_id': common.LIVE_TV_SECTION_ID} section_values = {'server_id': plexpy.CONFIG.PMS_IDENTIFIER, 'section_id': common.LIVE_TV_SECTION_ID, 'section_name': common.LIVE_TV_SECTION_NAME, - 'section_type': 'live' + 'section_type': 'live', + 'is_active': 1 } result = monitor_db.upsert('library_sections', key_dict=section_keys, value_dict=section_values) - if result == 'insert': - plexpy.CONFIG.__setattr__('ADD_LIVE_TV_LIBRARY', 0) - plexpy.CONFIG.write() - def has_library_type(section_type): monitor_db = database.MonitorDatabase()