diff --git a/resources/lib/itemtypes.py b/resources/lib/itemtypes.py index 2375a63c..29e1517d 100644 --- a/resources/lib/itemtypes.py +++ b/resources/lib/itemtypes.py @@ -2055,17 +2055,18 @@ class Music(Items): if doIndirect: # Plex works a bit differently path = "%s%s" % (self.server, item[0][0].attrib.get('key')) - filename = API.addPlexCredentialsToUrl(path) - # Keep path empty to not let Kodi scan it - path = "" + path = API.addPlexCredentialsToUrl(path) + filename = path.rsplit('/', 1)[1] + path = path.replace(filename, '') # UPDATE THE SONG ##### if update_item: self.logMsg("UPDATE song itemid: %s - Title: %s with path: %s" % (itemid, title, path), 1) # Update path - query = "UPDATE path SET strPath = ? WHERE idPath = ?" - kodicursor.execute(query, (path, pathid)) + # Use dummy strHash '123' for Kodi + query = "UPDATE path SET strPath = ?, strHash = ? WHERE idPath = ?" + kodicursor.execute(query, (path, '123', pathid)) # Update the song entry query = ' '.join(( @@ -2087,7 +2088,7 @@ class Music(Items): self.logMsg("ADD song itemid: %s - Title: %s" % (itemid, title), 1) # Add path - pathid = kodi_db.addPath(path) + pathid = kodi_db.addPath(path, strHash="123") try: # Get the album diff --git a/resources/lib/kodidb_functions.py b/resources/lib/kodidb_functions.py index c9dc2011..34021952 100644 --- a/resources/lib/kodidb_functions.py +++ b/resources/lib/kodidb_functions.py @@ -47,7 +47,7 @@ class Kodidb_Functions(): self.clientInfo = clientinfo.ClientInfo() self.artwork = artwork.Artwork() - def addPath(self, path): + def addPath(self, path, strHash=None): # SQL won't return existing paths otherwise if path is None: path = "" @@ -64,15 +64,26 @@ class Kodidb_Functions(): except TypeError: cursor.execute("select coalesce(max(idPath),0) from path") pathid = cursor.fetchone()[0] + 1 - query = ( - ''' - INSERT INTO path( - idPath, strPath) + if strHash is None: + query = ( + ''' + INSERT INTO path( + idPath, strPath) - VALUES (?, ?) - ''' - ) - cursor.execute(query, (pathid, path)) + VALUES (?, ?) + ''' + ) + cursor.execute(query, (pathid, path)) + else: + query = ( + ''' + INSERT INTO path( + idPath, strPath, strHash) + + VALUES (?, ?, ?) + ''' + ) + cursor.execute(query, (pathid, path, strHash)) return pathid diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 179c1835..591f9041 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -638,6 +638,12 @@ class LibrarySync(Thread): # Add sources utils.sourcesXML() + # Deactivate Kodi popup showing that it's (unsuccessfully) trying to + # scan music folders + if self.enableMusic: + utils.musiclibXML() + utils.advancedSettingsXML() + # Set new timestamp NOW because sync might take a while self.saveLastSync() diff --git a/resources/lib/utils.py b/resources/lib/utils.py index f4167133..f8b3d244 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -625,6 +625,85 @@ def indent(elem, level=0): if level and (not elem.tail or not elem.tail.strip()): elem.tail = i + +def musiclibXML(): + """ + 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 advancedSettingsXML(): + """ + Deactivates Kodi popup for scanning of music library + + Changes advancedsettings.xml, musiclibrary: + backgroundupdate set to "true" + """ + path = xbmc.translatePath("special://profile/").decode('utf-8') + xmlpath = "%sadvancedsettings.xml" % path + + try: + xmlparse = etree.parse(xmlpath) + except: + # Document is blank or missing + root = etree.Element('advancedsettings') + else: + root = xmlparse.getroot() + + music = root.find('musiclibrary') + if music is None: + music = etree.SubElement(root, 'musiclibrary') + + 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" + + # Prettify and write to file + try: + indent(root) + except: + pass + etree.ElementTree(root).write(xmlpath) + + def sourcesXML(): # To make Master lock compatible path = xbmc.translatePath("special://profile/").decode('utf-8')