From f31046bed18b7c3a79696c90c808f71c7c9bf836 Mon Sep 17 00:00:00 2001 From: croneter Date: Wed, 28 Feb 2018 18:48:39 +0100 Subject: [PATCH] Greatly speed up switch of PMS --- .../resource.language.en_gb/strings.po | 4 - resources/lib/entrypoint.py | 8 +- resources/lib/utils.py | 97 ++++++++++--------- 3 files changed, 53 insertions(+), 56 deletions(-) diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index b1a9193b..939dfbcd 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -1851,10 +1851,6 @@ msgctxt "#39601" msgid "Could not stop the database from running. Please try again later." msgstr "" -msgctxt "#39602" -msgid "Remove all cached artwork? (recommended!)" -msgstr "" - msgctxt "#39603" msgid "Reset all PlexKodiConnect Addon settings? (this is usually NOT recommended and unnecessary!)" msgstr "" diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index dd228719..6bb54d2d 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -53,11 +53,9 @@ def chooseServer(): if not __LogOut(): return - from utils import delete_playlists, delete_nodes - # First remove playlists - delete_playlists() - # Remove video nodes - delete_nodes() + from utils import wipe_database + # Wipe Kodi and Plex database as well as playlists and video nodes + wipe_database() # Log in again __LogIn() diff --git a/resources/lib/utils.py b/resources/lib/utils.py index d73acf09..3c3ac8b6 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -368,34 +368,14 @@ def create_actor_db_index(): conn.close() -def reset(): +def wipe_database(): """ - User navigated to the PKC settings, Advanced, and wants to reset the Kodi - database and possibly PKC entirely + Deletes all Plex playlists as well as video nodes, then clears Kodi as well + as Plex databases completely. + Will also delete all cached artwork. """ - # Are you sure you want to reset your local Kodi database? - if not dialog('yesno', - heading='{plex} %s ' % language(30132), - line1=language(39600)): - return - - # first stop any db sync - plex_command('STOP_SYNC', 'True') - count = 10 - while window('plex_dbScan') == "true": - LOG.debug("Sync is running, will retry: %s...", count) - count -= 1 - if count == 0: - # Could not stop the database from running. Please try again later. - dialog('ok', - heading='{plex} %s' % language(30132), - line1=language(39601)) - return - xbmc.sleep(1000) - # Clean up the playlists delete_playlists() - # Clean up the video nodes delete_nodes() @@ -435,36 +415,59 @@ def reset(): tablename = row[0] if tablename != "version": cursor.execute("DELETE FROM %s" % tablename) - cursor.execute('DROP table IF EXISTS plex') - cursor.execute('DROP table IF EXISTS view') connection.commit() cursor.close() - # Remove all cached artwork? (recommended!) - if dialog('yesno', - heading='{plex} %s ' % language(30132), - line1=language(39602)): - LOG.info("Resetting all cached artwork.") - # Remove all existing textures first - path = xbmc.translatePath("special://thumbnails/") - if exists(path): - rmtree(try_decode(path), ignore_errors=True) - # remove all existing data from texture DB - connection = kodi_sql('texture') - cursor = connection.cursor() - query = 'SELECT tbl_name FROM sqlite_master WHERE type=?' - cursor.execute(query, ("table", )) - rows = cursor.fetchall() - for row in rows: - table_name = row[0] - if table_name != "version": - cursor.execute("DELETE FROM %s" % table_name) - connection.commit() - cursor.close() + LOG.info("Resetting all cached artwork.") + # Remove all existing textures first + path = xbmc.translatePath("special://thumbnails/") + if exists(path): + rmtree(try_decode(path), ignore_errors=True) + # remove all existing data from texture DB + connection = kodi_sql('texture') + cursor = connection.cursor() + query = 'SELECT tbl_name FROM sqlite_master WHERE type=?' + cursor.execute(query, ("table", )) + rows = cursor.fetchall() + for row in rows: + table_name = row[0] + if table_name != "version": + cursor.execute("DELETE FROM %s" % table_name) + connection.commit() + cursor.close() # reset the install run flag settings('SyncInstallRunDone', value="false") + +def reset(): + """ + User navigated to the PKC settings, Advanced, and wants to reset the Kodi + database and possibly PKC entirely + """ + # Are you sure you want to reset your local Kodi database? + if not dialog('yesno', + heading='{plex} %s ' % language(30132), + line1=language(39600)): + return + + # first stop any db sync + plex_command('STOP_SYNC', 'True') + count = 10 + while window('plex_dbScan') == "true": + LOG.debug("Sync is running, will retry: %s...", count) + count -= 1 + if count == 0: + # Could not stop the database from running. Please try again later. + dialog('ok', + heading='{plex} %s' % language(30132), + line1=language(39601)) + return + xbmc.sleep(1000) + + # Wipe everything + wipe_database() + # Reset all PlexKodiConnect Addon settings? (this is usually NOT # recommended and unnecessary!) if dialog('yesno',