mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 10:16:11 +00:00
Fix database discovery
Add table verification + date modified verification
This commit is contained in:
parent
7da421d970
commit
ddc6b01055
2 changed files with 29 additions and 9 deletions
|
@ -66,8 +66,19 @@ class Database(object):
|
||||||
|
|
||||||
path = xbmc.translatePath(path).decode('utf-8')
|
path = xbmc.translatePath(path).decode('utf-8')
|
||||||
|
|
||||||
if not xbmcvfs.exists(path) and not silent:
|
if not silent:
|
||||||
raise Exception("Database: %s missing" % path)
|
|
||||||
|
if not xbmcvfs.exists(path):
|
||||||
|
raise Exception("Database: %s missing" % path)
|
||||||
|
|
||||||
|
conn = sqlite3.connect(path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
|
||||||
|
tables = cursor.fetchall()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
if not len(tables):
|
||||||
|
raise Exception("Database: %s malformed?" % path)
|
||||||
|
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
@ -76,21 +87,32 @@ class Database(object):
|
||||||
''' Grab the first database encountered, by most recent.
|
''' Grab the first database encountered, by most recent.
|
||||||
Will likely not work, but heck.
|
Will likely not work, but heck.
|
||||||
'''
|
'''
|
||||||
|
databases = xbmc.translatePath("special://database/").decode('utf-8')
|
||||||
types = {
|
types = {
|
||||||
'video': "MyVideos",
|
'video': "MyVideos",
|
||||||
'music': "MyMusic",
|
'music': "MyMusic",
|
||||||
'texture': "Textures"
|
'texture': "Textures"
|
||||||
}
|
}
|
||||||
database = types[database]
|
database = types[database]
|
||||||
dirs, files = xbmcvfs.listdir(xbmc.translatePath("special://database/").decode('utf-8'))
|
dirs, files = xbmcvfs.listdir(databases)
|
||||||
|
modified = {'file': None, 'time': 0}
|
||||||
|
|
||||||
for file in reversed(files):
|
for file in reversed(files):
|
||||||
if file.startswith(database) and not file.endswith('-wal') and not file.endswith('-shm'):
|
if file.startswith(database) and not file.endswith('-wal') and not file.endswith('-shm'):
|
||||||
|
|
||||||
LOG.info("Found database: %s", file)
|
st = xbmcvfs.Stat(databases + file.decode('utf-8'))
|
||||||
self.discovered = True
|
modified_int = st.st_mtime()
|
||||||
|
LOG.debug("Database detected: %s time: %s", file.decode('utf-8'), modified_int)
|
||||||
return xbmc.translatePath("special://database/%s" % file.decode('utf-8')).decode('utf-8')
|
|
||||||
|
if modified_int > modified['time']:
|
||||||
|
|
||||||
|
modified['time'] = modified_int
|
||||||
|
modified['file'] = file.decode('utf-8')
|
||||||
|
|
||||||
|
LOG.info("Loading discovered database: %s", modified)
|
||||||
|
self.discovered = True
|
||||||
|
|
||||||
|
return xbmc.translatePath("special://database/%s" % modified['file'])
|
||||||
|
|
||||||
def _sql(self, file):
|
def _sql(self, file):
|
||||||
|
|
||||||
|
|
|
@ -128,8 +128,6 @@ class Library(threading.Thread):
|
||||||
|
|
||||||
LOG.info("Newly discovered database: %s", kodidb.path)
|
LOG.info("Newly discovered database: %s", kodidb.path)
|
||||||
settings('DiscoveredDatabase', kodidb.path)
|
settings('DiscoveredDatabase', kodidb.path)
|
||||||
self.monitor.settings['enable_db_discovery'] = False
|
|
||||||
settings('AskDiscoverDatabase.bool', False)
|
|
||||||
|
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue