Removes blank popup window from db reset logic

Cleans up the database reset logic to remove a blank popup window. Some
other minor cleanup is included for readability.
This commit is contained in:
owner 2019-08-24 09:16:39 -05:00
commit 0108ed15e2
13 changed files with 102 additions and 109 deletions

View file

@ -538,6 +538,10 @@ msgctxt "#33074"
msgid "Are you sure you want to reset your local Kodi database?" msgid "Are you sure you want to reset your local Kodi database?"
msgstr "Möchtest du wirklich deine lokale Kodi Datenbank zurücksetzen?" msgstr "Möchtest du wirklich deine lokale Kodi Datenbank zurücksetzen?"
msgctxt "#33085"
msgid "Unable to reset Kodi database while sync is running"
msgstr "Kodi-Datenbank kann während der Synchronisierung nicht zurückgesetzt werden"
msgctxt "#33086" msgctxt "#33086"
msgid "Remove all cached artwork?" msgid "Remove all cached artwork?"
msgstr "Alle zwischengespeicherten Bilder entfernen?" msgstr "Alle zwischengespeicherten Bilder entfernen?"

View file

@ -514,6 +514,10 @@ msgctxt "#33074"
msgid "Are you sure you want to reset your local Kodi database?" msgid "Are you sure you want to reset your local Kodi database?"
msgstr "" msgstr ""
msgctxt "#33085"
msgid "Unable to reset Kodi database while sync is running"
msgstr ""
msgctxt "#33086" msgctxt "#33086"
msgid "Remove all cached artwork?" msgid "Remove all cached artwork?"
msgstr "" msgstr ""

View file

@ -538,6 +538,10 @@ msgid "Are you sure you want to reset your local Kodi database?"
msgstr "" msgstr ""
"Êtes-vous sûr de vouloir réinitialiser votre base de données Kodi locale ?" "Êtes-vous sûr de vouloir réinitialiser votre base de données Kodi locale ?"
msgctxt "#33085"
msgid "Unable to reset Kodi database while sync is running"
msgstr "Impossible de réinitialiser la base de données Kodi lorsque la synchronisation est en cours d'exécution"
msgctxt "#33086" msgctxt "#33086"
msgid "Remove all cached artwork?" msgid "Remove all cached artwork?"
msgstr "Supprimer toutes les illustrations en cache ?" msgstr "Supprimer toutes les illustrations en cache ?"

View file

@ -536,6 +536,10 @@ msgctxt "#33074"
msgid "Are you sure you want to reset your local Kodi database?" msgid "Are you sure you want to reset your local Kodi database?"
msgstr "Sei sicuro di voler resettare il tuo database Kodi locale?" msgstr "Sei sicuro di voler resettare il tuo database Kodi locale?"
msgctxt "#33085"
msgid "Unable to reset Kodi database while sync is running"
msgstr "Impossibile ripristinare il database Kodi mentre la sincronizzazione è in esecuzione"
msgctxt "#33086" msgctxt "#33086"
msgid "Remove all cached artwork?" msgid "Remove all cached artwork?"
msgstr "Rimuove tutte le artwork dalla cache?" msgstr "Rimuove tutte le artwork dalla cache?"

View file

@ -534,6 +534,10 @@ msgctxt "#33074"
msgid "Are you sure you want to reset your local Kodi database?" msgid "Are you sure you want to reset your local Kodi database?"
msgstr "Weet u zeker dat u de lokale Kodi databank resetten wilt?" msgstr "Weet u zeker dat u de lokale Kodi databank resetten wilt?"
msgctxt "#33085"
msgid "Unable to reset Kodi database while sync is running"
msgstr "Kan Kodi-database niet opnieuw instellen terwijl synchronisatie wordt uitgevoerd"
msgctxt "#33086" msgctxt "#33086"
msgid "Remove all cached artwork?" msgid "Remove all cached artwork?"
msgstr "Cached artwork verwijderen?" msgstr "Cached artwork verwijderen?"

View file

@ -538,6 +538,10 @@ msgctxt "#33074"
msgid "Are you sure you want to reset your local Kodi database?" msgid "Are you sure you want to reset your local Kodi database?"
msgstr "Na pewno chcesz zresetować lokalną bazę Kodi?" msgstr "Na pewno chcesz zresetować lokalną bazę Kodi?"
msgctxt "#33085"
msgid "Unable to reset Kodi database while sync is running"
msgstr "Nie można zresetować bazy danych Kodi podczas synchronizacji"
msgctxt "#33086" msgctxt "#33086"
msgid "Remove all cached artwork?" msgid "Remove all cached artwork?"
msgstr "Usunąć pobrane grafiki?" msgstr "Usunąć pobrane grafiki?"

View file

@ -16,6 +16,7 @@ from helper.utils import create_id
################################################################################################## ##################################################################################################
LOG = logging.getLogger("JELLYFIN."+__name__) LOG = logging.getLogger("JELLYFIN."+__name__)
ADDON_DATA = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/").decode('utf-8')
################################################################################################## ##################################################################################################
@ -82,12 +83,7 @@ def get_device_id(reset=False):
if client_id: if client_id:
return client_id return client_id
directory = xbmc.translatePath('special://profile/addon_data/plugin.video.jellyfin/').decode('utf-8') jellyfin_guid = os.path.join(ADDON_DATA, "jellyfin_guid")
if not xbmcvfs.exists(directory):
xbmcvfs.mkdir(directory)
jellyfin_guid = os.path.join(directory, "jellyfin_guid")
file_guid = xbmcvfs.File(jellyfin_guid) file_guid = xbmcvfs.File(jellyfin_guid)
client_id = file_guid.read() client_id = file_guid.read()

View file

@ -18,6 +18,7 @@ from objects import obj
################################################################################################# #################################################################################################
LOG = logging.getLogger("JELLYFIN."+__name__) LOG = logging.getLogger("JELLYFIN."+__name__)
ADDON_DATA = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/").decode('utf-8')
################################################################################################# #################################################################################################
@ -211,50 +212,37 @@ def reset():
from views import Views from views import Views
views = Views() views = Views()
if not dialog("yesno", heading="{jellyfin}", line1=_(33074)): if window('jellyfin_sync.bool'):
return dialog("ok", heading="{jellyfin}", line1=_(33085))
else:
if dialog("yesno", heading="{jellyfin}", line1=_(33074)):
reset_kodi()
reset_jellyfin()
views.delete_playlists()
views.delete_nodes()
LOG.info("[ reset kodi database ]")
window('jellyfin_should_stop.bool', True) if dialog("yesno", heading="{jellyfin}", line1=_(33086)):
count = 10 reset_artwork()
while window('jellyfin_sync.bool'): if dialog("yesno", heading="{jellyfin}", line1=_(33087)):
xbmcvfs.delete(os.path.join(ADDON_DATA, "settings.xml"))
xbmcvfs.delete(os.path.join(ADDON_DATA, "data.json"))
LOG.info("[ reset settings ]")
LOG.info("Sync is running...") if xbmcvfs.exists(os.path.join(ADDON_DATA, "sync.json")):
count -= 1 xbmcvfs.delete(os.path.join(ADDON_DATA, "sync.json"))
if not count: settings('enableMusic.bool', False)
dialog("ok", heading="{jellyfin}", line1=_(33085)) settings('MinimumSetup', "")
settings('MusicRescan.bool', False)
settings('SyncInstallRunDone.bool', False)
dialog("ok", heading="{jellyfin}", line1=_(33088))
xbmc.executebuiltin('RestartApp')
else:
pass
return return
if xbmc.Monitor().waitForAbort(1):
return
reset_kodi()
reset_jellyfin()
views.delete_playlists()
views.delete_nodes()
if dialog("yesno", heading="{jellyfin}", line1=_(33086)):
reset_artwork()
addon_data = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/").decode('utf-8')
if dialog("yesno", heading="{jellyfin}", line1=_(33087)):
xbmcvfs.delete(os.path.join(addon_data, "settings.xml"))
xbmcvfs.delete(os.path.join(addon_data, "data.json"))
LOG.info("[ reset settings ]")
if xbmcvfs.exists(os.path.join(addon_data, "sync.json")):
xbmcvfs.delete(os.path.join(addon_data, "sync.json"))
settings('enableMusic.bool', False)
settings('MinimumSetup', "")
settings('MusicRescan.bool', False)
settings('SyncInstallRunDone.bool', False)
dialog("ok", heading="{jellyfin}", line1=_(33088))
xbmc.executebuiltin('RestartApp')
def reset_kodi(): def reset_kodi():
@ -278,7 +266,7 @@ def reset_kodi():
if name != 'version': if name != 'version':
musicdb.cursor.execute("DELETE FROM " + name) musicdb.cursor.execute("DELETE FROM " + name)
LOG.warn("[ reset kodi ]") LOG.info("[ reset kodi ]")
def reset_jellyfin(): def reset_jellyfin():
@ -295,7 +283,7 @@ def reset_jellyfin():
jellyfindb.cursor.execute("DROP table IF EXISTS view") jellyfindb.cursor.execute("DROP table IF EXISTS view")
jellyfindb.cursor.execute("DROP table IF EXISTS version") jellyfindb.cursor.execute("DROP table IF EXISTS version")
LOG.warn("[ reset jellyfin ]") LOG.info("[ reset jellyfin ]")
def reset_artwork(): def reset_artwork():
@ -322,17 +310,12 @@ def reset_artwork():
if name != 'version': if name != 'version':
texdb.cursor.execute("DELETE FROM " + name) texdb.cursor.execute("DELETE FROM " + name)
LOG.warn("[ reset artwork ]") LOG.info("[ reset artwork ]")
def get_sync(): def get_sync():
path = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/").decode('utf-8')
if not xbmcvfs.exists(path):
xbmcvfs.mkdirs(path)
try: try:
with open(os.path.join(path, 'sync.json')) as infile: with open(os.path.join(ADDON_DATA, 'sync.json')) as infile:
sync = json.load(infile) sync = json.load(infile)
except Exception: except Exception:
sync = {} sync = {}
@ -346,36 +329,25 @@ def get_sync():
def save_sync(sync): def save_sync(sync):
path = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/").decode('utf-8')
if not xbmcvfs.exists(path):
xbmcvfs.mkdirs(path)
sync['Date'] = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ') sync['Date'] = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
with open(os.path.join(path, 'sync.json'), 'w') as outfile: with open(os.path.join(ADDON_DATA, 'sync.json'), 'w') as outfile:
json.dump(sync, outfile, sort_keys=True, indent=4, ensure_ascii=False) json.dump(sync, outfile, sort_keys=True, indent=4, ensure_ascii=False)
def get_credentials(): def get_credentials():
path = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/").decode('utf-8')
if not xbmcvfs.exists(path):
xbmcvfs.mkdirs(path)
try: try:
with open(os.path.join(path, 'data.json')) as infile: if os.path.exists(os.path.join(ADDON_DATA, 'data.json')):
pass
elif os.path.exists(os.path.join(ADDON_DATA, 'data.txt')):
os.rename(os.path.join(ADDON_DATA, 'data.txt'), os.path.join(ADDON_DATA, 'data.json'))
else:
open(os.path.join(ADDON_DATA, 'data.json'), 'a')
with open(os.path.join(ADDON_DATA, 'data.json')) as infile:
credentials = json.load(infile) credentials = json.load(infile)
except Exception: except Exception:
credentials = {}
try:
with open(os.path.join(path, 'data.txt')) as infile:
credentials = json.load(infile)
save_credentials(credentials)
xbmcvfs.delete(os.path.join(path, 'data.txt'))
except Exception:
credentials = {}
credentials['Servers'] = credentials.get('Servers', []) credentials['Servers'] = credentials.get('Servers', [])
@ -383,12 +355,8 @@ def get_credentials():
def save_credentials(credentials): def save_credentials(credentials):
credentials = credentials or {} credentials = credentials or {}
path = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/").decode('utf-8')
if not xbmcvfs.exists(path): with open(os.path.join(ADDON_DATA, 'data.json'), 'w') as outfile:
xbmcvfs.mkdirs(path)
with open(os.path.join(path, 'data.json'), 'w') as outfile:
json.dump(credentials, outfile, sort_keys=True, indent=4, ensure_ascii=False) json.dump(credentials, outfile, sort_keys=True, indent=4, ensure_ascii=False)
def get_item(kodi_id, media): def get_item(kodi_id, media):

View file

@ -22,7 +22,7 @@ from jellyfin import Jellyfin
################################################################################################## ##################################################################################################
LOG = logging.getLogger("JELLYFIN."+__name__) LOG = logging.getLogger("JELLYFIN." + __name__)
LIMIT = min(int(settings('limitIndex') or 50), 50) LIMIT = min(int(settings('limitIndex') or 50), 50)
DTHREADS = int(settings('limitThreads') or 3) DTHREADS = int(settings('limitThreads') or 3)
MEDIA = { MEDIA = {
@ -96,7 +96,7 @@ class Library(threading.Thread):
def run(self): def run(self):
LOG.warn("--->[ library ]") LOG.info("--->[ library ]")
if not self.startup(): if not self.startup():
self.stop_client() self.stop_client()
@ -117,7 +117,7 @@ class Library(threading.Thread):
if self.monitor.waitForAbort(2): if self.monitor.waitForAbort(2):
break break
LOG.warn("---<[ library ]") LOG.info("---<[ library ]")
def test_databases(self): def test_databases(self):

View file

@ -22,7 +22,7 @@ from webservice import WebService
################################################################################################# #################################################################################################
LOG = logging.getLogger("JELLYFIN."+__name__) LOG = logging.getLogger("JELLYFIN." + __name__)
################################################################################################# #################################################################################################
@ -449,7 +449,7 @@ class Listener(threading.Thread):
''' Detect the resume dialog for widgets. ''' Detect the resume dialog for widgets.
Detect external players. Detect external players.
''' '''
LOG.warn("--->[ listener ]") LOG.info("--->[ listener ]")
while not self.stop_thread: while not self.stop_thread:
special_listener() special_listener()

View file

@ -15,7 +15,7 @@ from jellyfin import Jellyfin
################################################################################################# #################################################################################################
LOG = logging.getLogger("JELLYFIN."+__name__) LOG = logging.getLogger("JELLYFIN." + __name__)
################################################################################################# #################################################################################################

View file

@ -10,7 +10,7 @@ from helper import _, settings, dialog, JSONRPC, compare_version
################################################################################################# #################################################################################################
LOG = logging.getLogger("JELLYFIN."+__name__) LOG = logging.getLogger("JELLYFIN." + __name__)
################################################################################################# #################################################################################################

View file

@ -9,6 +9,7 @@ import sys
import xbmc import xbmc
import xbmcaddon import xbmcaddon
import xbmcvfs
################################################################################################# #################################################################################################
@ -27,6 +28,7 @@ from helper import settings
################################################################################################# #################################################################################################
LOG = logging.getLogger("JELLYFIN." + __name__) LOG = logging.getLogger("JELLYFIN." + __name__)
ADDON_DATA = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/").decode('utf-8')
DELAY = int(settings('startupDelay') if settings('SyncInstallRunDone.bool') else 4 or 0) DELAY = int(settings('startupDelay') if settings('SyncInstallRunDone.bool') else 4 or 0)
################################################################################################# #################################################################################################
@ -71,26 +73,29 @@ if __name__ == "__main__":
LOG.info("-->[ service ]") LOG.info("-->[ service ]")
LOG.info("Delay startup by %s seconds.", DELAY) LOG.info("Delay startup by %s seconds.", DELAY)
if not xbmcvfs.exists(ADDON_DATA):
xbmcvfs.mkdirs(ADDON_DATA)
while True: while True:
if not settings('enableAddon.bool'): if settings('enableAddon.bool'):
LOG.warn("Jellyfin for Kodi is not enabled.") try:
session = ServiceManager()
session.start()
session.join() # Block until the thread exits.
if 'RestartService' in session.exception:
continue
except Exception as error:
''' Issue initializing the service.
'''
LOG.exception(error)
break break
else:
try: LOG.warn("Jellyfin for Kodi is not enabled.")
session = ServiceManager() break
session.start()
session.join() # Block until the thread exits.
if 'RestartService' in session.exception:
continue
except Exception as error:
''' Issue initializing the service.
'''
LOG.exception(error)
break
LOG.info("--<[ service ]") LOG.info("--<[ service ]")