From 177a5ea78bb793652aeaa98226fe4999165f0dab Mon Sep 17 00:00:00 2001 From: unfledged Date: Fri, 11 Sep 2015 23:22:47 +0100 Subject: [PATCH] Support adding music nodes from library node editor --- default.py | 14 ++++++++++++++ resources/lib/nodefunctions.py | 14 ++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/default.py b/default.py index a5d43640..959b66f4 100644 --- a/default.py +++ b/default.py @@ -136,6 +136,20 @@ def __init__(self): if result == False: # The item failed to add to the menu xbmcgui.dialog().ok( __addon__.getAddonInfo( "name" ), __language__(32091) ) + + if self.TYPE=="addMusicNode": + # We've been sent a node from plugin.program.video.node.editor + targetDir = "library://music" + self.OPTIONS[ 0 ] + + icon = "DefaultShortcut.png" + if self.OPTIONS[ 2 ] != "None": + icon = self.OPTIONS[ 2 ].decode( "utf-8" ) + + result = nodefunctions.NodeFunctions().addNodeToMenu( targetDir, urllib.unquote( self.OPTIONS[ 1 ] ).decode( "utf-8" ), icon, DATA, isVideo = False ) + + if result == False: + # The item failed to add to the menu + xbmcgui.dialog().ok( __addon__.getAddonInfo( "name" ), __language__(32091) ) if self.TYPE=="resetall": # Tell XBMC not to try playing any media diff --git a/resources/lib/nodefunctions.py b/resources/lib/nodefunctions.py index 7bc04e05..90428bdf 100755 --- a/resources/lib/nodefunctions.py +++ b/resources/lib/nodefunctions.py @@ -287,7 +287,7 @@ def get_mediaType( self, path ): # Functions used to add a node to the menu # ############################################ - def addNodeToMenu( self, node, label, icon, DATA ): + def addNodeToMenu( self, node, label, icon, DATA, isVideo = False ): # Get a list of all nodes within json_query = xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "id": 0, "method": "Files.GetDirectory", "params": { "properties": ["title", "file", "thumbnail"], "directory": "' + node + '", "media": "files" } }') json_query = unicode(json_query, 'utf-8', errors='ignore') @@ -332,7 +332,10 @@ def addNodeToMenu( self, node, label, icon, DATA ): xmltree.SubElement( newelement, "label2" ).text = "32024" # Custom shortcut xmltree.SubElement( newelement, "icon" ).text = icon xmltree.SubElement( newelement, "thumb" ) - xmltree.SubElement( newelement, "action" ).text = "ActivateWindow(10025," + paths[ selected ] + ",return)" + if isVideo: + xmltree.SubElement( newelement, "action" ).text = "ActivateWindow(10025," + paths[ selected ] + ",return)" + else: + xmltree.SubElement( newelement, "action" ).text = "ActivateWindow(10502," + paths[ selected ] + ",return)" DATA.indent( menuitems.getroot() ) path = xbmc.translatePath( os.path.join( "special://profile", "addon_data", __addonid__, "mainmenu.DATA.xml" ).encode('utf-8') ) @@ -348,7 +351,10 @@ def addNodeToMenu( self, node, label, icon, DATA ): xmltree.SubElement( newelement, "label2" ).text = "32024" # Custom shortcut xmltree.SubElement( newelement, "icon" ).text = item[ "thumbnail" ] xmltree.SubElement( newelement, "thumb" ) - xmltree.SubElement( newelement, "action" ).text = "ActivateWindow(10025," + item[ "file" ] + ",return)" + if isVideo: + xmltree.SubElement( newelement, "action" ).text = "ActivateWindow(10025," + item[ "file" ] + ",return)" + else: + xmltree.SubElement( newelement, "action" ).text = "ActivateWindow(10502," + item[ "file" ] + ",return)" DATA.indent( menuitems.getroot() ) path = xbmc.translatePath( os.path.join( "special://profile", "addon_data", __addonid__, DATA.slugify( labelID ) + ".DATA.xml" ).encode('utf-8') ) @@ -360,4 +366,4 @@ def addNodeToMenu( self, node, label, icon, DATA ): # And tell the user it all worked xbmcgui.Dialog().ok( __addon__.getAddonInfo( "name" ), __language__(32090) ) - return True \ No newline at end of file + return True