From d16296395f69dc351472773c2e43a4526a6fefae Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 13 May 2018 14:20:39 +0200 Subject: [PATCH] Show caching progress for Plex images in the PKC settings --- .../resource.language.en_gb/strings.po | 16 ++++++-- resources/lib/artwork.py | 39 ++++++++++++++----- resources/settings.xml | 5 ++- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 43d86404..a73605d8 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -43,12 +43,12 @@ msgstr "" # Sync notification displayed if there is still artwork to be cached to Kodi msgctxt "#30006" -msgid "Caching %s images" +msgid "Caching %s Plex images" msgstr "" # Sync notification displayed if syncing of major artwork is done msgctxt "#30007" -msgid "Major image caching done" +msgid "Plex image caching done" msgstr "" # PKC settings artwork: Enable notifications for artwork image sync @@ -61,6 +61,16 @@ msgctxt "#30009" msgid "Enable image caching during Kodi playback (restart Kodi!)" msgstr "" +# PKC settings - Artwork +msgctxt "#30010" +msgid "Approximate caching progress" +msgstr "" + +# PKC settings - Artwork +msgctxt "#30011" +msgid "Plex artwork (posters and backgrounds) left to cache:" +msgstr "" + # Button text msgctxt "#30012" msgid "OK" @@ -407,7 +417,7 @@ msgstr "" # PKC Settings - Artwork msgctxt "#30512" -msgid "Force artwork caching" +msgid "Cache all artwork for a smooth Kodi experience" msgstr "" # PKC Settings - Artwork diff --git a/resources/lib/artwork.py b/resources/lib/artwork.py index 5ab1199c..3362a472 100644 --- a/resources/lib/artwork.py +++ b/resources/lib/artwork.py @@ -69,7 +69,15 @@ class Image_Cache_Thread(Thread): sleep(1000) continue if isinstance(url, ArtworkSyncMessage): - if state.IMAGE_SYNC_NOTIFICATIONS: + if url.major_artwork_counter is not None: + if url.major_artwork_counter == 0: + # Done caching, show this in the PKC settings, too + settings('caching_major_artwork', value=lang(30069)) + LOG.info('Done caching major images!') + else: + settings('caching_major_artwork', + value=str(url.major_artwork_counter)) + if url.message and state.IMAGE_SYNC_NOTIFICATIONS: dialog('notification', heading=lang(29999), message=url.message, @@ -110,9 +118,9 @@ class Image_Cache_Thread(Thread): sleep((2**sleeptime) * 1000) sleeptime += 1 continue - except Exception as e: + except Exception as err: LOG.error('Unknown exception for url %s: %s'. - double_urldecode(url), e) + double_urldecode(url), err) import traceback LOG.error("Traceback:\n%s", traceback.format_exc()) break @@ -159,15 +167,25 @@ class Artwork(): connection.close() if not artworks_to_cache: LOG.info('Caching of major images to Kodi texture cache done') + # Set to "None" + settings('caching_major_artwork', value=lang(30069)) return + length = len(artworks_to_cache) LOG.info('Caching has not been completed - caching %s major images', - len(artworks_to_cache)) - # Caching %s images - self.queue.put(ArtworkSyncMessage(lang(30006) % len(artworks_to_cache))) - for url in artworks_to_cache: + length) + settings('caching_major_artwork', value=str(length)) + # Caching %s Plex images + self.queue.put(ArtworkSyncMessage(message=lang(30006) % length, + major_artwork_counter=length)) + for i, url in enumerate(artworks_to_cache): self.queue.put(url[0]) - # Major image caching done - self.queue.put(ArtworkSyncMessage(lang(30007))) + if (length - i) % 10 == 0: + # Update the PKC settings for artwork caching progress + msg = ArtworkSyncMessage(major_artwork_counter=length - i) + self.queue.put(msg) + # Plex image caching done + self.queue.put(ArtworkSyncMessage(message=lang(30007), + major_artwork_counter=0)) def fullTextureCacheSync(self): """ @@ -325,5 +343,6 @@ class ArtworkSyncMessage(object): """ Put in artwork queue to display the message as a Kodi notification """ - def __init__(self, message): + def __init__(self, message=None, major_artwork_counter=None): self.message = message + self.major_artwork_counter = major_artwork_counter diff --git a/resources/settings.xml b/resources/settings.xml index 4f92a9f8..a5f33022 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -123,12 +123,15 @@ - + + + +