From fc43f4773a57b4084f40202fc85c51458531f04d Mon Sep 17 00:00:00 2001 From: Jonathan Wong Date: Mon, 19 Oct 2015 21:18:18 -0700 Subject: [PATCH] Update library_id from top level info page * Calls update first time loading the page --- data/interfaces/default/info.html | 18 ++++++++++++++++++ plexpy/__init__.py | 9 --------- plexpy/config.py | 1 + plexpy/webserve.py | 19 ++++++++++++++++++- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/data/interfaces/default/info.html b/data/interfaces/default/info.html index f5ff3932..6de5b27f 100644 --- a/data/interfaces/default/info.html +++ b/data/interfaces/default/info.html @@ -502,6 +502,24 @@ DOCUMENTATION :: END 'library_id': "${data['library_id']}" }; } } + if ("${config['update_library_ids']}" == "1") { + $('#history_table').before('
\ + Updating library ids in the database. This could take a few minutes depending on the size of your database. \ +
\ + The history table will refresh automatically when complete. Please wait... \ +
') + $.ajax({ + url: 'update_library_ids', + type: 'post', + cache: false, + async: true, + data: { }, + complete: function (xhr, status) { + $('#update_mssage').remove(); + history_table.draw(); + } + }); + } } % elif data['type'] == 'show' or data['type'] == 'artist': diff --git a/plexpy/__init__.py b/plexpy/__init__.py index a9b05274..b62df1ed 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -609,15 +609,6 @@ def dbcheck(): c_db.execute( 'ALTER TABLE session_history_metadata ADD COLUMN library_title TEXT' ) - logger.debug(u"Updating library_id's in database. Please wait...") - from plexpy import datafactory - data_factory = datafactory.DataFactory() - result = data_factory.update_library_ids() - - if result: - logger.debug(u"Updated all library_id's in database.") - else: - logger.debug(u"Unable to update library_id's in database.") # Upgrade users table from earlier versions try: diff --git a/plexpy/config.py b/plexpy/config.py index f9e65086..3a597814 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -210,6 +210,7 @@ _CONFIG_DEFINITIONS = { 'TWITTER_ON_BUFFER': (int, 'Twitter', 0), 'TWITTER_ON_WATCHED': (int, 'Twitter', 0), 'UPDATE_DB_INTERVAL': (int, 'General', 24), + 'UPDATE_LIBRARY_IDS': (int, 'General', 1), 'VERIFY_SSL_CERT': (bool_int, 'Advanced', 1), 'VIDEO_LOGGING_ENABLE': (int, 'Monitoring', 1), 'XBMC_ENABLED': (int, 'XBMC', 0), diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 8d79489e..7b5896bb 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -774,7 +774,8 @@ class WebInterface(object): query = None config = { - "pms_identifier": plexpy.CONFIG.PMS_IDENTIFIER + "pms_identifier": plexpy.CONFIG.PMS_IDENTIFIER, + "update_library_ids": plexpy.CONFIG.UPDATE_LIBRARY_IDS } if source == 'history': @@ -1471,3 +1472,19 @@ class WebInterface(object): if servers: cherrypy.response.headers['Content-type'] = 'application/json' return servers + + @cherrypy.expose + def update_library_ids(self, **kwargs): + + logger.debug(u"Updating library_id's in database.") + data_factory = datafactory.DataFactory() + result = data_factory.update_library_ids() + + if result: + plexpy.CONFIG.UPDATE_LIBRARY_IDS = 0 + plexpy.CONFIG.write() + logger.debug(u"Updated all library_id's in database.") + return "Library ids updated." + else: + logger.debug(u"Unable to update library_id's in database.") + return "Unable to update library ids in database." \ No newline at end of file