diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po
index 292beee7..e62c76dc 100644
--- a/resources/language/resource.language.en_gb/strings.po
+++ b/resources/language/resource.language.en_gb/strings.po
@@ -41,6 +41,21 @@ msgctxt "#30005"
msgid "Username: "
msgstr ""
+# Sync notification displayed if there is still artwork to be cached to Kodi
+msgctxt "#30006"
+msgid "Caching %s images"
+msgstr ""
+
+# Sync notification displayed if syncing of major artwork is done
+msgctxt "#30007"
+msgid "Major image caching done"
+msgstr ""
+
+# PKC settings artwork: Enable notifications for artwork image sync
+msgctxt "#30008"
+msgid "Enable notifications for image caching"
+msgstr ""
+
# PKC settings artwork: Enable image caching during Kodi playback
msgctxt "#30009"
msgid "Enable image caching during Kodi playback (restart Kodi!)"
diff --git a/resources/lib/artwork.py b/resources/lib/artwork.py
index d4e1e80d..2b4d609b 100644
--- a/resources/lib/artwork.py
+++ b/resources/lib/artwork.py
@@ -68,6 +68,16 @@ class Image_Cache_Thread(Thread):
except Empty:
sleep(1000)
continue
+ if isinstance(url, ArtworkSyncMessage):
+ if state.IMAGE_SYNC_NOTIFICATIONS:
+ dialog('notification',
+ heading=lang(29999),
+ message=url.message,
+ icon='{plex}',
+ sound=False)
+ queue.task_done()
+ continue
+ url = double_urlencode(try_encode(url))
sleeptime = 0
while True:
try:
@@ -119,6 +129,46 @@ class Artwork():
if enableTextureCache:
queue = ARTWORK_QUEUE
+ def cache_major_artwork(self):
+ """
+ Takes the existing Kodi library and caches posters and fanart.
+ Necessary because otherwise PKC caches artwork e.g. from fanart.tv
+ which basically blocks Kodi from getting needed artwork fast (e.g.
+ while browsing the library)
+ """
+ if not self.enableTextureCache:
+ return
+ artworks = list()
+ # Get all posters and fanart/background for video and music
+ for kind in ('video', 'music'):
+ connection = kodi_sql(kind)
+ cursor = connection.cursor()
+ for typus in ('poster', 'fanart'):
+ cursor.execute('SELECT url FROM art WHERE type == ?',
+ (typus, ))
+ artworks.extend(cursor.fetchall())
+ connection.close()
+ LOG.debug('artworks: %s', artworks)
+ LOG.debug('artworks: %s', len(artworks))
+ artworks_to_cache = list()
+ connection = kodi_sql('texture')
+ cursor = connection.cursor()
+ for url in artworks:
+ query = 'SELECT url FROM texture WHERE url == ? LIMIT 1'
+ cursor.execute(query, (url[0], ))
+ if not cursor.fetchone():
+ artworks_to_cache.append(url)
+ connection.close()
+ if not artworks_to_cache:
+ LOG.info('Caching of major images to Kodi texture cache done')
+ return
+ LOG.info('Caching has not been completed - caching %s major images',
+ len(artworks_to_cache))
+ self.queue.put(ArtworkSyncMessage(lang(30006) % len(artworks_to_cache)))
+ for url in artworks_to_cache:
+ self.queue.put(url[0])
+ self.queue.put(ArtworkSyncMessage(lang(30007)))
+
def fullTextureCacheSync(self):
"""
This method will sync all Kodi artwork to textures13.db
@@ -177,10 +227,10 @@ class Artwork():
def cache_texture(self, url):
'''
- Cache a single image url to the texture cache
+ Cache a single image url to the texture cache. url: unicode
'''
if url and self.enableTextureCache:
- self.queue.put(double_urlencode(try_encode(url)))
+ self.queue.put(url)
def modify_artwork(self, artworks, kodi_id, kodi_type, cursor):
"""
@@ -269,3 +319,11 @@ class Artwork():
for path in paths:
makedirs(try_decode(translatePath("special://thumbnails/%s"
% path)))
+
+
+class ArtworkSyncMessage(object):
+ """
+ Put in artwork queue to display the message as a Kodi notification
+ """
+ def __init__(self, message):
+ self.message = message
diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py
index d5070df3..00a63f85 100644
--- a/resources/lib/kodimonitor.py
+++ b/resources/lib/kodimonitor.py
@@ -50,7 +50,8 @@ STATE_SETTINGS = {
'remapSMBphotoNew': 'remapSMBphotoNew',
'enableMusic': 'ENABLE_MUSIC',
'forceReloadSkinOnPlaybackStop': 'FORCE_RELOAD_SKIN',
- 'fetch_pms_item_number': 'FETCH_PMS_ITEM_NUMBER'
+ 'fetch_pms_item_number': 'FETCH_PMS_ITEM_NUMBER',
+ 'imageSyncNotifications': 'IMAGE_SYNC_NOTIFICATIONS'
}
###############################################################################
diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py
index 4d63c609..e94d35c0 100644
--- a/resources/lib/librarysync.py
+++ b/resources/lib/librarysync.py
@@ -16,6 +16,7 @@ from downloadutils import DownloadUtils as DU
import itemtypes
import plexdb_functions as plexdb
import kodidb_functions as kodidb
+import artwork
import videonodes
import variables as v
@@ -1453,7 +1454,6 @@ class LibrarySync(Thread):
elif state.RUN_LIB_SCAN == 'textures':
state.DB_SCAN = True
window('plex_dbScan', value="true")
- import artwork
artwork.Artwork().fullTextureCacheSync()
window('plex_dbScan', clear=True)
state.DB_SCAN = False
@@ -1517,8 +1517,6 @@ class LibrarySync(Thread):
last_time_sync = utils.unix_timestamp()
window('plex_dbScan', clear=True)
state.DB_SCAN = False
- # Start the fanart download thread
- self.fanartthread.start()
while not self.stopped():
# In the event the server goes offline
@@ -1544,6 +1542,7 @@ class LibrarySync(Thread):
initial_sync_done = True
kodi_db_version_checked = True
last_sync = utils.unix_timestamp()
+ self.fanartthread.start()
else:
LOG.error('Initial start-up full sync unsuccessful')
xbmc.executebuiltin('InhibitIdleShutdown(false)')
@@ -1591,6 +1590,8 @@ class LibrarySync(Thread):
LOG.info('Startup sync has not yet been successful')
window('plex_dbScan', clear=True)
state.DB_SCAN = False
+ artwork.Artwork().cache_major_artwork()
+ self.fanartthread.start()
# Currently no db scan, so we can start a new scan
elif state.DB_SCAN is False:
diff --git a/resources/lib/state.py b/resources/lib/state.py
index 69532239..60b15ede 100644
--- a/resources/lib/state.py
+++ b/resources/lib/state.py
@@ -39,6 +39,8 @@ FORCE_RELOAD_SKIN = True
# Stemming from the PKC settings.xml
# Shall we show Kodi dialogs when synching?
SYNC_DIALOG = True
+# Shall Kodi show dialogs for syncing/caching images? (e.g. images left to sync)
+IMAGE_SYNC_NOTIFICATIONS = True
# Is synching of Plex music enabled?
ENABLE_MUSIC = True
# How often shall we sync?
diff --git a/resources/settings.xml b/resources/settings.xml
index 928c125f..d8e46400 100644
--- a/resources/settings.xml
+++ b/resources/settings.xml
@@ -125,6 +125,7 @@
+