Clean up code

This commit is contained in:
Croneter 2018-04-09 07:15:12 +02:00
parent a53bd0f89c
commit ec5dff4a8d

View file

@ -178,34 +178,15 @@ class Plex_DB_Functions():
None if not found None if not found
""" """
query = ''' query = '''
SELECT plex_id SELECT plex_id FROM plex WHERE kodi_fileid = ? AND kodi_type = ?
FROM plex LIMIT 1
WHERE kodi_fileid = ? AND kodi_type = ?
''' '''
self.plexcursor.execute(query, (kodi_fileid, kodi_type))
try: try:
self.plexcursor.execute(query, (kodi_fileid, kodi_type))
item = self.plexcursor.fetchone()[0] item = self.plexcursor.fetchone()[0]
return item except TypeError:
except: item = None
return None return item
def getMusicItem_byFileId(self, kodi_id, kodi_type):
"""
Returns the plex_id for kodi_id and kodi_type
None if not found
"""
query = '''
SELECT plex_id
FROM plex
WHERE kodi_id = ? AND kodi_type = ?
'''
try:
self.plexcursor.execute(query, (kodi_id, kodi_type))
item = self.plexcursor.fetchone()[0]
return item
except:
return None
def getItem_byId(self, plex_id): def getItem_byId(self, plex_id):
""" """
@ -232,7 +213,7 @@ class Plex_DB_Functions():
FROM plex FROM plex
WHERE plex_id LIKE ? WHERE plex_id LIKE ?
''' '''
self.plexcursor.execute(query, (plex_id+"%",)) self.plexcursor.execute(query, (plex_id + "%",))
return self.plexcursor.fetchall() return self.plexcursor.fetchall()
def getItem_byView(self, view_id): def getItem_byView(self, view_id):
@ -255,8 +236,7 @@ class Plex_DB_Functions():
query = ''' query = '''
SELECT plex_id, parent_id, plex_type SELECT plex_id, parent_id, plex_type
FROM plex FROM plex
WHERE kodi_id = ? WHERE kodi_id = ? AND kodi_type = ?
AND kodi_type = ?
''' '''
self.plexcursor.execute(query, (kodi_id, kodi_type,)) self.plexcursor.execute(query, (kodi_id, kodi_type,))
return self.plexcursor.fetchone() return self.plexcursor.fetchone()
@ -299,24 +279,6 @@ class Plex_DB_Functions():
self.plexcursor.execute(query, (plex_type,)) self.plexcursor.execute(query, (plex_type,))
return self.plexcursor.fetchall() return self.plexcursor.fetchall()
def getMediaType_byId(self, plex_id):
"""
Returns plex_type for plex_id
Or None if not found
"""
query = '''
SELECT plex_type
FROM plex
WHERE plex_id = ?
'''
self.plexcursor.execute(query, (plex_id,))
try:
itemtype = self.plexcursor.fetchone()[0]
except TypeError:
itemtype = None
return itemtype
def addReference(self, plex_id, plex_type, kodi_id, kodi_type, def addReference(self, plex_id, plex_type, kodi_id, kodi_type,
kodi_fileid=None, kodi_pathid=None, parent_id=None, kodi_fileid=None, kodi_pathid=None, parent_id=None,
checksum=None, view_id=None): checksum=None, view_id=None):
@ -376,13 +338,6 @@ class Plex_DB_Functions():
self.plexcursor.execute('DELETE FROM plex WHERE plex_id = ?', self.plexcursor.execute('DELETE FROM plex WHERE plex_id = ?',
(plex_id,)) (plex_id,))
def removeWildItem(self, plex_id):
"""
Removes all entries with plex_id with % added
"""
query = "DELETE FROM plex WHERE plex_id LIKE ?"
self.plexcursor.execute(query, (plex_id+"%",))
def itemsByType(self, plex_type): def itemsByType(self, plex_type):
""" """
Returns a list of dicts for plex_type: Returns a list of dicts for plex_type:
@ -413,7 +368,7 @@ class Plex_DB_Functions():
""" """
Sets the fanart_synced flag to 1 for plex_id Sets the fanart_synced flag to 1 for plex_id
""" """
query = '''UPDATE plex SET fanart_synced = 1 WHERE plex_id = ?''' query = 'UPDATE plex SET fanart_synced = 1 WHERE plex_id = ?'
self.plexcursor.execute(query, (plex_id,)) self.plexcursor.execute(query, (plex_id,))
def get_missing_fanart(self): def get_missing_fanart(self):