2018-09-06 08:36:32 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import xml.etree.ElementTree as etree
|
|
|
|
|
|
|
|
import xbmc
|
|
|
|
|
2018-09-08 03:53:49 +00:00
|
|
|
from . import _, indent, write_xml, dialog, settings
|
2018-09-06 08:36:32 +00:00
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
LOG = logging.getLogger("EMBY."+__name__)
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
def sources():
|
|
|
|
|
|
|
|
''' Create master lock compatible sources.
|
|
|
|
Also add the kodi.emby.media source.
|
|
|
|
'''
|
|
|
|
path = xbmc.translatePath("special://profile/").decode('utf-8')
|
|
|
|
file = os.path.join(path, 'sources.xml')
|
|
|
|
|
|
|
|
try:
|
|
|
|
xml = etree.parse(file).getroot()
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
xml = etree.Element('sources')
|
|
|
|
video = etree.SubElement(xml, 'video')
|
|
|
|
etree.SubElement(video, 'default', attrib={'pathversion': "1"})
|
|
|
|
|
|
|
|
video = xml.find('video')
|
|
|
|
count = 2
|
|
|
|
|
|
|
|
for source in xml.findall('.//path'):
|
|
|
|
if source.text == 'smb://':
|
|
|
|
count -= 1
|
|
|
|
|
|
|
|
if count == 0:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
for i in range(0, count):
|
|
|
|
source = etree.SubElement(video, 'source')
|
|
|
|
etree.SubElement(source, 'name').text = "Emby"
|
|
|
|
etree.SubElement(source, 'path', attrib={'pathversion': "1"}).text = "smb://"
|
|
|
|
etree.SubElement(source, 'allowsharing').text = "true"
|
|
|
|
|
|
|
|
for source in xml.findall('.//path'):
|
|
|
|
if source.text == 'http://kodi.emby.media':
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
source = etree.SubElement(video, 'source')
|
|
|
|
etree.SubElement(source, 'name').text = "kodi.emby.media"
|
|
|
|
etree.SubElement(source, 'path', attrib={'pathversion': "1"}).text = "http://kodi.emby.media"
|
|
|
|
etree.SubElement(source, 'allowsharing').text = "true"
|
|
|
|
|
|
|
|
indent(xml)
|
|
|
|
write_xml(etree.tostring(xml, 'UTF-8'), file)
|
|
|
|
|
|
|
|
def tvtunes_nfo(path, urls):
|
|
|
|
|
|
|
|
''' Create tvtunes.nfo
|
|
|
|
'''
|
|
|
|
try:
|
|
|
|
xml = etree.parse(path).getroot()
|
|
|
|
except Exception:
|
|
|
|
xml = etree.Element('tvtunes')
|
|
|
|
|
|
|
|
for elem in xml.getiterator('tvtunes'):
|
|
|
|
for file in list(elem):
|
|
|
|
elem.remove(file)
|
|
|
|
|
|
|
|
for url in urls:
|
|
|
|
etree.SubElement(xml, 'file').text = url
|
|
|
|
|
|
|
|
indent(xml)
|
|
|
|
write_xml(etree.tostring(xml, 'UTF-8'), path)
|
|
|
|
|
2018-09-07 21:34:14 +00:00
|
|
|
def advanced_settings():
|
2018-09-06 08:36:32 +00:00
|
|
|
|
2018-09-07 21:34:14 +00:00
|
|
|
''' Track the existence of <cleanonupdate>true</cleanonupdate>
|
|
|
|
It is incompatible with plugin paths.
|
|
|
|
'''
|
|
|
|
if settings('useDirectPaths') != "0":
|
|
|
|
return
|
|
|
|
|
|
|
|
path = xbmc.translatePath("special://profile/").decode('utf-8')
|
|
|
|
file = os.path.join(path, 'advancedsettings.xml')
|
2018-09-06 08:36:32 +00:00
|
|
|
|
|
|
|
try:
|
2018-09-07 21:34:14 +00:00
|
|
|
xml = etree.parse(file).getroot()
|
|
|
|
except Exception:
|
2018-09-06 08:36:32 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
video = root.find('videolibrary')
|
2018-09-07 21:34:14 +00:00
|
|
|
|
2018-09-06 08:36:32 +00:00
|
|
|
if video is not None:
|
|
|
|
cleanonupdate = video.find('cleanonupdate')
|
2018-09-07 21:34:14 +00:00
|
|
|
|
2018-09-06 08:36:32 +00:00
|
|
|
if cleanonupdate is not None and cleanonupdate.text == "true":
|
2018-09-07 21:34:14 +00:00
|
|
|
|
|
|
|
LOG.warn("cleanonupdate disabled")
|
2018-09-06 08:36:32 +00:00
|
|
|
video.remove(cleanonupdate)
|
2018-09-07 21:34:14 +00:00
|
|
|
|
|
|
|
indent(xml)
|
|
|
|
write_xml(etree.tostring(xml, 'UTF-8'), path)
|
|
|
|
|
2018-09-08 03:53:49 +00:00
|
|
|
dialog("ok", heading="{emby}", line1=_(33097))
|
2018-09-06 08:36:32 +00:00
|
|
|
xbmc.executebuiltin('RestartApp')
|
2018-09-07 21:34:14 +00:00
|
|
|
|
2018-09-06 08:36:32 +00:00
|
|
|
return True
|