From 27e92afe02cae33f63f93a6123f49ab3bce90b8b Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 7 Oct 2018 17:47:32 +0200 Subject: [PATCH] Make sure we retain a dummy first music artist entry - Hopefully fixes #527 --- resources/lib/kodidb_functions.py | 30 ++++++++++++++++++++++-------- resources/lib/librarysync.py | 6 +++++- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/resources/lib/kodidb_functions.py b/resources/lib/kodidb_functions.py index c5680cd3..c9194f3a 100644 --- a/resources/lib/kodidb_functions.py +++ b/resources/lib/kodidb_functions.py @@ -100,6 +100,22 @@ class KodiDBMethods(object): 1, 0)) + def setup_music_db_dummy_entries(self): + """ + Kodi Krypton Krypton has some dummy first entries that we might've + deleted + idArtist: 1 strArtist: [Missing Tag] + strMusicBrainzArtistID: Artist Tag Missing + """ + query = ''' + INSERT OR REPLACE INTO artist( + idArtist, strArtist, strMusicBrainzArtistID) + VALUES (?, ?, ?) + ''' + self.cursor.execute(query, (1, + '[Missing Tag]', + 'Artist Tag Missing')) + def parent_path_id(self, path): """ Video DB: Adds all subdirectories to path table while setting a "trail" @@ -292,11 +308,13 @@ class KodiDBMethods(object): (path_id,)) def _modify_link_and_table(self, kodi_id, kodi_type, entries, link_table, - table, key): + table, key, first_id=None): + first_id = first_id if first_id is not None else 1 query = ''' SELECT %s FROM %s WHERE name = ? COLLATE NOCASE LIMIT 1 ''' % (key, table) - query_id = 'SELECT COALESCE(MAX(%s), 0) FROM %s' % (key, table) + query_id = ('SELECT COALESCE(MAX(%s), %s) FROM %s' + % (key, first_id - 1, table)) query_new = ('INSERT INTO %s(%s, name) values(?, ?)' % (table, key)) entry_ids = [] @@ -906,12 +924,8 @@ class KodiDBMethods(object): except TypeError: # Krypton has a dummy first entry idArtist: 1 strArtist: # [Missing Tag] strMusicBrainzArtistID: Artist Tag Missing - if v.KODIVERSION >= 17: - self.cursor.execute( - "SELECT COALESCE(MAX(idArtist),1) FROM artist") - else: - self.cursor.execute( - "SELECT COALESCE(MAX(idArtist),0) FROM artist") + self.cursor.execute( + "SELECT COALESCE(MAX(idArtist),1) FROM artist") artistid = self.cursor.fetchone()[0] + 1 query = ''' INSERT INTO artist(idArtist, strArtist, diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 34d8c463..bfc678ac 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -1543,9 +1543,13 @@ class LibrarySync(Thread): LOG.info("Db version: %s", utils.settings('dbCreatedWithVersion')) LOG.info('Refreshing video nodes and playlists now') - # Setup the paths for addon-paths (even when using direct paths) with kodidb.GetKodiDB('video') as kodi_db: + # Setup the paths for addon-paths (even when using direct paths) kodi_db.setup_path_table() + with kodidb.GetKodiDB('music') as kodi_db: + # Hack for a dummy genre entry - even when we're not using + # Plex Music + kodi_db.setup_music_db_dummy_entries() utils.window('plex_dbScan', clear=True) state.DB_SCAN = False playlist_monitor = None