From 81ea279319d7d95ec1579f1e63cd7aa1612a6a7d Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Tue, 23 Feb 2016 00:00:24 -0600 Subject: [PATCH] Create video nodes/playlist using the id Prevent errors with special characters that have no ascii replacement --- resources/lib/librarysync.py | 28 ++++++++++++++++++---------- resources/lib/utils.py | 8 ++++---- resources/lib/videonodes.py | 13 ++++++------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 2a9f3755..3b966ece 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -392,6 +392,7 @@ class LibrarySync(threading.Thread): for mediatype in mediatypes: nodes = [] # Prevent duplicate for nodes of the same type + playlists = [] # Prevent duplicate for playlists of the same type # Get media folders from server folders = self.emby.getViews(mediatype, root=True) for folder in folders: @@ -422,12 +423,14 @@ class LibrarySync(threading.Thread): self.logMsg("Creating viewid: %s in Emby database." % folderid, 1) tagid = kodi_db.createTag(foldername) # Create playlist for the video library - if mediatype in ('movies', 'tvshows', 'musicvideos'): - utils.playlistXSP(mediatype, foldername, viewtype) + if (foldername not in playlists and + mediatype in ('movies', 'tvshows', 'musicvideos')): + utils.playlistXSP(mediatype, foldername, folderid, viewtype) + playlists.append(foldername) # Create the video node if (foldername not in nodes and mediatype in ('movies', 'tvshows', 'musicvideos', 'homevideos')): - vnodes.viewNode(totalnodes, foldername, mediatype, viewtype) + vnodes.viewNode(totalnodes, foldername, mediatype, viewtype, folderid) nodes.append(foldername) totalnodes += 1 # Add view to emby database @@ -454,7 +457,7 @@ class LibrarySync(threading.Thread): # The tag could be a combined view. Ensure there's no other tags # with the same name before deleting playlist. utils.playlistXSP( - mediatype, current_viewname, current_viewtype, True) + mediatype, current_viewname, folderid, current_viewtype, True) # Delete video node if mediatype != "musicvideos": vnodes.viewNode( @@ -462,14 +465,17 @@ class LibrarySync(threading.Thread): tagname=current_viewname, mediatype=mediatype, viewtype=current_viewtype, + viewid=folderid, delete=True) # Added new playlist - if mediatype in ('movies', 'tvshows', 'musicvideos'): - utils.playlistXSP(mediatype, foldername, viewtype) + if (foldername not in playlists and + mediatype in ('movies', 'tvshows', 'musicvideos')): + utils.playlistXSP(mediatype, foldername, folderid, viewtype) + playlists.append(foldername) # Add new video node if (foldername not in nodes and mediatype in ('movies', 'tvshows', 'musicvideos', 'homevideos')): - vnodes.viewNode(totalnodes, foldername, mediatype, viewtype) + vnodes.viewNode(totalnodes, foldername, mediatype, viewtype, folderid) nodes.append(foldername) totalnodes += 1 @@ -481,12 +487,14 @@ class LibrarySync(threading.Thread): current_tagid, tagid, item[0], current_viewtype[:-1]) else: # Validate the playlist exists or recreate it - if mediatype in ('movies', 'tvshows', 'musicvideos'): - utils.playlistXSP(mediatype, foldername, viewtype) + if (foldername not in playlists and + mediatype in ('movies', 'tvshows', 'musicvideos')): + utils.playlistXSP(mediatype, foldername, folderid, viewtype) + playlists.append(foldername) # Create the video node if not already exists if (foldername not in nodes and mediatype in ('movies', 'tvshows', 'musicvideos', 'homevideos')): - vnodes.viewNode(totalnodes, foldername, mediatype, viewtype) + vnodes.viewNode(totalnodes, foldername, mediatype, viewtype, folderid) nodes.append(foldername) totalnodes += 1 else: diff --git a/resources/lib/utils.py b/resources/lib/utils.py index a83fb48b..9c0b9a03 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -449,17 +449,17 @@ def passwordsXML(): time=1000, sound=False) -def playlistXSP(mediatype, tagname, viewtype="", delete=False): +def playlistXSP(mediatype, tagname, viewid, viewtype="", delete=False): # Tagname is in unicode - actions: add or delete tagname = tagname.encode('utf-8') - cleantagname = normalize_nodes(tagname) + path = xbmc.translatePath("special://profile/playlists/video/").decode('utf-8') if viewtype == "mixed": plname = "%s - %s" % (tagname, mediatype) - xsppath = "%sEmby %s - %s.xsp" % (path, cleantagname, mediatype) + xsppath = "%sEmby %s - %s.xsp" % (path, viewid, mediatype) else: plname = tagname - xsppath = "%sEmby %s.xsp" % (path, cleantagname) + xsppath = "%sEmby %s.xsp" % (path, viewid) # Create the playlist directory if not xbmcvfs.exists(path): diff --git a/resources/lib/videonodes.py b/resources/lib/videonodes.py index 75d8ba64..53c18385 100644 --- a/resources/lib/videonodes.py +++ b/resources/lib/videonodes.py @@ -52,16 +52,15 @@ class VideoNodes(object): return root - def viewNode(self, indexnumber, tagname, mediatype, viewtype, delete=False): + def viewNode(self, indexnumber, tagname, mediatype, viewtype, viewid, delete=False): window = utils.window kodiversion = self.kodiversion - cleantagname = utils.normalize_nodes(tagname.encode('utf-8')) if viewtype == "mixed": - dirname = "%s - %s" % (cleantagname, mediatype) + dirname = "%s - %s" % (viewid, mediatype) else: - dirname = cleantagname + dirname = viewid path = xbmc.translatePath("special://profile/library/video/").decode('utf-8') nodepath = xbmc.translatePath( @@ -182,7 +181,7 @@ class VideoNodes(object): for node in nodes: nodetype = nodetypes[node] - nodeXML = "%s%s_%s.xml" % (nodepath, cleantagname, nodetype) + nodeXML = "%s%s_%s.xml" % (nodepath, viewid, nodetype) # Get label stringid = nodes[node] if node != "1": @@ -211,7 +210,7 @@ class VideoNodes(object): # Custom query path = "plugin://plugin.video.emby/?id=%s&mode=inprogressepisodes&limit=25"% tagname else: - path = "library://video/Emby - %s/%s_%s.xml" % (dirname, cleantagname, nodetype) + path = "library://video/Emby - %s/%s_%s.xml" % (dirname, viewid, nodetype) if mediatype == "photos": windowpath = "ActivateWindow(Pictures,%s,return)" % path @@ -221,7 +220,7 @@ class VideoNodes(object): if nodetype == "all": if viewtype == "mixed": - templabel = dirname + templabel = "%s - %s" % (tagname, mediatype) else: templabel = label