Cache missing artwork on PKC startup

This commit is contained in:
tomkat83 2017-01-20 18:41:56 +01:00
parent 6049ec468a
commit 81747a668a
2 changed files with 42 additions and 3 deletions

View file

@ -127,6 +127,40 @@ def double_urldecode(text):
return unquote(unquote(text)) return unquote(unquote(text))
def get_uncached_artwork():
"""
Returns a list of URLs that haven't been cached yet
"""
all_urls = []
cached_urls = []
result = []
connection = kodiSQL('video')
cursor = connection.cursor()
# Get all artwork urls
cursor.execute("SELECT url FROM art WHERE media_type != 'actor'")
for url in cursor.fetchall():
all_urls.append(url[0])
connection.close()
connection = kodiSQL('music')
cursor = connection.cursor()
cursor.execute("SELECT url FROM art")
for url in cursor.fetchall():
all_urls.append(url[0])
connection.close()
# Get the cached urls
connection = kodiSQL('texture')
cursor = connection.cursor()
cursor.execute("SELECT url FROM texture")
for url in cursor.fetchall():
cached_urls.append(url[0])
connection.close()
for url in all_urls:
if url not in cached_urls:
result.append(url)
log.info('%s artwork urls have not been cached yet' % len(result))
return result
@ThreadMethodsAdditionalStop('plex_shouldStop') @ThreadMethodsAdditionalStop('plex_shouldStop')
@ThreadMethods @ThreadMethods
class Image_Cache_Thread(Thread): class Image_Cache_Thread(Thread):

View file

@ -15,7 +15,8 @@ from utils import window, settings, getUnixTimestamp, sourcesXML,\
ThreadMethods, ThreadMethodsAdditionalStop, LogTime, getScreensaver,\ ThreadMethods, ThreadMethodsAdditionalStop, LogTime, getScreensaver,\
setScreensaver, playlistXSP, language as lang, DateToKodi, reset,\ setScreensaver, playlistXSP, language as lang, DateToKodi, reset,\
advancedSettingsXML, getKodiVideoDBPath, tryDecode, deletePlaylists,\ advancedSettingsXML, getKodiVideoDBPath, tryDecode, deletePlaylists,\
deleteNodes, ThreadMethodsAdditionalSuspend, create_actor_db_index deleteNodes, ThreadMethodsAdditionalSuspend, create_actor_db_index, \
tryEncode
import clientinfo import clientinfo
import downloadutils import downloadutils
import itemtypes import itemtypes
@ -23,6 +24,7 @@ import plexdb_functions as plexdb
import kodidb_functions as kodidb import kodidb_functions as kodidb
import userclient import userclient
import videonodes import videonodes
import artwork
import PlexFunctions as PF import PlexFunctions as PF
import PlexAPI import PlexAPI
@ -1792,7 +1794,6 @@ class LibrarySync(Thread):
# "Current Kodi version is unsupported, cancel lib sync" # "Current Kodi version is unsupported, cancel lib sync"
self.dialog.ok(heading=addonName, line1=lang(39403)) self.dialog.ok(heading=addonName, line1=lang(39403))
break break
# Run start up sync # Run start up sync
window('plex_dbScan', value="true") window('plex_dbScan', value="true")
log.info("Db version: %s" % settings('dbCreatedWithVersion')) log.info("Db version: %s" % settings('dbCreatedWithVersion'))
@ -1800,6 +1801,11 @@ class LibrarySync(Thread):
# Initialize time offset Kodi - PMS # Initialize time offset Kodi - PMS
self.syncPMStime() self.syncPMStime()
lastSync = getUnixTimestamp() lastSync = getUnixTimestamp()
if settings('enableTextureCache') == "true":
# Start caching artwork that has not been cached yet
for url in artwork.get_uncached_artwork():
artwork.ARTWORK_QUEUE.put(
artwork.double_urlencode(tryEncode((url))))
log.info('Refreshing video nodes and playlists now') log.info('Refreshing video nodes and playlists now')
deletePlaylists() deletePlaylists()
deleteNodes() deleteNodes()
@ -1874,7 +1880,6 @@ class LibrarySync(Thread):
elif window('plex_runLibScan') == 'del_textures': elif window('plex_runLibScan') == 'del_textures':
window('plex_runLibScan', clear=True) window('plex_runLibScan', clear=True)
window('plex_dbScan', value="true") window('plex_dbScan', value="true")
import artwork
artwork.Artwork().fullTextureCacheSync() artwork.Artwork().fullTextureCacheSync()
window('plex_dbScan', clear=True) window('plex_dbScan', clear=True)
else: else: