From 6db79723010e02b3d18164a7ddaef4503f415fb4 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Thu, 20 Oct 2016 01:47:42 -0500 Subject: [PATCH] Make sure emby tables exists before proceeding --- resources/lib/librarysync.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 455ccdfe..44dd4499 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -232,20 +232,6 @@ class LibrarySync(threading.Thread): # Add sources utils.sourcesXML() - embyconn = utils.kodiSQL('emby') - embycursor = embyconn.cursor() - # Create the tables for the emby database - # emby, view, version - embycursor.execute( - """CREATE TABLE IF NOT EXISTS emby( - emby_id TEXT UNIQUE, media_folder TEXT, emby_type TEXT, media_type TEXT, kodi_id INTEGER, - kodi_fileid INTEGER, kodi_pathid INTEGER, parent_id INTEGER, checksum INTEGER)""") - embycursor.execute( - """CREATE TABLE IF NOT EXISTS view( - view_id TEXT UNIQUE, view_name TEXT, media_type TEXT, kodi_tagid INTEGER)""") - embycursor.execute("CREATE TABLE IF NOT EXISTS version(idVersion TEXT)") - embyconn.commit() - # content sync: movies, tvshows, musicvideos, music kodiconn = utils.kodiSQL('video') kodicursor = kodiconn.cursor() @@ -854,6 +840,23 @@ class LibrarySync(threading.Thread): # Database out of date. return False + def _verify_emby_database(cls): + # Create the tables for the emby database + conn = utils.kodiSQL('emby') + cursor = conn.cursor() + # emby, view, version + cursor.execute( + """CREATE TABLE IF NOT EXISTS emby( + emby_id TEXT UNIQUE, media_folder TEXT, emby_type TEXT, media_type TEXT, + kodi_id INTEGER, kodi_fileid INTEGER, kodi_pathid INTEGER, parent_id INTEGER, + checksum INTEGER)""") + cursor.execute( + """CREATE TABLE IF NOT EXISTS view( + view_id TEXT UNIQUE, view_name TEXT, media_type TEXT, kodi_tagid INTEGER)""") + cursor.execute("CREATE TABLE IF NOT EXISTS version(idVersion TEXT)") + + conn.commit() + def run(self): try: @@ -885,6 +888,9 @@ class LibrarySync(threading.Thread): log.warn("---===### Starting LibrarySync ###===---") + # Verify database structure, otherwise create it. + self._verify_emby_database() + while not self.monitor.abortRequested(): # In the event the server goes offline