Separate function to wipe all synched Plex playlists
This commit is contained in:
parent
92a7fa7c7a
commit
a83cf93150
2 changed files with 33 additions and 16 deletions
|
@ -311,12 +311,16 @@ def initialize():
|
|||
plexdb.cursor.execute(cmd)
|
||||
|
||||
|
||||
def wipe():
|
||||
def wipe(table=None):
|
||||
"""
|
||||
Completely resets the Plex database
|
||||
Completely resets the Plex database.
|
||||
If a table [unicode] name is provided, only that table will be dropped
|
||||
"""
|
||||
with PlexDBBase() as plexdb:
|
||||
plexdb.cursor.execute("SELECT name FROM sqlite_master WHERE type = 'table'")
|
||||
tables = [i[0] for i in plexdb.cursor.fetchall()]
|
||||
if table:
|
||||
tables = [table]
|
||||
else:
|
||||
plexdb.cursor.execute("SELECT name FROM sqlite_master WHERE type = 'table'")
|
||||
tables = [i[0] for i in plexdb.cursor.fetchall()]
|
||||
for table in tables:
|
||||
plexdb.cursor.execute('DROP table IF EXISTS %s' % table)
|
||||
|
|
|
@ -539,6 +539,29 @@ def create_kodi_db_indicees():
|
|||
conn.close()
|
||||
|
||||
|
||||
def wipe_synched_playlists():
|
||||
"""
|
||||
Deletes all synched playlist files on the Kodi side; resets the Plex table
|
||||
listing all synched Plex playlists
|
||||
"""
|
||||
from . import plex_db
|
||||
try:
|
||||
with plex_db.PlexDB() as plexdb:
|
||||
plexdb.cursor.execute('SELECT kodi_path FROM playlists')
|
||||
playlist_paths = [x[0] for x in plexdb.cursor]
|
||||
except OperationalError:
|
||||
# Plex DB completely empty yet
|
||||
playlist_paths = []
|
||||
for path in playlist_paths:
|
||||
try:
|
||||
path_ops.remove(path)
|
||||
LOG.info('Removed playlist %s', path)
|
||||
except (OSError, IOError):
|
||||
LOG.warn('Could not remove playlist %s', path)
|
||||
# Now wipe our database
|
||||
plex_db.wipe(table='playlists')
|
||||
|
||||
|
||||
def wipe_database(reboot=True):
|
||||
"""
|
||||
Deletes all Plex playlists as well as video nodes, then clears Kodi as well
|
||||
|
@ -550,8 +573,8 @@ def wipe_database(reboot=True):
|
|||
from . import kodi_db, plex_db
|
||||
# Clean up the playlists and video nodes
|
||||
delete_files()
|
||||
# First get the paths to all synced playlists
|
||||
playlist_paths = []
|
||||
# Wipe all synched playlists
|
||||
wipe_synched_playlists()
|
||||
try:
|
||||
with plex_db.PlexDB() as plexdb:
|
||||
if plexdb.songs_have_been_synced():
|
||||
|
@ -560,22 +583,12 @@ def wipe_database(reboot=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])
|
||||
except OperationalError:
|
||||
# Plex DB completely empty yet. Wipe existing Kodi music only if we
|
||||
# expect to sync Plex music
|
||||
music = settings('enableMusic') == 'true'
|
||||
kodi_db.wipe_dbs(music)
|
||||
plex_db.wipe()
|
||||
# Delete all synced playlists
|
||||
for path in playlist_paths:
|
||||
try:
|
||||
path_ops.remove(path)
|
||||
LOG.debug('Removed playlist %s', path)
|
||||
except (OSError, IOError):
|
||||
LOG.warn('Could not remove playlist %s', path)
|
||||
|
||||
LOG.info("Resetting all cached artwork.")
|
||||
# Remove all cached artwork
|
||||
|
|
Loading…
Reference in a new issue