mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 23:42:37 -07:00
Remove unused library update functions
This commit is contained in:
parent
01c56ef280
commit
b97d32671d
2 changed files with 1 additions and 157 deletions
|
@ -180,9 +180,7 @@ _CONFIG_DEFINITIONS = {
|
||||||
'TVMAZE_LOOKUP': (int, 'General', 0),
|
'TVMAZE_LOOKUP': (int, 'General', 0),
|
||||||
'TV_WATCHED_PERCENT': (int, 'Monitoring', 85),
|
'TV_WATCHED_PERCENT': (int, 'Monitoring', 85),
|
||||||
'UPDATE_DB_INTERVAL': (int, 'General', 24),
|
'UPDATE_DB_INTERVAL': (int, 'General', 24),
|
||||||
'UPDATE_SECTION_IDS': (int, 'General', 1),
|
|
||||||
'UPDATE_SHOW_CHANGELOG': (int, 'General', 1),
|
'UPDATE_SHOW_CHANGELOG': (int, 'General', 1),
|
||||||
'UPDATE_LABELS': (int, 'General', 1),
|
|
||||||
'VERBOSE_LOGS': (int, 'Advanced', 1),
|
'VERBOSE_LOGS': (int, 'Advanced', 1),
|
||||||
'VERIFY_SSL_CERT': (bool_int, 'Advanced', 1),
|
'VERIFY_SSL_CERT': (bool_int, 'Advanced', 1),
|
||||||
'VIDEO_LOGGING_ENABLE': (int, 'Monitoring', 1),
|
'VIDEO_LOGGING_ENABLE': (int, 'Monitoring', 1),
|
||||||
|
@ -197,7 +195,7 @@ _CONFIG_DEFINITIONS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
_BLACKLIST_KEYS = ['_APITOKEN', '_TOKEN', '_KEY', '_SECRET', '_PASSWORD', '_APIKEY', '_ID', '_HOOK']
|
_BLACKLIST_KEYS = ['_APITOKEN', '_TOKEN', '_KEY', '_SECRET', '_PASSWORD', '_APIKEY', '_ID', '_HOOK']
|
||||||
_WHITELIST_KEYS = ['HTTPS_KEY', 'UPDATE_SECTION_IDS']
|
_WHITELIST_KEYS = ['HTTPS_KEY']
|
||||||
|
|
||||||
|
|
||||||
def make_backup(cleanup=False, scheduler=False):
|
def make_backup(cleanup=False, scheduler=False):
|
||||||
|
|
|
@ -102,14 +102,6 @@ def refresh_libraries():
|
||||||
plexpy.CONFIG.__setattr__('HOME_LIBRARY_CARDS', new_keys)
|
plexpy.CONFIG.__setattr__('HOME_LIBRARY_CARDS', new_keys)
|
||||||
plexpy.CONFIG.write()
|
plexpy.CONFIG.write()
|
||||||
|
|
||||||
#if plexpy.CONFIG.UPDATE_SECTION_IDS == 1 or plexpy.CONFIG.UPDATE_SECTION_IDS == -1:
|
|
||||||
# # Start library section_id update on it's own thread
|
|
||||||
# threading.Thread(target=libraries.update_section_ids).start()
|
|
||||||
|
|
||||||
#if plexpy.CONFIG.UPDATE_LABELS == 1 or plexpy.CONFIG.UPDATE_LABELS == -1:
|
|
||||||
# # Start library labels update on it's own thread
|
|
||||||
# threading.Thread(target=libraries.update_labels).start()
|
|
||||||
|
|
||||||
logger.info("Tautulli Libraries :: Libraries list refreshed.")
|
logger.info("Tautulli Libraries :: Libraries list refreshed.")
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
@ -148,152 +140,6 @@ def has_library_type(section_type):
|
||||||
return bool(result)
|
return bool(result)
|
||||||
|
|
||||||
|
|
||||||
def update_section_ids():
|
|
||||||
plexpy.CONFIG.UPDATE_SECTION_IDS = -1
|
|
||||||
|
|
||||||
monitor_db = database.MonitorDatabase()
|
|
||||||
|
|
||||||
try:
|
|
||||||
query = 'SELECT id, rating_key, grandparent_rating_key, media_type ' \
|
|
||||||
'FROM session_history_metadata WHERE section_id IS NULL'
|
|
||||||
history_results = monitor_db.select(query=query)
|
|
||||||
query = 'SELECT section_id, section_type FROM library_sections'
|
|
||||||
library_results = monitor_db.select(query=query)
|
|
||||||
except Exception as e:
|
|
||||||
logger.warn("Tautulli Libraries :: Unable to execute database query for update_section_ids: %s." % e)
|
|
||||||
|
|
||||||
logger.warn("Tautulli Libraries :: Unable to update section_id's in database.")
|
|
||||||
plexpy.CONFIG.UPDATE_SECTION_IDS = 1
|
|
||||||
plexpy.CONFIG.write()
|
|
||||||
return None
|
|
||||||
|
|
||||||
if not history_results:
|
|
||||||
plexpy.CONFIG.UPDATE_SECTION_IDS = 0
|
|
||||||
plexpy.CONFIG.write()
|
|
||||||
return None
|
|
||||||
|
|
||||||
logger.debug("Tautulli Libraries :: Updating section_id's in database.")
|
|
||||||
|
|
||||||
# Get rating_key: section_id mapping pairs
|
|
||||||
key_mappings = {}
|
|
||||||
|
|
||||||
pms_connect = pmsconnect.PmsConnect()
|
|
||||||
for library in library_results:
|
|
||||||
section_id = library['section_id']
|
|
||||||
section_type = library['section_type']
|
|
||||||
|
|
||||||
if section_type != 'photo':
|
|
||||||
library_children = pms_connect.get_library_children_details(section_id=section_id,
|
|
||||||
section_type=section_type)
|
|
||||||
if library_children:
|
|
||||||
children_list = library_children['children_list']
|
|
||||||
key_mappings.update({child['rating_key']: child['section_id'] for child in children_list})
|
|
||||||
else:
|
|
||||||
logger.warn("Tautulli Libraries :: Unable to get a list of library items for section_id %s." % section_id)
|
|
||||||
|
|
||||||
error_keys = set()
|
|
||||||
for item in history_results:
|
|
||||||
rating_key = item['grandparent_rating_key'] if item['media_type'] != 'movie' else item['rating_key']
|
|
||||||
section_id = key_mappings.get(str(rating_key), None)
|
|
||||||
|
|
||||||
if section_id:
|
|
||||||
try:
|
|
||||||
section_keys = {'id': item['id']}
|
|
||||||
section_values = {'section_id': section_id}
|
|
||||||
monitor_db.upsert('session_history_metadata', key_dict=section_keys, value_dict=section_values)
|
|
||||||
except:
|
|
||||||
error_keys.add(item['rating_key'])
|
|
||||||
else:
|
|
||||||
error_keys.add(item['rating_key'])
|
|
||||||
|
|
||||||
if error_keys:
|
|
||||||
logger.info("Tautulli Libraries :: Updated all section_id's in database except for rating_keys: %s." %
|
|
||||||
', '.join(str(key) for key in error_keys))
|
|
||||||
else:
|
|
||||||
logger.info("Tautulli Libraries :: Updated all section_id's in database.")
|
|
||||||
|
|
||||||
plexpy.CONFIG.UPDATE_SECTION_IDS = 0
|
|
||||||
plexpy.CONFIG.write()
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def update_labels():
|
|
||||||
plexpy.CONFIG.UPDATE_LABELS = -1
|
|
||||||
|
|
||||||
monitor_db = database.MonitorDatabase()
|
|
||||||
|
|
||||||
try:
|
|
||||||
query = 'SELECT section_id, section_type FROM library_sections'
|
|
||||||
library_results = monitor_db.select(query=query)
|
|
||||||
except Exception as e:
|
|
||||||
logger.warn("Tautulli Libraries :: Unable to execute database query for update_labels: %s." % e)
|
|
||||||
|
|
||||||
logger.warn("Tautulli Libraries :: Unable to update labels in database.")
|
|
||||||
plexpy.CONFIG.UPDATE_LABELS = 1
|
|
||||||
plexpy.CONFIG.write()
|
|
||||||
return None
|
|
||||||
|
|
||||||
if not library_results:
|
|
||||||
plexpy.CONFIG.UPDATE_LABELS = 0
|
|
||||||
plexpy.CONFIG.write()
|
|
||||||
return None
|
|
||||||
|
|
||||||
logger.debug("Tautulli Libraries :: Updating labels in database.")
|
|
||||||
|
|
||||||
# Get rating_key: section_id mapping pairs
|
|
||||||
key_mappings = {}
|
|
||||||
|
|
||||||
pms_connect = pmsconnect.PmsConnect()
|
|
||||||
for library in library_results:
|
|
||||||
section_id = library['section_id']
|
|
||||||
section_type = library['section_type']
|
|
||||||
|
|
||||||
if section_type != 'photo':
|
|
||||||
library_children = []
|
|
||||||
library_labels = pms_connect.get_library_label_details(section_id=section_id)
|
|
||||||
|
|
||||||
if library_labels:
|
|
||||||
for label in library_labels:
|
|
||||||
library_children = pms_connect.get_library_children_details(section_id=section_id,
|
|
||||||
section_type=section_type,
|
|
||||||
label_key=label['label_key'])
|
|
||||||
|
|
||||||
if library_children:
|
|
||||||
children_list = library_children['children_list']
|
|
||||||
# rating_key_list = [child['rating_key'] for child in children_list]
|
|
||||||
|
|
||||||
for rating_key in [child['rating_key'] for child in children_list]:
|
|
||||||
if key_mappings.get(rating_key):
|
|
||||||
key_mappings[rating_key].append(label['label_title'])
|
|
||||||
else:
|
|
||||||
key_mappings[rating_key] = [label['label_title']]
|
|
||||||
|
|
||||||
else:
|
|
||||||
logger.warn("Tautulli Libraries :: Unable to get a list of library items for section_id %s."
|
|
||||||
% section_id)
|
|
||||||
|
|
||||||
error_keys = set()
|
|
||||||
for rating_key, labels in key_mappings.items():
|
|
||||||
try:
|
|
||||||
labels = ';'.join(labels)
|
|
||||||
monitor_db.action('UPDATE session_history_metadata SET labels = ? '
|
|
||||||
'WHERE rating_key = ? OR parent_rating_key = ? OR grandparent_rating_key = ? ',
|
|
||||||
args=[labels, rating_key, rating_key, rating_key])
|
|
||||||
except:
|
|
||||||
error_keys.add(rating_key)
|
|
||||||
|
|
||||||
if error_keys:
|
|
||||||
logger.info("Tautulli Libraries :: Updated all labels in database except for rating_keys: %s." %
|
|
||||||
', '.join(str(key) for key in error_keys))
|
|
||||||
else:
|
|
||||||
logger.info("Tautulli Libraries :: Updated all labels in database.")
|
|
||||||
|
|
||||||
plexpy.CONFIG.UPDATE_LABELS = 0
|
|
||||||
plexpy.CONFIG.write()
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class Libraries(object):
|
class Libraries(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue