From 671424ecbe571f881406549391f59d2f4daffac0 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Sun, 7 Jan 2018 15:44:20 +0100 Subject: [PATCH] Move PKC Kodi master lock hack to PKC startup --- resources/lib/initialsetup.py | 32 ++++++++++++++++++++++-- resources/lib/librarysync.py | 6 +---- resources/lib/utils.py | 47 ----------------------------------- 3 files changed, 31 insertions(+), 54 deletions(-) diff --git a/resources/lib/initialsetup.py b/resources/lib/initialsetup.py index f0cf9067..4a8f9e83 100644 --- a/resources/lib/initialsetup.py +++ b/resources/lib/initialsetup.py @@ -2,7 +2,7 @@ ############################################################################### from logging import getLogger from Queue import Queue -from xml.etree.ElementTree import ParseError +import xml.etree.ElementTree as etree import xbmc import xbmcgui @@ -416,7 +416,7 @@ class InitialSetup(): xml.set_setting(['videolibrary', 'cleanonupdate'], value='false') reboot = xml.write_xml - except ParseError: + except etree.ParseError: cache = None reboot = False # Kodi default cache if no setting is set @@ -424,6 +424,34 @@ class InitialSetup(): LOG.info('Current Kodi video memory cache in bytes: %s', cache) settings('kodi_video_cache', value=cache) + # Hack to make PKC Kodi master lock compatible + try: + with XmlKodiSetting('sources.xml', + force_create=True, + top_element='sources') as xml: + root = xml.set_setting(['video']) + count = 2 + for source in root.findall('.//path'): + if source.text == "smb://": + count -= 1 + if count == 0: + # sources already set + break + else: + # Missing smb:// occurences, re-add. + for _ in range(0, count): + source = etree.SubElement(root, 'source') + etree.SubElement(source, + 'name').text = "PlexKodiConnect Masterlock Hack" + etree.SubElement(source, + 'path', + attrib={'pathversion': "1"}).text = "smb://" + etree.SubElement(source, 'allowsharing').text = "true" + if reboot is False: + reboot = xml.write_xml + except etree.ParseError: + pass + # Do we need to migrate stuff? check_migration() diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 82f21f4b..f7df635d 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -8,7 +8,7 @@ from random import shuffle import xbmc from xbmcvfs import exists -from utils import window, settings, getUnixTimestamp, sourcesXML,\ +from utils import window, settings, getUnixTimestamp, \ thread_methods, create_actor_db_index, dialog, LogTime, playlistXSP,\ language as lang, DateToKodi, reset, tryDecode, deletePlaylists, \ deleteNodes, tryEncode, compare_version @@ -266,10 +266,6 @@ class LibrarySync(Thread): screensaver = js.get_setting('screensaver.mode') js.set_setting('screensaver.mode', '') if self.new_items_only is True: - # Only do the following once for new items - # Add sources - sourcesXML() - # Set views. Abort if unsuccessful if not self.maintainViews(): xbmc.executebuiltin('InhibitIdleShutdown(false)') diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 68ab881b..990f3f5c 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -785,53 +785,6 @@ class XmlKodiSetting(object): return element -def sourcesXML(): - # To make Master lock compatible - path = tryDecode(xbmc.translatePath("special://profile/")) - xmlpath = "%ssources.xml" % path - - try: - xmlparse = etree.parse(xmlpath) - except IOError: # Document is blank or missing - root = etree.Element('sources') - except etree.ParseError: - log.error('Error parsing %s' % xmlpath) - # "Kodi cannot parse {0}. PKC will not function correctly. Please visit - # {1} and correct your file!" - dialog('ok', language(29999), language(39716).format( - 'sources.xml', 'http://kodi.wiki/view/sources.xml')) - return - else: - root = xmlparse.getroot() - - video = root.find('video') - if video is None: - video = etree.SubElement(root, 'video') - etree.SubElement(video, 'default', attrib={'pathversion': "1"}) - - # Add elements - count = 2 - for source in root.findall('.//path'): - if source.text == "smb://": - count -= 1 - - if count == 0: - # sources already set - break - else: - # Missing smb:// occurences, re-add. - for i in range(0, count): - source = etree.SubElement(video, 'source') - etree.SubElement(source, 'name').text = "Plex" - etree.SubElement(source, 'path', attrib={'pathversion': "1"}).text = "smb://" - etree.SubElement(source, 'allowsharing').text = "true" - # Prettify and write to file - try: - indent(root) - except: pass - etree.ElementTree(root).write(xmlpath, encoding="UTF-8") - - def passwordsXML(): # To add network credentials path = tryDecode(xbmc.translatePath("special://userdata/"))