more unicode fixes: os.path functions use unicode depending on the OS

This commit is contained in:
marcelveldt 2016-01-18 12:05:05 +01:00
parent 2bd1d139c1
commit eae4fea76a
7 changed files with 30 additions and 13 deletions

View file

@ -185,7 +185,10 @@ class Artwork():
for dir in allDirs:
allDirs, allFiles = xbmcvfs.listdir(path+dir)
for file in allFiles:
xbmcvfs.delete(os.path.join(path+dir.decode('utf-8'),file.decode('utf-8')))
if os.path.supports_unicode_filenames:
xbmcvfs.delete(os.path.join(path+dir.decode('utf-8'),file.decode('utf-8')))
else:
xbmcvfs.delete(os.path.join(path.encode('utf-8')+dir,file))
# remove all existing data from texture DB
textureconnection = utils.kodiSQL('texture')

View file

@ -76,7 +76,10 @@ class ClientInfo():
return clientId
addon_path = self.addon.getAddonInfo('path').decode('utf-8')
GUID_file = xbmc.translatePath(os.path.join(addon_path, "machine_guid")).decode('utf-8')
if os.path.supports_unicode_filenames:
GUID_file = xbmc.translatePath(os.path.join(addon_path, "machine_guid")).decode('utf-8')
else:
GUID_file = xbmc.translatePath(os.path.join(addon_path.encode("utf-8"), "machine_guid")).decode('utf-8')
try:
GUID = xbmcvfs.File(GUID_file)

View file

@ -326,7 +326,7 @@ class DownloadUtils():
elif r.status_code == requests.codes.ok:
try:
# UTF-8 - JSON object
# UNICODE - JSON object
r = r.json()
self.logMsg("====== 200 Success ======", 2)
self.logMsg("Response: %s" % r, 2)

View file

@ -990,7 +990,10 @@ def getExtraFanArt():
for backdrop in backdrops:
# Same ordering as in artwork
tag = tags[count]
fanartFile = os.path.join(fanartDir, "fanart%s.jpg" % tag)
if os.path.supports_unicode_filenames:
fanartFile = os.path.join(fanartDir, "fanart%s.jpg" % tag)
else:
fanartFile = os.path.join(fanartDir.encode("utf-8"), "fanart%s.jpg" % tag.encode("utf-8"))
li = xbmcgui.ListItem(tag, path=fanartFile)
xbmcplugin.addDirectoryItem(
handle=int(sys.argv[1]),

View file

@ -2208,8 +2208,10 @@ class Music(Items):
filename = API.getFilePath()
rating = 0
emby_rating = int(round(emby_rating, 0))
file_rating, comment = musicutils.getSongTags(filename)
#get file rating and comment tag from file itself.
#TODO: should we make this an optional setting if it impacts sync speed too much ?
file_rating, comment = musicutils.getSongTags(filename)
emby_dbitem = self.emby_db.getItem_byId(embyid)
try:
@ -2228,7 +2230,6 @@ class Music(Items):
elif file_rating is None and not currentvalue:
return (emby_rating, comment)
file_rating = int(round(file_rating,0))
self.logMsg("getSongRatingAndComment --> embyid: %s - emby_rating: %s - file_rating: %s - current rating in kodidb: %s" %(embyid, emby_rating, file_rating, currentvalue))
updateFileRating = False

View file

@ -72,7 +72,7 @@ class KodiMonitor(xbmc.Monitor):
self.logMsg("Method: %s Data: %s" % (method, data), 1)
if data:
data = json.loads(data)
data = json.loads(data,'utf-8')
if method == "Player.OnPlay":

View file

@ -24,10 +24,16 @@ def getRealFileName(filename):
logMsg( "File does not exist! %s" %(filename), 0)
return (False, "")
#if we use os.path method on older python versions (sunch as some android builds), we need to pass arguments as string
if os.path.supports_unicode_filenames:
checkfile = filename
else:
checkfile = file.encode("utf-8")
# determine if our python module is able to access the file directly...
if os.path.exists(filename):
if os.path.exists(checkfile):
filename = filename
elif os.path.exists(filename.replace("smb://","\\\\").replace("/","\\")):
elif os.path.exists(checkfile.replace("smb://","\\\\").replace("/","\\")):
filename = filename.replace("smb://","\\\\").replace("/","\\")
else:
#file can not be accessed by python directly, we copy it for processing...
@ -57,7 +63,7 @@ def getEmbyRatingFromKodiRating(rating):
def getSongTags(file):
# Get the actual ID3 tags for music songs as the server is lacking that info
rating = None
rating = 0
comment = ""
isTemp,filename = getRealFileName(file)
@ -84,12 +90,13 @@ def getSongTags(file):
else:
logMsg( "Not supported fileformat or unable to access file: %s" %(filename))
if rating:
rating = int(round(rating,0))
#the rating must be a round value
rating = int(round(rating,0))
except Exception as e:
#file in use ?
logMsg("Exception in getSongTags %s" %e,0)
return (None,"")
#remove tempfile if needed....
if isTemp: xbmcvfs.delete(filename)