Be smart when wiping Kodi DBs: only wipe music if necessary
This commit is contained in:
parent
20f26364b8
commit
a81fd527c1
3 changed files with 18 additions and 5 deletions
|
@ -1298,7 +1298,7 @@ def reset_cached_images():
|
|||
kodi_db.cursor.execute("DELETE FROM %s" % row[0])
|
||||
|
||||
|
||||
def wipe_dbs():
|
||||
def wipe_dbs(music=True):
|
||||
"""
|
||||
Completely resets the Kodi databases 'video', 'texture' and 'music' (if
|
||||
music sync is enabled)
|
||||
|
@ -1306,8 +1306,7 @@ def wipe_dbs():
|
|||
LOG.warn('Wiping Kodi databases!')
|
||||
query = "SELECT name FROM sqlite_master WHERE type = 'table'"
|
||||
kinds = ['video', 'texture']
|
||||
if utils.settings('enableMusic') == 'true':
|
||||
LOG.info('Also deleting music database')
|
||||
if music:
|
||||
kinds.append('music')
|
||||
for db in kinds:
|
||||
with GetKodiDB(db) as kodi_db:
|
||||
|
|
|
@ -235,3 +235,11 @@ class Music(object):
|
|||
self.cursor.execute('SELECT * FROM album WHERE artist_id = ?',
|
||||
(plex_id, ))
|
||||
return (self.entry_to_album(x) for x in self.cursor)
|
||||
|
||||
def songs_have_been_synced(self):
|
||||
"""
|
||||
Returns True if at least one song has been synced - indicating that
|
||||
Plex Music sync has been active at some point
|
||||
"""
|
||||
self.cursor.execute('SELECT plex_id FROM track LIMIT 1')
|
||||
return self.cursor.fetchone() is not None
|
||||
|
|
|
@ -523,21 +523,27 @@ def wipe_database():
|
|||
# Clean up the video nodes
|
||||
delete_nodes()
|
||||
from . import kodidb_functions
|
||||
kodidb_functions.wipe_dbs()
|
||||
from . import plex_db
|
||||
# First get the paths to all synced playlists
|
||||
playlist_paths = []
|
||||
with plex_db.PlexDB() as plexdb:
|
||||
if plexdb.songs_have_been_synced():
|
||||
LOG.info('Detected that music has also been synced - wiping music')
|
||||
music = True
|
||||
else:
|
||||
LOG.info('No music has been synced in the past - not wiping')
|
||||
music = False
|
||||
plexdb.cursor.execute('SELECT kodi_path FROM playlists')
|
||||
for entry in plexdb.cursor:
|
||||
playlist_paths.append(entry[0])
|
||||
kodidb_functions.wipe_dbs(music)
|
||||
plex_db.wipe()
|
||||
plex_db.initialize()
|
||||
# Delete all synced playlists
|
||||
for path in playlist_paths:
|
||||
try:
|
||||
path_ops.remove(path)
|
||||
LOG.info('Removed playlist %s', path)
|
||||
LOG.debug('Removed playlist %s', path)
|
||||
except (OSError, IOError):
|
||||
LOG.warn('Could not remove playlist %s', path)
|
||||
|
||||
|
|
Loading…
Reference in a new issue