Move PKC Kodi master lock hack to PKC startup

This commit is contained in:
tomkat83 2018-01-07 15:44:20 +01:00
parent 36bcd70c9d
commit 671424ecbe
3 changed files with 31 additions and 54 deletions

View file

@ -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()

View file

@ -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)')

View file

@ -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/"))