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])
|
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
|
Completely resets the Kodi databases 'video', 'texture' and 'music' (if
|
||||||
music sync is enabled)
|
music sync is enabled)
|
||||||
|
@ -1306,8 +1306,7 @@ def wipe_dbs():
|
||||||
LOG.warn('Wiping Kodi databases!')
|
LOG.warn('Wiping Kodi databases!')
|
||||||
query = "SELECT name FROM sqlite_master WHERE type = 'table'"
|
query = "SELECT name FROM sqlite_master WHERE type = 'table'"
|
||||||
kinds = ['video', 'texture']
|
kinds = ['video', 'texture']
|
||||||
if utils.settings('enableMusic') == 'true':
|
if music:
|
||||||
LOG.info('Also deleting music database')
|
|
||||||
kinds.append('music')
|
kinds.append('music')
|
||||||
for db in kinds:
|
for db in kinds:
|
||||||
with GetKodiDB(db) as kodi_db:
|
with GetKodiDB(db) as kodi_db:
|
||||||
|
|
|
@ -235,3 +235,11 @@ class Music(object):
|
||||||
self.cursor.execute('SELECT * FROM album WHERE artist_id = ?',
|
self.cursor.execute('SELECT * FROM album WHERE artist_id = ?',
|
||||||
(plex_id, ))
|
(plex_id, ))
|
||||||
return (self.entry_to_album(x) for x in self.cursor)
|
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
|
# Clean up the video nodes
|
||||||
delete_nodes()
|
delete_nodes()
|
||||||
from . import kodidb_functions
|
from . import kodidb_functions
|
||||||
kodidb_functions.wipe_dbs()
|
|
||||||
from . import plex_db
|
from . import plex_db
|
||||||
# First get the paths to all synced playlists
|
# First get the paths to all synced playlists
|
||||||
playlist_paths = []
|
playlist_paths = []
|
||||||
with plex_db.PlexDB() as plexdb:
|
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')
|
plexdb.cursor.execute('SELECT kodi_path FROM playlists')
|
||||||
for entry in plexdb.cursor:
|
for entry in plexdb.cursor:
|
||||||
playlist_paths.append(entry[0])
|
playlist_paths.append(entry[0])
|
||||||
|
kodidb_functions.wipe_dbs(music)
|
||||||
plex_db.wipe()
|
plex_db.wipe()
|
||||||
plex_db.initialize()
|
plex_db.initialize()
|
||||||
# Delete all synced playlists
|
# Delete all synced playlists
|
||||||
for path in playlist_paths:
|
for path in playlist_paths:
|
||||||
try:
|
try:
|
||||||
path_ops.remove(path)
|
path_ops.remove(path)
|
||||||
LOG.info('Removed playlist %s', path)
|
LOG.debug('Removed playlist %s', path)
|
||||||
except (OSError, IOError):
|
except (OSError, IOError):
|
||||||
LOG.warn('Could not remove playlist %s', path)
|
LOG.warn('Could not remove playlist %s', path)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue