mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-24 09:46:11 +00:00
Correcting sources
With elementetree instead
This commit is contained in:
parent
c10cee3cb3
commit
5a39208aa3
1 changed files with 54 additions and 33 deletions
|
@ -129,47 +129,68 @@ def stopProfiling(pr, profileName):
|
||||||
f.write(str(ncalls) + "\t" + "{0}".format(total_time) + "\t" + "{0}".format(cumulative_time) + "\t" + func_name + "\t" + filename + "\r\n")
|
f.write(str(ncalls) + "\t" + "{0}".format(total_time) + "\t" + "{0}".format(cumulative_time) + "\t" + func_name + "\t" + filename + "\r\n")
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
def indent(elem, level=0):
|
||||||
|
# Prettify xml trees
|
||||||
|
i = "\n" + level*" "
|
||||||
|
if len(elem):
|
||||||
|
if not elem.text or not elem.text.strip():
|
||||||
|
elem.text = i + " "
|
||||||
|
if not elem.tail or not elem.tail.strip():
|
||||||
|
elem.tail = i
|
||||||
|
for elem in elem:
|
||||||
|
indent(elem, level+1)
|
||||||
|
if not elem.tail or not elem.tail.strip():
|
||||||
|
elem.tail = i
|
||||||
|
else:
|
||||||
|
if level and (not elem.tail or not elem.tail.strip()):
|
||||||
|
elem.tail = i
|
||||||
|
|
||||||
def createSources():
|
def createSources():
|
||||||
# To make Master lock compatible
|
# To make Master lock compatible
|
||||||
path = xbmc.translatePath("special://profile/").decode("utf-8")
|
path = xbmc.translatePath("special://profile/").decode("utf-8")
|
||||||
xmlpath = "%ssources.xml" % path
|
xmlpath = "%ssources.xml" % path
|
||||||
|
|
||||||
if xbmcvfs.exists(xmlpath):
|
if xbmcvfs.exists(xmlpath):
|
||||||
# add some way to writing dummy path to existing sources.xml
|
# Modify the existing file
|
||||||
pass
|
try:
|
||||||
|
xmlparse = etree.parse(xmlpath)
|
||||||
|
except:
|
||||||
|
root = etree.Element('sources')
|
||||||
|
else:
|
||||||
|
root = xmlparse.getroot()
|
||||||
|
|
||||||
|
video = root.find('video')
|
||||||
|
if video is None:
|
||||||
|
video = etree.SubElement(root, 'video')
|
||||||
else:
|
else:
|
||||||
sources = open(xmlpath, 'w')
|
# We need to create the file
|
||||||
sources.write(
|
root = etree.Element('sources')
|
||||||
|
video = etree.SubElement(root, 'video')
|
||||||
'<sources>\n\t'
|
|
||||||
'<programs>\n\t\t'
|
|
||||||
'<default pathversion="1"></default>\n\t'
|
# Add elements
|
||||||
'</programs>\n\t'
|
etree.SubElement(video, 'default', attrib={'pathversion': "1"})
|
||||||
'<video>\n\t\t'
|
|
||||||
'<default pathversion="1"></default>\n\t\t'
|
# First dummy source
|
||||||
'<source>\n\t\t\t'
|
source_one = etree.SubElement(video, 'source')
|
||||||
'<name>Emby</name>\n\t\t\t'
|
etree.SubElement(source_one, 'name').text = "Emby"
|
||||||
'<path pathversion="1">smb://embydummy/dummypath1/</path>\n\t\t\t'
|
etree.SubElement(source_one, 'path', attrib={'pathversion': "1"}).text = (
|
||||||
'<allowsharing>true</allowsharing>\n\t\t'
|
|
||||||
'</source>\n\t\t'
|
"smb://embydummy/dummypath1/"
|
||||||
'<source>\n\t\t\t'
|
|
||||||
'<name>Emby</name>\n\t\t\t'
|
|
||||||
'<path pathversion="1">smb://embydummy/dummypath2/</path>\n\t\t\t'
|
|
||||||
'<allowsharing>true</allowsharing>\n\t\t'
|
|
||||||
'</source>\n\t'
|
|
||||||
'</video>\n\t'
|
|
||||||
'<music>\n\t\t'
|
|
||||||
'<default pathversion="1"></default>\n\t'
|
|
||||||
'</music>\n\t'
|
|
||||||
'<pictures>\n\t\t'
|
|
||||||
'<default pathversion="1"></default>\n\t'
|
|
||||||
'</pictures>\n\t'
|
|
||||||
'<files>\n\t\t'
|
|
||||||
'<default pathversion="1"></default>\n\t'
|
|
||||||
'</files>\n'
|
|
||||||
'</sources>'
|
|
||||||
)
|
)
|
||||||
sources.close()
|
etree.SubElement(source_one, 'allowsharing').text = "true"
|
||||||
|
|
||||||
|
# Second dummy source
|
||||||
|
source_two = etree.SubElement(video, 'source')
|
||||||
|
etree.SubElement(source_two, 'name').text = "Emby"
|
||||||
|
etree.SubElement(source_two, 'path', attrib={'pathversion': "1"}).text = (
|
||||||
|
|
||||||
|
"smb://embydummy/dummypath2/"
|
||||||
|
)
|
||||||
|
etree.SubElement(source_two, 'allowsharing').text = "true"
|
||||||
|
|
||||||
|
indent(root)
|
||||||
|
etree.ElementTree(root).write(xmlpath, method="html")
|
||||||
|
|
||||||
def pathsubstitution(add=True):
|
def pathsubstitution(add=True):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue