Prepare DB for selective Plex library sync

This commit is contained in:
tomkat83 2017-02-01 10:41:44 +01:00
parent 3871af77e6
commit 16e6fc5ca4
2 changed files with 24 additions and 12 deletions

View file

@ -552,7 +552,8 @@ class LibrarySync(Thread):
view_id TEXT UNIQUE, view_id TEXT UNIQUE,
view_name TEXT, view_name TEXT,
kodi_type TEXT, kodi_type TEXT,
kodi_tagid INTEGER) kodi_tagid INTEGER,
sync_to_kodi INTEGER)
''') ''')
plex_db.plexcursor.execute(''' plex_db.plexcursor.execute('''
CREATE TABLE IF NOT EXISTS version(idVersion TEXT) CREATE TABLE IF NOT EXISTS version(idVersion TEXT)

View file

@ -51,21 +51,26 @@ class Plex_DB_Functions():
def getAllViewInfo(self): def getAllViewInfo(self):
""" """
Returns a list of dicts: Returns a list of dicts for all Plex libraries:
{'id': view_id, 'name': view_name, 'itemtype': kodi_type} {
'id': view_id,
'name': view_name,
'itemtype': kodi_type
'kodi_tagid'
'sync_to_kodi'
}
""" """
plexcursor = self.plexcursor plexcursor = self.plexcursor
views = [] views = []
query = ''' query = '''SELECT * FROM view'''
SELECT view_id, view_name, kodi_type
FROM view
'''
plexcursor.execute(query) plexcursor.execute(query)
rows = plexcursor.fetchall() rows = plexcursor.fetchall()
for row in rows: for row in rows:
views.append({'id': row[0], views.append({'id': row[0],
'name': row[1], 'name': row[1],
'itemtype': row[2]}) 'itemtype': row[2],
'kodi_tagid': row[3],
'sync_to_kodi': row[4]})
return views return views
def getView_byId(self, view_id): def getView_byId(self, view_id):
@ -118,17 +123,23 @@ class Plex_DB_Functions():
view = None view = None
return view return view
def addView(self, view_id, view_name, kodi_type, kodi_tagid): def addView(self, view_id, view_name, kodi_type, kodi_tagid, sync=True):
""" """
Appends an entry to the view table Appends an entry to the view table
sync=False: Plex library won't be synced to Kodi
""" """
query = ''' query = '''
INSERT INTO view( INSERT INTO view(
view_id, view_name, kodi_type, kodi_tagid) view_id, view_name, kodi_type, kodi_tagid, sync_to_kodi)
VALUES (?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
''' '''
self.plexcursor.execute(query, self.plexcursor.execute(query,
(view_id, view_name, kodi_type, kodi_tagid)) (view_id,
view_name,
kodi_type,
kodi_tagid,
1 if sync is True else 0))
def updateView(self, view_name, kodi_tagid, view_id): def updateView(self, view_name, kodi_tagid, view_id):
""" """