unicode fixes

fix for users who have redirected kodi data folders (replace open with xbmcvfs.file)
This commit is contained in:
marcelveldt 2016-01-18 10:00:32 +01:00
parent ca0906aaaf
commit 2bd1d139c1
4 changed files with 21 additions and 20 deletions

View file

@ -45,10 +45,10 @@ def window(property, value=None, clear=False, windowid=10000):
if clear:
WINDOW.clearProperty(property)
elif value is not None:
WINDOW.setProperty(property, value)
else:
return WINDOW.getProperty(property)
elif value is not None: #setproperty accepts both string and unicode but utf-8 string seems best practice to pass
WINDOW.setProperty(property.encode("utf-8"), value.encode("utf-8"))
else: #getproperty returns string so convert to unicode
return WINDOW.getProperty(property).decode("utf-8")
def settings(setting, value=None):
# Get or add addon setting
@ -138,11 +138,11 @@ def reset():
path = xbmc.translatePath("special://profile/library/video/").decode('utf-8')
dirs, files = xbmcvfs.listdir(path)
for dir in dirs:
if dir.startswith('Emby'):
shutil.rmtree("%s%s" % (path, dir))
if dir.decode('utf-8').startswith('Emby'):
shutil.rmtree("%s%s" % (path, dir.decode('utf-8')))
for file in files:
if file.startswith('emby'):
xbmcvfs.delete("%s%s" % (path, file))
if file.decode('utf-8').startswith('emby'):
xbmcvfs.delete("%s%s" % (path, file.decode('utf-8')))
# Wipe the kodi databases
logMsg("EMBY", "Resetting the Kodi video database.")
@ -223,7 +223,7 @@ def stopProfiling(pr, profileName):
timestamp = time.strftime("%Y-%m-%d %H-%M-%S")
profile = "%s%s_profile_(%s).tab" % (profiles, profileName, timestamp)
f = open(profile, 'wb')
f = xbmcvfs.File(profile, 'w')
f.write("NumbCalls\tTotalTime\tCumulativeTime\tFunctionName\tFileName\r\n")
for (key, value) in ps.stats.items():
(filename, count, func_name) = key
@ -471,7 +471,7 @@ def playlistXSP(mediatype, tagname, viewtype="", delete=False):
}
logMsg("EMBY", "Writing playlist file to: %s" % xsppath, 1)
try:
f = open(xsppath, 'w')
f = xbmcvfs.File(xsppath, 'w')
except:
logMsg("EMBY", "Failed to create playlist: %s" % xsppath, 1)
return
@ -495,5 +495,5 @@ def deletePlaylists():
path = xbmc.translatePath("special://profile/playlists/video/").decode('utf-8')
dirs, files = xbmcvfs.listdir(path)
for file in files:
if file.startswith('Emby'):
if file.decode('utf-8').startswith('Emby'):
xbmcvfs.delete("%s%s" % (path, file))