Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Kodi library being empty for PKC direct paths if Kodi Masterlock has been activated #1745

Draft
wants to merge 1 commit into
base: python3-beta
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 2 additions & 40 deletions resources/lib/initialsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from xbmc import executebuiltin

from . import utils
import xml.etree.ElementTree as etree
from . import path_ops
from . import migration
from .downloadutils import DownloadUtils as DU, exceptions
Expand All @@ -14,6 +13,7 @@
from . import json_rpc as js
from . import app
from . import variables as v
from . import sources

###############################################################################

Expand Down Expand Up @@ -454,31 +454,6 @@ def write_pms_to_settings(server):
server['machineIdentifier'], server['ip'], server['port'],
server['scheme'])

@staticmethod
def _add_sources(root, extension):
changed = False
count = 2
for source in root.findall('.//path'):
if source.text == extension:
count -= 1
if count == 0:
# sources already set
break
else:
# Missing smb:// occurences, re-add.
changed = True
for _ in range(0, count):
source = etree.SubElement(root, 'source')
etree.SubElement(
source,
'name').text = "PlexKodiConnect Masterlock Hack"
etree.SubElement(
source,
'path',
{'pathversion': "1"}).text = extension
etree.SubElement(source, 'allowsharing').text = "true"
return changed

def setup(self):
"""
Initial setup. Run once upon startup.
Expand Down Expand Up @@ -520,20 +495,7 @@ def setup(self):
LOG.info('Current Kodi video memory cache in bytes: %s', cache)
utils.settings('kodi_video_cache', value=cache)

# Hack to make PKC Kodi master lock compatible
try:
with utils.XmlKodiSetting('sources.xml',
force_create=True,
top_element='sources') as xml:
changed = False
for extension in ('smb://', 'nfs://'):
root = xml.set_setting(['video'])
changed = self._add_sources(root, extension) or changed
if changed:
xml.write_xml = True
reboot = True
except utils.ParseError:
pass
reboot = sources.pkc_sources_hack() or reboot

# Do we need to migrate stuff?
migration.check_migration()
Expand Down
48 changes: 48 additions & 0 deletions resources/lib/sources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as etree

from . import utils


def pkc_sources_hack():
# Hack to make PKC Kodi master lock compatible
try:
with utils.XmlKodiSetting('sources.xml',
force_create=True,
top_element='sources') as xml:
changed = False
for extension in ('smb://', 'nfs://'):
root = xml.set_setting(['video'])
changed = add_source(root, extension) or changed
if changed:
xml.write_xml = True
except utils.ParseError:
pass
return changed


def add_source(root, source_path):
changed = False
# Originally, 2 sources were necessary for the PKC Masterlock Hack
count = 1
for source in root.findall('.//path'):
if source.text == source_path:
count -= 1
if count == 0:
# sources already set
break
else:
# Missing smb:// occurences, re-add.
changed = True
for _ in range(0, count):
source = etree.SubElement(root, 'source')
etree.SubElement(
source,
'name').text = "PlexKodiConnect Masterlock Hack"
etree.SubElement(
source,
'path',
{'pathversion': "1"}).text = source_path
etree.SubElement(source, 'allowsharing').text = "true"
return changed