Allow non-ASCI library names

This commit is contained in:
tomkat83 2016-03-07 15:31:07 +01:00
parent c0f2067856
commit dc2ae721e6
2 changed files with 30 additions and 29 deletions

View file

@ -418,8 +418,8 @@ def reset():
addon = xbmcaddon.Addon() addon = xbmcaddon.Addon()
addondir = xbmc.translatePath(addon.getAddonInfo('profile')).decode('utf-8') addondir = xbmc.translatePath(addon.getAddonInfo('profile')).decode('utf-8')
dataPath = "%ssettings.xml" % addondir dataPath = "%ssettings.xml" % addondir
xbmcvfs.delete(dataPath) xbmcvfs.delete(dataPath.encode('utf-8'))
logMsg("EMBY", "Deleting: settings.xml", 1) logMsg("PLEX", "Deleting: settings.xml", 1)
dialog.ok( dialog.ok(
heading="Emby for Kodi", heading="Emby for Kodi",
@ -676,9 +676,9 @@ def passwordsXML():
sound=False) sound=False)
def playlistXSP(mediatype, tagname, viewid, viewtype="", delete=False): def playlistXSP(mediatype, tagname, viewid, viewtype="", delete=False):
# Tagname is in unicode - actions: add or delete """
tagname = tagname.encode('utf-8') Feed with tagname as unicode
"""
path = xbmc.translatePath("special://profile/playlists/video/").decode('utf-8') path = xbmc.translatePath("special://profile/playlists/video/").decode('utf-8')
if viewtype == "mixed": if viewtype == "mixed":
plname = "%s - %s" % (tagname, mediatype) plname = "%s - %s" % (tagname, mediatype)
@ -688,15 +688,15 @@ def playlistXSP(mediatype, tagname, viewid, viewtype="", delete=False):
xsppath = "%sPlex %s.xsp" % (path, viewid) xsppath = "%sPlex %s.xsp" % (path, viewid)
# Create the playlist directory # Create the playlist directory
if not xbmcvfs.exists(path): if not xbmcvfs.exists(path.encode('utf-8')):
logMsg("PLEX", "Creating directory: %s" % path, 1) logMsg("PLEX", "Creating directory: %s" % path, 1)
xbmcvfs.mkdirs(path) xbmcvfs.mkdirs(path.encode('utf-8'))
# Only add the playlist if it doesn't already exists # Only add the playlist if it doesn't already exists
if xbmcvfs.exists(xsppath): if xbmcvfs.exists(xsppath.encode('utf-8')):
logMsg('Path %s does exist' % xsppath, 1)
if delete: if delete:
xbmcvfs.delete(xsppath) xbmcvfs.delete(xsppath.encode('utf-8'))
logMsg("PLEX", "Successfully removed playlist: %s." % tagname, 1) logMsg("PLEX", "Successfully removed playlist: %s." % tagname, 1)
return return
@ -707,21 +707,22 @@ def playlistXSP(mediatype, tagname, viewid, viewtype="", delete=False):
} }
logMsg("Plex", "Writing playlist file to: %s" % xsppath, 1) logMsg("Plex", "Writing playlist file to: %s" % xsppath, 1)
try: try:
f = xbmcvfs.File(xsppath, 'w') f = xbmcvfs.File(xsppath.encode('utf-8'), 'wb')
except: except:
logMsg("Plex", "Failed to create playlist: %s" % xsppath, -1) logMsg("Plex", "Failed to create playlist: %s" % xsppath, -1)
return return
else: else:
f.write( f.write((
'<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>\n' '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>\n'
'<smartplaylist type="%s">\n\t' '<smartplaylist type="%s">\n\t'
'<name>Plex %s</name>\n\t' '<name>Plex %s</name>\n\t'
'<match>all</match>\n\t' '<match>all</match>\n\t'
'<rule field="tag" operator="is">\n\t\t' '<rule field="tag" operator="is">\n\t\t'
'<value>%s</value>\n\t' '<value>%s</value>\n\t'
'</rule>' '</rule>\n'
'</smartplaylist>' '</smartplaylist>'
% (itemtypes.get(mediatype, mediatype), plname, tagname)) % (itemtypes.get(mediatype, mediatype), plname, tagname))
.encode('utf-8'))
f.close() f.close()
logMsg("Plex", "Successfully added playlist: %s" % tagname) logMsg("Plex", "Successfully added playlist: %s" % tagname)
@ -729,26 +730,26 @@ def deletePlaylists():
# Clean up the playlists # Clean up the playlists
path = xbmc.translatePath("special://profile/playlists/video/").decode('utf-8') path = xbmc.translatePath("special://profile/playlists/video/").decode('utf-8')
dirs, files = xbmcvfs.listdir(path) dirs, files = xbmcvfs.listdir(path.encode('utf-8'))
for file in files: for file in files:
if file.decode('utf-8').startswith('Emby'): if file.decode('utf-8').startswith('Plex'):
xbmcvfs.delete("%s%s" % (path, file)) xbmcvfs.delete(("%s%s" % (path, file.decode('utf-8'))).encode('utf-8'))
def deleteNodes(): def deleteNodes():
# Clean up video nodes # Clean up video nodes
import shutil import shutil
path = xbmc.translatePath("special://profile/library/video/").decode('utf-8') path = xbmc.translatePath("special://profile/library/video/").decode('utf-8')
dirs, files = xbmcvfs.listdir(path) dirs, files = xbmcvfs.listdir(path.encode('utf-8'))
for dir in dirs: for dir in dirs:
if dir.decode('utf-8').startswith('Emby'): if dir.decode('utf-8').startswith('Plex'):
try: try:
shutil.rmtree("%s%s" % (path, dir.decode('utf-8'))) shutil.rmtree("%s%s" % (path, dir.decode('utf-8')))
except: except:
logMsg("EMBY", "Failed to delete directory: %s" % dir.decode('utf-8')) logMsg("PLEX", "Failed to delete directory: %s" % dir.decode('utf-8'))
for file in files: for file in files:
if file.decode('utf-8').startswith('emby'): if file.decode('utf-8').startswith('plex'):
try: try:
xbmcvfs.delete("%s%s" % (path, file.decode('utf-8'))) xbmcvfs.delete(("%s%s" % (path, file.decode('utf-8'))).encode('utf-8'))
except: except:
logMsg("EMBY", "Failed to file: %s" % file.decode('utf-8')) logMsg("PLEX", "Failed to file: %s" % file.decode('utf-8'))

View file

@ -65,21 +65,21 @@ class VideoNodes(object):
"special://profile/library/video/Plex-%s/" % dirname).decode('utf-8') "special://profile/library/video/Plex-%s/" % dirname).decode('utf-8')
# Verify the video directory # Verify the video directory
if not xbmcvfs.exists(path): if not xbmcvfs.exists(path.encode('utf-8')):
shutil.copytree( shutil.copytree(
src=xbmc.translatePath("special://xbmc/system/library/video").decode('utf-8'), src=xbmc.translatePath("special://xbmc/system/library/video").decode('utf-8'),
dst=xbmc.translatePath("special://profile/library/video").decode('utf-8')) dst=xbmc.translatePath("special://profile/library/video").decode('utf-8'))
xbmcvfs.exists(path) xbmcvfs.exists(path.encode('utf-8'))
# Create the node directory # Create the node directory
if not xbmcvfs.exists(nodepath) and not mediatype == "photo": if not xbmcvfs.exists(nodepath.encode('utf-8')) and not mediatype == "photo":
# We need to copy over the default items # We need to copy over the default items
xbmcvfs.mkdirs(nodepath) xbmcvfs.mkdirs(nodepath.encode('utf-8'))
else: else:
if delete: if delete:
dirs, files = xbmcvfs.listdir(nodepath) dirs, files = xbmcvfs.listdir(nodepath.encode('utf-8'))
for file in files: for file in files:
xbmcvfs.delete(nodepath + file) xbmcvfs.delete((nodepath + file).encode('utf-8'))
self.logMsg("Sucessfully removed videonode: %s." % tagname, 1) self.logMsg("Sucessfully removed videonode: %s." % tagname, 1)
return return
@ -239,7 +239,7 @@ class VideoNodes(object):
# To do: add our photos nodes to kodi picture sources somehow # To do: add our photos nodes to kodi picture sources somehow
continue continue
if xbmcvfs.exists(nodeXML): if xbmcvfs.exists(nodeXML.encode('utf-8')):
# Don't recreate xml if already exists # Don't recreate xml if already exists
continue continue