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,9 +66,20 @@ class Database(object):
|
|||
|
||||
path = xbmc.translatePath(path).decode('utf-8')
|
||||
|
||||
if not xbmcvfs.exists(path) and not silent:
|
||||
if not silent:
|
||||
|
||||
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
|
||||
|
||||
def _discover_database(self, database):
|
||||
|
@ -76,21 +87,32 @@ class Database(object):
|
|||
''' Grab the first database encountered, by most recent.
|
||||
Will likely not work, but heck.
|
||||
'''
|
||||
databases = xbmc.translatePath("special://database/").decode('utf-8')
|
||||
types = {
|
||||
'video': "MyVideos",
|
||||
'music': "MyMusic",
|
||||
'texture': "Textures"
|
||||
}
|
||||
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):
|
||||
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'))
|
||||
modified_int = st.st_mtime()
|
||||
LOG.debug("Database detected: %s time: %s", file.decode('utf-8'), modified_int)
|
||||
|
||||
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" % file.decode('utf-8')).decode('utf-8')
|
||||
return xbmc.translatePath("special://database/%s" % modified['file'])
|
||||
|
||||
def _sql(self, file):
|
||||
|
||||
|
|
|
@ -128,8 +128,6 @@ class Library(threading.Thread):
|
|||
|
||||
LOG.info("Newly discovered database: %s", kodidb.path)
|
||||
settings('DiscoveredDatabase', kodidb.path)
|
||||
self.monitor.settings['enable_db_discovery'] = False
|
||||
settings('AskDiscoverDatabase.bool', False)
|
||||
|
||||
return False
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue