Fix PKC add-on setting user changes not saving

This commit is contained in:
Croneter 2018-05-30 07:53:30 +02:00
parent 7b4a3da023
commit 06f9f6a7a5
2 changed files with 20 additions and 16 deletions

View file

@ -9,7 +9,7 @@ from threading import Thread
from os import makedirs from os import makedirs
import requests import requests
from xbmc import sleep, translatePath import xbmc
from xbmcvfs import exists from xbmcvfs import exists
from utils import settings, language as lang, kodi_sql, try_encode, try_decode,\ from utils import settings, language as lang, kodi_sql, try_encode, try_decode,\
@ -64,16 +64,17 @@ class Image_Cache_Thread(Thread):
# Abort was requested while waiting. We should exit # Abort was requested while waiting. We should exit
LOG.info("---===### Stopped Image_Cache_Thread ###===---") LOG.info("---===### Stopped Image_Cache_Thread ###===---")
return return
sleep(1000) xbmc.sleep(1000)
try: try:
url = queue.get(block=False) url = queue.get(block=False)
except Empty: except Empty:
if not set_zero: if not set_zero and not xbmc.getCondVisibility(
'Window.IsVisible(DialogAddonSettings.xml)'):
# Avoid saving '0' all the time # Avoid saving '0' all the time
set_zero = True set_zero = True
settings('caching_artwork_count', value='0') settings('caching_artwork_count', value='0')
sleep(1000) xbmc.sleep(1000)
continue continue
set_zero = False set_zero = False
if isinstance(url, ArtworkSyncMessage): if isinstance(url, ArtworkSyncMessage):
@ -115,7 +116,7 @@ class Image_Cache_Thread(Thread):
'over-loaded. Sleep %s seconds before trying ' 'over-loaded. Sleep %s seconds before trying '
'again to download %s', 'again to download %s',
2**sleeptime, double_urldecode(url)) 2**sleeptime, double_urldecode(url))
sleep((2**sleeptime) * 1000) xbmc.sleep((2**sleeptime) * 1000)
sleeptime += 1 sleeptime += 1
continue continue
except Exception as err: except Exception as err:
@ -129,11 +130,12 @@ class Image_Cache_Thread(Thread):
queue.task_done() queue.task_done()
# Update the caching state in the PKC settings. # Update the caching state in the PKC settings.
counter += 1 counter += 1
if counter > 20: if (counter > 20 and not xbmc.getCondVisibility(
'Window.IsVisible(DialogAddonSettings.xml)')):
counter = 0 counter = 0
settings('caching_artwork_count', value=str(queue.qsize())) settings('caching_artwork_count', value=str(queue.qsize()))
# Sleep for a bit to reduce CPU strain # Sleep for a bit to reduce CPU strain
sleep(sleep_between) xbmc.sleep(sleep_between)
LOG.info("---===### Stopped Image_Cache_Thread ###===---") LOG.info("---===### Stopped Image_Cache_Thread ###===---")
@ -200,7 +202,7 @@ class Artwork():
if dialog('yesno', "Image Texture Cache", lang(39251)): if dialog('yesno', "Image Texture Cache", lang(39251)):
LOG.info("Resetting all cache data first") LOG.info("Resetting all cache data first")
# Remove all existing textures first # Remove all existing textures first
path = try_decode(translatePath("special://thumbnails/")) path = try_decode(xbmc.translatePath("special://thumbnails/"))
if exists_dir(path): if exists_dir(path):
rmtree(path, ignore_errors=True) rmtree(path, ignore_errors=True)
self.restore_cache_directories() self.restore_cache_directories()
@ -318,7 +320,7 @@ class Artwork():
pass pass
else: else:
# Delete thumbnail as well as the entry # Delete thumbnail as well as the entry
path = translatePath("special://thumbnails/%s" % cachedurl) path = xbmc.translatePath("special://thumbnails/%s" % cachedurl)
LOG.debug("Deleting cached thumbnail: %s", path) LOG.debug("Deleting cached thumbnail: %s", path)
if exists(path): if exists(path):
rmtree(try_decode(path), ignore_errors=True) rmtree(try_decode(path), ignore_errors=True)
@ -334,7 +336,7 @@ class Artwork():
"a", "b", "c", "d", "e", "f", "a", "b", "c", "d", "e", "f",
"Video", "plex") "Video", "plex")
for path in paths: for path in paths:
makedirs(try_decode(translatePath("special://thumbnails/%s" makedirs(try_decode(xbmc.translatePath("special://thumbnails/%s"
% path))) % path)))

View file

@ -3,7 +3,7 @@ from logging import getLogger
from threading import Thread from threading import Thread
from Queue import Empty from Queue import Empty
from xbmc import sleep import xbmc
from utils import thread_methods, settings, language as lang, dialog from utils import thread_methods, settings, language as lang, dialog
import plexdb_functions as plexdb import plexdb_functions as plexdb
@ -59,16 +59,17 @@ class ThreadedProcessFanart(Thread):
# Abort was requested while waiting. We should exit # Abort was requested while waiting. We should exit
LOG.info("---===### Stopped FanartSync ###===---") LOG.info("---===### Stopped FanartSync ###===---")
return return
sleep(1000) xbmc.sleep(1000)
# grabs Plex item from queue # grabs Plex item from queue
try: try:
item = queue.get(block=False) item = queue.get(block=False)
except Empty: except Empty:
if not set_zero: if not set_zero and not xbmc.getCondVisibility(
'Window.IsVisible(DialogAddonSettings.xml)')::
# Avoid saving '0' all the time # Avoid saving '0' all the time
set_zero = True set_zero = True
settings('fanarttv_lookups', value='0') settings('fanarttv_lookups', value='0')
sleep(200) xbmc.sleep(200)
continue continue
set_zero = False set_zero = False
if isinstance(item, ArtworkSyncMessage): if isinstance(item, ArtworkSyncMessage):
@ -92,7 +93,8 @@ class ThreadedProcessFanart(Thread):
plex_db.set_fanart_synched(item['plex_id']) plex_db.set_fanart_synched(item['plex_id'])
# Update the caching state in the PKC settings. Avoid saving '0' # Update the caching state in the PKC settings. Avoid saving '0'
counter += 1 counter += 1
if counter > 10: if (counter > 20 and not xbmc.getCondVisibility(
'Window.IsVisible(DialogAddonSettings.xml)')):
counter = 0 counter = 0
settings('fanarttv_lookups', value=str(queue.qsize())) settings('fanarttv_lookups', value=str(queue.qsize()))
queue.task_done() queue.task_done()