Cache missing posters and backgrounds/fanart on Kodi startup
- Partially fixes #457
This commit is contained in:
parent
51f47452f2
commit
d3ef80ed22
6 changed files with 84 additions and 6 deletions
|
@ -41,6 +41,21 @@ msgctxt "#30005"
|
||||||
msgid "Username: "
|
msgid "Username: "
|
||||||
msgstr ""
|
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
|
# PKC settings artwork: Enable image caching during Kodi playback
|
||||||
msgctxt "#30009"
|
msgctxt "#30009"
|
||||||
msgid "Enable image caching during Kodi playback (restart Kodi!)"
|
msgid "Enable image caching during Kodi playback (restart Kodi!)"
|
||||||
|
|
|
@ -68,6 +68,16 @@ class Image_Cache_Thread(Thread):
|
||||||
except Empty:
|
except Empty:
|
||||||
sleep(1000)
|
sleep(1000)
|
||||||
continue
|
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
|
sleeptime = 0
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -119,6 +129,46 @@ class Artwork():
|
||||||
if enableTextureCache:
|
if enableTextureCache:
|
||||||
queue = ARTWORK_QUEUE
|
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):
|
def fullTextureCacheSync(self):
|
||||||
"""
|
"""
|
||||||
This method will sync all Kodi artwork to textures13.db
|
This method will sync all Kodi artwork to textures13.db
|
||||||
|
@ -177,10 +227,10 @@ class Artwork():
|
||||||
|
|
||||||
def cache_texture(self, url):
|
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:
|
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):
|
def modify_artwork(self, artworks, kodi_id, kodi_type, cursor):
|
||||||
"""
|
"""
|
||||||
|
@ -269,3 +319,11 @@ class Artwork():
|
||||||
for path in paths:
|
for path in paths:
|
||||||
makedirs(try_decode(translatePath("special://thumbnails/%s"
|
makedirs(try_decode(translatePath("special://thumbnails/%s"
|
||||||
% path)))
|
% path)))
|
||||||
|
|
||||||
|
|
||||||
|
class ArtworkSyncMessage(object):
|
||||||
|
"""
|
||||||
|
Put in artwork queue to display the message as a Kodi notification
|
||||||
|
"""
|
||||||
|
def __init__(self, message):
|
||||||
|
self.message = message
|
||||||
|
|
|
@ -50,7 +50,8 @@ STATE_SETTINGS = {
|
||||||
'remapSMBphotoNew': 'remapSMBphotoNew',
|
'remapSMBphotoNew': 'remapSMBphotoNew',
|
||||||
'enableMusic': 'ENABLE_MUSIC',
|
'enableMusic': 'ENABLE_MUSIC',
|
||||||
'forceReloadSkinOnPlaybackStop': 'FORCE_RELOAD_SKIN',
|
'forceReloadSkinOnPlaybackStop': 'FORCE_RELOAD_SKIN',
|
||||||
'fetch_pms_item_number': 'FETCH_PMS_ITEM_NUMBER'
|
'fetch_pms_item_number': 'FETCH_PMS_ITEM_NUMBER',
|
||||||
|
'imageSyncNotifications': 'IMAGE_SYNC_NOTIFICATIONS'
|
||||||
}
|
}
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
|
@ -16,6 +16,7 @@ from downloadutils import DownloadUtils as DU
|
||||||
import itemtypes
|
import itemtypes
|
||||||
import plexdb_functions as plexdb
|
import plexdb_functions as plexdb
|
||||||
import kodidb_functions as kodidb
|
import kodidb_functions as kodidb
|
||||||
|
import artwork
|
||||||
import videonodes
|
import videonodes
|
||||||
import variables as v
|
import variables as v
|
||||||
|
|
||||||
|
@ -1453,7 +1454,6 @@ class LibrarySync(Thread):
|
||||||
elif state.RUN_LIB_SCAN == 'textures':
|
elif state.RUN_LIB_SCAN == 'textures':
|
||||||
state.DB_SCAN = True
|
state.DB_SCAN = 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)
|
||||||
state.DB_SCAN = False
|
state.DB_SCAN = False
|
||||||
|
@ -1517,8 +1517,6 @@ class LibrarySync(Thread):
|
||||||
last_time_sync = utils.unix_timestamp()
|
last_time_sync = utils.unix_timestamp()
|
||||||
window('plex_dbScan', clear=True)
|
window('plex_dbScan', clear=True)
|
||||||
state.DB_SCAN = False
|
state.DB_SCAN = False
|
||||||
# Start the fanart download thread
|
|
||||||
self.fanartthread.start()
|
|
||||||
|
|
||||||
while not self.stopped():
|
while not self.stopped():
|
||||||
# In the event the server goes offline
|
# In the event the server goes offline
|
||||||
|
@ -1544,6 +1542,7 @@ class LibrarySync(Thread):
|
||||||
initial_sync_done = True
|
initial_sync_done = True
|
||||||
kodi_db_version_checked = True
|
kodi_db_version_checked = True
|
||||||
last_sync = utils.unix_timestamp()
|
last_sync = utils.unix_timestamp()
|
||||||
|
self.fanartthread.start()
|
||||||
else:
|
else:
|
||||||
LOG.error('Initial start-up full sync unsuccessful')
|
LOG.error('Initial start-up full sync unsuccessful')
|
||||||
xbmc.executebuiltin('InhibitIdleShutdown(false)')
|
xbmc.executebuiltin('InhibitIdleShutdown(false)')
|
||||||
|
@ -1591,6 +1590,8 @@ class LibrarySync(Thread):
|
||||||
LOG.info('Startup sync has not yet been successful')
|
LOG.info('Startup sync has not yet been successful')
|
||||||
window('plex_dbScan', clear=True)
|
window('plex_dbScan', clear=True)
|
||||||
state.DB_SCAN = False
|
state.DB_SCAN = False
|
||||||
|
artwork.Artwork().cache_major_artwork()
|
||||||
|
self.fanartthread.start()
|
||||||
|
|
||||||
# Currently no db scan, so we can start a new scan
|
# Currently no db scan, so we can start a new scan
|
||||||
elif state.DB_SCAN is False:
|
elif state.DB_SCAN is False:
|
||||||
|
|
|
@ -39,6 +39,8 @@ FORCE_RELOAD_SKIN = True
|
||||||
# Stemming from the PKC settings.xml
|
# Stemming from the PKC settings.xml
|
||||||
# Shall we show Kodi dialogs when synching?
|
# Shall we show Kodi dialogs when synching?
|
||||||
SYNC_DIALOG = True
|
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?
|
# Is synching of Plex music enabled?
|
||||||
ENABLE_MUSIC = True
|
ENABLE_MUSIC = True
|
||||||
# How often shall we sync?
|
# How often shall we sync?
|
||||||
|
|
|
@ -125,6 +125,7 @@
|
||||||
<setting id="enableTextureCache" label="30512" type="bool" default="true" /> <!-- Force Artwork Caching -->
|
<setting id="enableTextureCache" label="30512" type="bool" default="true" /> <!-- Force Artwork Caching -->
|
||||||
<setting id="FanartTV" label="30539" type="bool" default="false" /><!-- Download additional art from FanArtTV -->
|
<setting id="FanartTV" label="30539" type="bool" default="false" /><!-- Download additional art from FanArtTV -->
|
||||||
<setting label="39222" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect/?mode=fanart)" option="close" visible="eq(-1,true)" subsetting="true" /> <!-- Look for missing fanart on FanartTV now -->
|
<setting label="39222" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect/?mode=fanart)" option="close" visible="eq(-1,true)" subsetting="true" /> <!-- Look for missing fanart on FanartTV now -->
|
||||||
|
<setting id="imageSyncNotifications" label="30008" type="bool" default="true" /><!-- Enable notifications for image caching -->
|
||||||
<setting id="imageSyncDuringPlayback" label="30009" type="bool" default="true" /><!-- Enable image caching during Kodi playback (restart Kodi!) -->
|
<setting id="imageSyncDuringPlayback" label="30009" type="bool" default="true" /><!-- Enable image caching during Kodi playback (restart Kodi!) -->
|
||||||
<setting label="39020" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect/?mode=texturecache)" option="close" /> <!-- Cache all images to Kodi texture cache now -->
|
<setting label="39020" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect/?mode=texturecache)" option="close" /> <!-- Cache all images to Kodi texture cache now -->
|
||||||
</category>
|
</category>
|
||||||
|
|
Loading…
Reference in a new issue