fix texture cache stuff

This commit is contained in:
Marcel van der Veldt 2015-06-24 10:02:34 +02:00
parent d617aa13ac
commit feb6c73fc3
2 changed files with 28 additions and 21 deletions

View File

@ -3,11 +3,11 @@
################################################################################################# #################################################################################################
import xbmc import xbmc, xbmcaddon, xbmcvfs
import xbmcaddon
import json import json
import requests import requests
import urllib import urllib
import os
import Utils as utils import Utils as utils
@ -42,15 +42,38 @@ class TextureCache():
def FullTextureCacheSync(self): def FullTextureCacheSync(self):
#this method can be called from the plugin to sync all Kodi textures to the texture cache. #this method can be called from the plugin to sync all Kodi textures to the texture cache.
#Warning: this means that every image will be cached locally, this takes diskspace! #Warning: this means that every image will be cached locally, this takes diskspace!
#remove all existing textures first
path = "special://thumbnails/"
if xbmcvfs.exists(path):
allDirs, allFiles = xbmcvfs.listdir(path)
for dir in allDirs:
allDirs, allFiles = xbmcvfs.listdir(path+dir)
for file in allFiles:
xbmcvfs.delete(os.path.join(path+dir,file))
textureconnection = utils.KodiSQL("texture")
texturecursor = textureconnection.cursor()
texturecursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
rows = texturecursor.fetchall()
for row in rows:
tableName = row[0]
if(tableName != "version"):
texturecursor.execute("DELETE FROM " + tableName)
textureconnection.commit()
texturecursor.close()
#cache all entries in video DB
connection = utils.KodiSQL("video") connection = utils.KodiSQL("video")
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("SELECT url FROM art") cursor.execute("SELECT url FROM art")
result = cursor.fetchall() result = cursor.fetchall()
for url in result: for url in result:
self.CacheTexture(url[0]) self.CacheTexture(url[0])
cursor.close() cursor.close()
#cache all entries in music DB
connection = utils.KodiSQL("music") connection = utils.KodiSQL("music")
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("SELECT url FROM art") cursor.execute("SELECT url FROM art")
@ -74,20 +97,6 @@ class TextureCache():
#extreme short timeouts so we will have a exception, but we don't need the result so pass #extreme short timeouts so we will have a exception, but we don't need the result so pass
pass pass
def refreshFanart(self,url):
connection = utils.KodiSQL("texture")
cursor = connection.cursor()
cursor.execute("SELECT cachedurl FROM texture WHERE url = ?", (url,))
result = cursor.fetchone()
if result:
result = result[0]
cursor.execute("DELETE FROM texture WHERE cachedurl = ?", (result,))
connection.commit()
cursor.close()
else:
cursor.close()
self.CacheTexture(url)
def setKodiWebServerDetails(self): def setKodiWebServerDetails(self):
# Get the Kodi webserver details - used to set the texture cache # Get the Kodi webserver details - used to set the texture cache

View File

@ -792,10 +792,8 @@ class WriteKodiVideoDB():
cursor.execute("UPDATE art set url = ? WHERE media_id = ? AND media_type = ? AND type = ?", (imageUrl, kodiId, mediaType, imageType)) cursor.execute("UPDATE art set url = ? WHERE media_id = ? AND media_type = ? AND type = ?", (imageUrl, kodiId, mediaType, imageType))
#cache fanart and poster in Kodi texture cache #cache fanart and poster in Kodi texture cache
if "fanart" in imageType: if "fanart" in imageType or "poster" in imageType:
utils.logMsg("ArtworkSync", "Adding or Updating Fanart: %s" % imageUrl) utils.logMsg("ArtworkSync", "Adding or Updating Fanart: %s" % imageUrl)
self.textureCache.refreshFanart(imageUrl)
elif "poster" in imageType:
self.textureCache.CacheTexture(imageUrl) self.textureCache.CacheTexture(imageUrl)
def setKodiResumePoint(self, fileid, resume_seconds, total_seconds, cursor): def setKodiResumePoint(self, fileid, resume_seconds, total_seconds, cursor):