use int percentage value for cache validation string
This commit is contained in:
@@ -32,9 +32,7 @@ sys.path.append(BASE_RESOURCE_PATH)
|
||||
|
||||
import Functions
|
||||
|
||||
xbmc.log ("===== MBCon START =====")
|
||||
Functions.mainEntryPoint()
|
||||
xbmc.log ("===== MBCon FINISHED =====")
|
||||
|
||||
#clear done and exit.
|
||||
#sys.modules.clear()
|
||||
|
||||
@@ -260,13 +260,13 @@ class ArtworkRotationThread(threading.Thread):
|
||||
result01 = self.updateCollectionArtLinks()
|
||||
t2 = time.time()
|
||||
diff = t2 - t1
|
||||
xbmc.log("TIME_DIFF : " + str(diff))
|
||||
self.logMsg("TIME_DIFF : " + str(diff))
|
||||
|
||||
if(result01):
|
||||
xbmc.log("BackgroundRotationThread Update Links Worked")
|
||||
self.logMsg("BackgroundRotationThread Update Links Worked")
|
||||
self.linksLoaded = True
|
||||
else:
|
||||
xbmc.log("BackgroundRotationThread Update Links Failed")
|
||||
self.logMsg("BackgroundRotationThread Update Links Failed")
|
||||
self.linksLoaded = False
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,20 @@ class DataManager():
|
||||
dataUrl = None
|
||||
cacheDataPath = None
|
||||
canRefreshNow = False
|
||||
logLevel = 0
|
||||
|
||||
def __init__(self, *args):
|
||||
addonSettings = xbmcaddon.Addon(id='plugin.video.mbcon')
|
||||
self.addonSettings = xbmcaddon.Addon(id='plugin.video.mbcon')
|
||||
level = addonSettings.getSetting('logLevel')
|
||||
self.logLevel = 0
|
||||
if(level != None):
|
||||
self.logLevel = int(level)
|
||||
|
||||
def logMsg(self, msg, level = 1):
|
||||
if(self.logLevel >= level):
|
||||
xbmc.log("MBCon DataManager -> " + msg)
|
||||
|
||||
def getCacheValidatorFromData(self, result):
|
||||
result = result.get("Items")
|
||||
if(result == None):
|
||||
@@ -34,21 +47,26 @@ class DataManager():
|
||||
itemPercent = 0.0
|
||||
if userData.get("Played") == False:
|
||||
unwatchedItemCount = unwatchedItemCount + 1
|
||||
itemPossition = userData.get("PlaybackPositionTicks")
|
||||
itemRuntime = item.get("RunTimeTicks")
|
||||
if(itemRuntime != None and itemPossition != None):
|
||||
itemPercent = float(itemPossition) / float(itemRuntime)
|
||||
else:
|
||||
itemPercent == 100.0
|
||||
|
||||
# calc the percentage
|
||||
itemPercent = 0.0
|
||||
itemPossition = userData.get("PlaybackPositionTicks")
|
||||
itemRuntime = item.get("RunTimeTicks")
|
||||
if(itemRuntime != None and itemPossition != None):
|
||||
itemPercent = (float(itemPossition) / float(itemRuntime)) * 100
|
||||
|
||||
dataHashString = dataHashString + str(itemCount) + "_" + item.get("Name", "name") + "_" + "{0:09.6f}".format(itemPercent) + "-" + str(unwatchedItemCount) + "|"
|
||||
itemString = str(itemCount) + "_" + item.get("Name", "name") + "_" + str(int(itemPercent)) + "-" + str(unwatchedItemCount) + "|"
|
||||
self.logMsg(itemString, level=2)
|
||||
dataHashString = dataHashString + itemString
|
||||
else:
|
||||
itemCount = itemCount + item.get("RecursiveItemCount")
|
||||
unwatchedItemCount = unwatchedItemCount + userData.get("UnplayedItemCount")
|
||||
PlayedPercentage = userData.get("PlayedPercentage")
|
||||
if PlayedPercentage == None:
|
||||
PlayedPercentage = 0
|
||||
dataHashString = dataHashString + str(itemCount) + "_" + item.get("Name", "name") + "_" + "{0:09.6f}".format(PlayedPercentage) + "-" + str(unwatchedItemCount) + "|"
|
||||
itemString = str(itemCount) + "_" + item.get("Name", "name") + "_" + str(int(PlayedPercentage)) + "-" + str(unwatchedItemCount) + "|"
|
||||
self.logMsg(itemString, level=2)
|
||||
dataHashString = dataHashString + itemString
|
||||
|
||||
# hash the data
|
||||
dataHashString = dataHashString.encode("UTF-8")
|
||||
@@ -56,8 +74,8 @@ class DataManager():
|
||||
m.update(dataHashString)
|
||||
validatorString = m.hexdigest()
|
||||
|
||||
#xbmc.log("Cache_Data_Manager: getCacheValidatorFromData : RawData : " + dataHashString)
|
||||
xbmc.log("Cache_Data_Manager: getCacheValidatorFromData : hashData : " + validatorString)
|
||||
self.logMsg("getCacheValidatorFromData : RawData : " + dataHashString, level=2)
|
||||
self.logMsg("getCacheValidatorFromData : hashData : " + validatorString, level=2)
|
||||
|
||||
return validatorString
|
||||
|
||||
@@ -78,7 +96,7 @@ class DataManager():
|
||||
os.makedirs(os.path.join(__addondir__, "cache"))
|
||||
cacheDataPath = os.path.join(__addondir__, "cache", urlHash)
|
||||
|
||||
xbmc.log("Cache_Data_Manager:" + cacheDataPath)
|
||||
self.logMsg("Cache_Data_Manager:" + cacheDataPath)
|
||||
|
||||
# are we forcing a reload
|
||||
WINDOW = xbmcgui.Window( 10000 )
|
||||
@@ -87,8 +105,8 @@ class DataManager():
|
||||
|
||||
if(os.path.exists(cacheDataPath)) and force_data_reload != "true":
|
||||
# load data from cache if it is available and trigger a background
|
||||
# verification process to test cache validity
|
||||
xbmc.log("Cache_Data_Manager: Loading Cached File")
|
||||
# verification process to test cache validity
|
||||
self.logMsg("Loading Cached File")
|
||||
cachedfie = open(cacheDataPath, 'r')
|
||||
jsonData = cachedfie.read()
|
||||
cachedfie.close()
|
||||
@@ -102,43 +120,58 @@ class DataManager():
|
||||
actionThread.setCacheData(self)
|
||||
actionThread.start()
|
||||
|
||||
xbmc.log("Cache_Data_Manager: Returning Cached Result")
|
||||
self.logMsg("Returning Cached Result")
|
||||
return result
|
||||
else:
|
||||
# no cache data so load the url and save it
|
||||
jsonData = DownloadUtils().downloadUrl(url, suppress=False, popup=1)
|
||||
xbmc.log("Cache_Data_Manager: Loading URL and saving to cache")
|
||||
self.logMsg("Loading URL and saving to cache")
|
||||
cachedfie = open(cacheDataPath, 'w')
|
||||
cachedfie.write(jsonData)
|
||||
cachedfie.close()
|
||||
result = self.loadJasonData(jsonData)
|
||||
self.cacheManagerFinished = True
|
||||
xbmc.log("Cache_Data_Manager: Returning Loaded Result")
|
||||
self.logMsg("Returning Loaded Result")
|
||||
return result
|
||||
|
||||
|
||||
class CacheManagerThread(threading.Thread):
|
||||
|
||||
dataManager = None
|
||||
logLevel = 0
|
||||
|
||||
def __init__(self, *args):
|
||||
addonSettings = xbmcaddon.Addon(id='plugin.video.mbcon')
|
||||
self.addonSettings = xbmcaddon.Addon(id='plugin.video.mbcon')
|
||||
level = addonSettings.getSetting('logLevel')
|
||||
self.logLevel = 0
|
||||
if(level != None):
|
||||
self.logLevel = int(level)
|
||||
|
||||
threading.Thread.__init__(self, *args)
|
||||
|
||||
def logMsg(self, msg, level = 1):
|
||||
if(self.logLevel >= level):
|
||||
xbmc.log("MBCon CacheManagerThread -> " + msg)
|
||||
|
||||
def setCacheData(self, data):
|
||||
self.dataManager = data
|
||||
|
||||
def run(self):
|
||||
|
||||
xbmc.log("Cache_Data_Manager: CacheManagerThread Started")
|
||||
self.logMsg("CacheManagerThread Started")
|
||||
|
||||
cacheValidatorString = self.dataManager.getCacheValidatorFromData(self.dataManager.cacheDataResult)
|
||||
xbmc.log("Cache_Data_Manager: Cache Validator String (" + cacheValidatorString + ")")
|
||||
self.logMsg("Cache Validator String (" + cacheValidatorString + ")")
|
||||
|
||||
jsonData = DownloadUtils().downloadUrl(self.dataManager.dataUrl, suppress=False, popup=1)
|
||||
loadedResult = self.dataManager.loadJasonData(jsonData)
|
||||
loadedValidatorString = self.dataManager.getCacheValidatorFromData(loadedResult)
|
||||
xbmc.log("Cache_Data_Manager: loaded Validator String (" + loadedValidatorString + ")")
|
||||
self.logMsg("Loaded Validator String (" + loadedValidatorString + ")")
|
||||
|
||||
# if they dont match then save the data and trigger a content reload
|
||||
if(cacheValidatorString != loadedValidatorString):
|
||||
xbmc.log("Cache_Data_Manager: CacheManagerThread Saving new cache data and reloading container")
|
||||
self.logMsg("CacheManagerThread Saving new cache data and reloading container")
|
||||
cachedfie = open(self.dataManager.cacheDataPath, 'w')
|
||||
cachedfie.write(jsonData)
|
||||
cachedfie.close()
|
||||
@@ -150,7 +183,7 @@ class CacheManagerThread(threading.Thread):
|
||||
xbmc.sleep(100)
|
||||
loops = loops + 1
|
||||
|
||||
xbmc.log("Cache_Data_Manager: Sending container refresh (" + str(loops) + ")")
|
||||
self.logMsg("Sending container refresh (" + str(loops) + ")")
|
||||
xbmc.executebuiltin("Container.Refresh")
|
||||
|
||||
xbmc.log("Cache_Data_Manager: CacheManagerThread Exited")
|
||||
self.logMsg("CacheManagerThread Exited")
|
||||
|
||||
@@ -117,7 +117,7 @@ class DownloadUtils():
|
||||
userid = WINDOW.getProperty("userid")
|
||||
|
||||
if(userid != None and userid != ""):
|
||||
xbmc.log("MBCon DownloadUtils -> Returning saved UserID : " + userid)
|
||||
self.logMsg("MBCon DownloadUtils -> Returning saved UserID : " + userid)
|
||||
return userid
|
||||
|
||||
port = self.addonSettings.getSetting('port')
|
||||
@@ -178,7 +178,7 @@ class DownloadUtils():
|
||||
|
||||
token = WINDOW.getProperty("AccessToken")
|
||||
if(token != None and token != ""):
|
||||
xbmc.log("MBCon DownloadUtils -> Returning saved AccessToken : " + token)
|
||||
self.logMsg("MBCon DownloadUtils -> Returning saved AccessToken : " + token)
|
||||
return token
|
||||
|
||||
port = self.addonSettings.getSetting("port")
|
||||
@@ -240,7 +240,7 @@ class DownloadUtils():
|
||||
if(authToken != ""):
|
||||
headers["X-MediaBrowser-Token"] = authToken
|
||||
|
||||
xbmc.log("MBCon Authentication Header : " + str(headers))
|
||||
self.logMsg("MBCon Authentication Header : " + str(headers))
|
||||
return headers
|
||||
|
||||
def downloadUrl(self, url, suppress=False, postBody=None, type="GET", popup=0, authenticate=True):
|
||||
|
||||
@@ -137,13 +137,15 @@ try:
|
||||
except:
|
||||
pass
|
||||
|
||||
xbmc.log ("MBCon -> LogLevel: " + str(logLevel))
|
||||
#xbmc.log("MBCon -> LogLevel: " + str(logLevel))
|
||||
|
||||
downloadUtils = DownloadUtils()
|
||||
dataManager = DataManager()
|
||||
|
||||
def mainEntryPoint():
|
||||
|
||||
printDebug("===== MBCon START =====")
|
||||
|
||||
ProfileCode = __settings__.getSetting('profile') == "true"
|
||||
|
||||
if(ProfileCode):
|
||||
@@ -152,10 +154,9 @@ def mainEntryPoint():
|
||||
pr.enable()
|
||||
|
||||
ADDON_VERSION = ClientInformation().getVersion()
|
||||
xbmc.log ("MBCon -> running Python: " + str(sys.version_info))
|
||||
xbmc.log ("MBCon -> running MBCon: " + str(ADDON_VERSION))
|
||||
xbmc.log (xbmc.getInfoLabel( "System.BuildVersion" ))
|
||||
|
||||
printDebug("MBCon -> running Python: " + str(sys.version_info))
|
||||
printDebug("MBCon -> running MBCon: " + str(ADDON_VERSION))
|
||||
printDebug(xbmc.getInfoLabel( "System.BuildVersion" ))
|
||||
printDebug( "MBCon -> Script argument date " + str(sys.argv))
|
||||
|
||||
try:
|
||||
@@ -163,7 +164,7 @@ def mainEntryPoint():
|
||||
except:
|
||||
params = {}
|
||||
|
||||
printDebug( "MBCon -> Script params is " + str(params))
|
||||
printDebug("MBCon -> Script params is " + str(params))
|
||||
|
||||
param_url = params.get('url', None)
|
||||
|
||||
@@ -270,6 +271,9 @@ def mainEntryPoint():
|
||||
f.write(str(ncalls) + "\t" + "{0}".format(total_time) + "\t" + "{0}".format(cumulative_time) + "\t" + func_name + "\t" + filename + "\r\n")
|
||||
f.close()
|
||||
|
||||
printDebug("===== MBCon FINISHED =====")
|
||||
|
||||
|
||||
def printDebug( msg, level = 1):
|
||||
if(logLevel >= level):
|
||||
if(logLevel == 2):
|
||||
|
||||
@@ -173,7 +173,7 @@ class BackgroundSearchThread(threading.Thread):
|
||||
searchString = ""
|
||||
|
||||
def __init__(self, *args):
|
||||
xbmc.log("BackgroundSearchThread Init")
|
||||
#xbmc.log("BackgroundSearchThread Init")
|
||||
threading.Thread.__init__(self, *args)
|
||||
|
||||
def setSearch(self, searchFor):
|
||||
@@ -186,7 +186,7 @@ class BackgroundSearchThread(threading.Thread):
|
||||
self.searchDialog = searchDialog
|
||||
|
||||
def run(self):
|
||||
xbmc.log("BackgroundSearchThread Started")
|
||||
#xbmc.log("BackgroundSearchThread Started")
|
||||
|
||||
lastSearchString = ""
|
||||
|
||||
@@ -198,7 +198,7 @@ class BackgroundSearchThread(threading.Thread):
|
||||
|
||||
xbmc.sleep(2000)
|
||||
|
||||
xbmc.log("BackgroundSearchThread Exited")
|
||||
#xbmc.log("BackgroundSearchThread Exited")
|
||||
|
||||
def doSearch(self, searchTerm):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user