From 97c261bc4db4595cf241c124fc763037e40429bf Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Fri, 22 Apr 2016 12:34:35 +0200 Subject: [PATCH] Tune advancedsettings.xml - Only set backgroundupdate to false for music library, if music is enabled --- resources/lib/initialsetup.py | 16 ++++-- resources/lib/librarysync.py | 1 - resources/lib/utils.py | 102 ++++++++++++++++------------------ 3 files changed, 57 insertions(+), 62 deletions(-) diff --git a/resources/lib/initialsetup.py b/resources/lib/initialsetup.py index a7e69597..d80b8c29 100644 --- a/resources/lib/initialsetup.py +++ b/resources/lib/initialsetup.py @@ -281,14 +281,18 @@ class InitialSetup(): line1=string(39016)): self.logMsg("User opted to disable Plex music library.", 1) utils.settings('enableMusic', value="false") + else: + utils.advancedSettingsXML() + if goToSettings is False: + # Open Settings page now? You will need to restart! + goToSettings = dialog.yesno(heading=self.addonName, + line1=string(39017)) if goToSettings: + utils.window('emby_serverStatus', value="Stop") xbmc.executebuiltin( 'Addon.OpenSettings(plugin.video.plexkodiconnect)') else: - # Open Settings page now? You will need to restart! - if dialog.yesno(heading=self.addonName, - line1=string(39017)): - utils.window('emby_serverStatus', value="Stop") - xbmc.executebuiltin( - 'Addon.OpenSettings(plugin.video.plexkodiconnect)') + xbmc.executebuiltin('RestartApp') + # We should always restart to ensure e.g. Kodi settings for Music + # are in use! diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index efe53c33..54e7f378 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -1576,7 +1576,6 @@ class LibrarySync(Thread): log("---===### Starting LibrarySync ###===---", 0) if self.enableMusic: - # utils.musiclibXML() utils.advancedSettingsXML() while not threadStopped(): diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 4c80d938..091a044b 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -615,47 +615,6 @@ def indent(elem, level=0): elem.tail = i -def musiclibXML(): - """ - UNUSED - WORK IN PROGRESS - - Deactivates Kodi trying to scan music library on startup - - Changes guisettings.xml in Kodi userdata folder: - updateonstartup: set to "false" - """ - path = xbmc.translatePath("special://profile/").decode('utf-8') - xmlpath = "%sguisettings.xml" % path - - try: - xmlparse = etree.parse(xmlpath) - except: - # Document is blank or missing - root = etree.Element('settings') - else: - root = xmlparse.getroot() - - music = root.find('musiclibrary') - if music is None: - music = etree.SubElement(root, 'musiclibrary') - - startup = music.find('updateonstartup') - if startup is None: - # Setting does not exist yet; create it - startup = etree.SubElement(music, - 'updateonstartup', - attrib={'default': "true"}).text = "false" - else: - startup.text = "false" - - # Prettify and write to file - try: - indent(root) - except: - pass - etree.ElementTree(root).write(xmlpath) - - def guisettingsXML(): """ Returns special://userdata/guisettings.xml as an etree xml root element @@ -673,14 +632,51 @@ def guisettingsXML(): return root +def __setXMLTag(element, tag, value, attrib=None): + """ + Looks for an element's subelement and sets its value. + If "subelement" does not exist, create it using attrib and value. + + element : etree element + tag : string/unicode for subelement + value : string/unicode + attrib : dict; will use etree attrib method + + Returns the subelement + """ + subelement = element.find(tag) + if subelement is None: + # Setting does not exist yet; create it + if attrib is None: + etree.SubElement(element, tag).text = value + else: + etree.SubElement(element, tag, attrib=attrib).text = value + else: + subelement.text = value + return subelement + + +def __setSubElement(element, subelement): + """ + Returns an etree element's subelement. Creates one if not exist + """ + answ = element.find(subelement) + if answ is None: + answ = etree.SubElement(element, subelement) + return answ + + def advancedSettingsXML(): """ - UNUSED - - Deactivates Kodi popup for scanning of music library + Kodi tweaks Changes advancedsettings.xml, musiclibrary: backgroundupdate set to "true" + + Overrides guisettings.xml in Kodi userdata folder: + updateonstartup : set to "false" + usetags : set to "false" + findremotethumbs : set to "false" """ path = xbmc.translatePath("special://profile/").decode('utf-8') xmlpath = "%sadvancedsettings.xml" % path @@ -693,18 +689,14 @@ def advancedSettingsXML(): else: root = xmlparse.getroot() - music = root.find('musiclibrary') - if music is None: - music = etree.SubElement(root, 'musiclibrary') + music = __setSubElement(root, 'musiclibrary') + __setXMLTag(music, 'backgroundupdate', "true") + # __setXMLTag(music, 'updateonstartup', "false") - backgroundupdate = music.find('backgroundupdate') - if backgroundupdate is None: - # Setting does not exist yet; create it - backgroundupdate = etree.SubElement( - music, - 'backgroundupdate').text = "true" - else: - backgroundupdate.text = "true" + # Subtag 'musicfiles' + # music = __setSubElement(root, 'musicfiles') + # __setXMLTag(music, 'usetags', "false") + # __setXMLTag(music, 'findremotethumbs', "false") # Prettify and write to file try: