From e16cbcc87cdc115f8ece51e03868aeff2a202b83 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Fri, 8 May 2015 00:46:41 +0200 Subject: [PATCH] corrected check for music artists and also reset music db at full reset --- resources/lib/Utils.py | 21 ++++++++++++++++++--- resources/lib/WriteKodiMusicDB.py | 10 +++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/resources/lib/Utils.py b/resources/lib/Utils.py index 7d3daba5..a466c237 100644 --- a/resources/lib/Utils.py +++ b/resources/lib/Utils.py @@ -203,9 +203,9 @@ def reset(): return xbmc.sleep(1000) - # delete db table data - print "Doing DB Reset" - connection = KodiSQL() + # delete video db table data + print "Doing Video DB Reset" + connection = KodiSQL("video") cursor = connection.cursor( ) cursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"') rows = cursor.fetchall() @@ -216,6 +216,21 @@ def reset(): connection.commit() cursor.close() + if addonSettings.getSetting("enableMusicSync") == "true": + # delete video db table data + print "Doing Music DB Reset" + connection = KodiSQL("music") + cursor = connection.cursor( ) + cursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"') + rows = cursor.fetchall() + for row in rows: + tableName = row[0] + if(tableName != "version"): + cursor.execute("DELETE FROM " + tableName) + connection.commit() + cursor.close() + + # reset the install run flag WINDOW.setProperty("SyncInstallRunDone", "false") diff --git a/resources/lib/WriteKodiMusicDB.py b/resources/lib/WriteKodiMusicDB.py index 659ac9f7..3b49a9ff 100644 --- a/resources/lib/WriteKodiMusicDB.py +++ b/resources/lib/WriteKodiMusicDB.py @@ -89,13 +89,17 @@ class WriteKodiMusicDB(): if MBitem.get("DateCreated"): dateadded = MBitem["DateCreated"].split('.')[0].replace('T', " ") - #convenience/safety check: does the artist already exist? + #safety check 1: does the artist already exist? cursor.execute("SELECT idArtist FROM artist WHERE strArtist = ?",(name,)) result = cursor.fetchone() if result != None: artistid = result[0] - else: - artistid = None + + #safety check 2: does the musicbrainzartistId already exist? + cursor.execute("SELECT idArtist FROM artist WHERE strMusicBrainzArtistID = ?",(musicBrainsId,)) + result = cursor.fetchone() + if result != None: + artistid = result[0] ##### ADD THE ARTIST ############ if artistid == None: