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 logging import getLogger
from Queue import Queue from Queue import Queue
from xml.etree.ElementTree import ParseError import xml.etree.ElementTree as etree
import xbmc import xbmc
import xbmcgui import xbmcgui
@ -416,7 +416,7 @@ class InitialSetup():
xml.set_setting(['videolibrary', 'cleanonupdate'], xml.set_setting(['videolibrary', 'cleanonupdate'],
value='false') value='false')
reboot = xml.write_xml reboot = xml.write_xml
except ParseError: except etree.ParseError:
cache = None cache = None
reboot = False reboot = False
# Kodi default cache if no setting is set # 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) LOG.info('Current Kodi video memory cache in bytes: %s', cache)
settings('kodi_video_cache', value=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? # Do we need to migrate stuff?
check_migration() check_migration()

View file

@ -8,7 +8,7 @@ from random import shuffle
import xbmc import xbmc
from xbmcvfs import exists 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,\ thread_methods, create_actor_db_index, dialog, LogTime, playlistXSP,\
language as lang, DateToKodi, reset, tryDecode, deletePlaylists, \ language as lang, DateToKodi, reset, tryDecode, deletePlaylists, \
deleteNodes, tryEncode, compare_version deleteNodes, tryEncode, compare_version
@ -266,10 +266,6 @@ class LibrarySync(Thread):
screensaver = js.get_setting('screensaver.mode') screensaver = js.get_setting('screensaver.mode')
js.set_setting('screensaver.mode', '') js.set_setting('screensaver.mode', '')
if self.new_items_only is True: if self.new_items_only is True:
# Only do the following once for new items
# Add sources
sourcesXML()
# Set views. Abort if unsuccessful # Set views. Abort if unsuccessful
if not self.maintainViews(): if not self.maintainViews():
xbmc.executebuiltin('InhibitIdleShutdown(false)') xbmc.executebuiltin('InhibitIdleShutdown(false)')

View file

@ -785,53 +785,6 @@ class XmlKodiSetting(object):
return element 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(): def passwordsXML():
# To add network credentials # To add network credentials
path = tryDecode(xbmc.translatePath("special://userdata/")) path = tryDecode(xbmc.translatePath("special://userdata/"))