Music library

make it seemless - dependant on alternate ip to be enabled to add
pathsubstitution.
This commit is contained in:
angelblue05 2015-08-22 11:17:54 -05:00
parent 64e413b9d1
commit e09c209a6b
5 changed files with 123 additions and 16 deletions

View file

@ -101,13 +101,17 @@ class UserClient(threading.Thread):
def getServer(self, prefix=True):
alternate = utils.settings('altip') == "true"
# For https support
HTTPS = utils.settings('https')
host = utils.settings('ipaddress')
port = utils.settings('port')
# Alternate host
if utils.settings('altip') == "true":
if alternate:
HTTPS = utils.settings('secondhttps')
host = utils.settings('secondipaddress')
port = utils.settings('secondport')
server = host + ":" + port
@ -149,6 +153,8 @@ class UserClient(threading.Thread):
def getSSLverify(self):
# Verify host certificate
s_sslverify = utils.settings('sslverify')
if utils.settings('altip') == "true":
s_sslverify = utils.settings('secondsslverify')
if s_sslverify == "true":
return True
@ -158,6 +164,8 @@ class UserClient(threading.Thread):
def getSSL(self):
# Client side certificate
s_cert = utils.settings('sslcert')
if utils.settings('altip') == "true":
s_cert = utils.settings('secondsslcert')
if s_cert == "None":
return None

View file

@ -15,7 +15,7 @@ import inspect
import sqlite3
import string
import unicodedata
import xml.etree.ElementTree as etree
from API import API
from PlayUtils import PlayUtils
@ -185,6 +185,82 @@ def createSources():
'</sources>'
)
def pathsubstitution(add=True):
path = xbmc.translatePath('special://userdata').decode('utf-8')
xmlpath = "%sadvancedsettings.xml" % path
xmlpathexists = xbmcvfs.exists(xmlpath)
# original address
originalServer = settings('ipaddress')
originalPort = settings('port')
originalHttp = settings('https') == "true"
if originalHttp:
originalHttp = "https"
else:
originalHttp = "http"
# Process add or deletion
if add:
# second address
secondServer = settings('secondipaddress')
secondPort = settings('secondport')
secondHttp = settings('secondhttps') == "true"
if secondHttp:
secondHttp = "https"
else:
secondHttp = "http"
logMsg("EMBY", "Original address: %s://%s:%s, alternate is: %s://%s:%s" % (originalHttp, originalServer, originalPort, secondHttp, secondServer, secondPort), 1)
if xmlpathexists:
# we need to modify the file.
try:
xmlparse = etree.parse(xmlpath)
except: # Document is blank
root = etree.Element('advancedsettings')
else:
root = xmlparse.getroot()
pathsubs = root.find('pathsubstitution')
if pathsubs is None:
pathsubs = etree.SubElement(root, 'pathsubstitution')
else:
# we need to create the file.
root = etree.Element('advancedsettings')
pathsubs = etree.SubElement(root, 'pathsubstitution')
substitute = etree.SubElement(pathsubs, 'substitute')
# From original address
etree.SubElement(substitute, 'from').text = "%s://%s:%s" % (originalHttp, originalServer, originalPort)
# To secondary address
etree.SubElement(substitute, 'to').text = "%s://%s:%s" % (secondHttp, secondServer, secondPort)
etree.ElementTree(root).write(xmlpath)
settings('pathsub', "true")
else: # delete the path substitution, we don't need it anymore.
logMsg("EMBY", "Alternate address is disabled, removing path substitution for: %s://%s:%s" % (originalHttp, originalServer, originalPort), 1)
xmlparse = etree.parse(xmlpath)
root = xmlparse.getroot()
iterator = root.getiterator("pathsubstitution")
for substitutes in iterator:
for substitute in substitutes:
frominsert = substitute.find(".//from").text == "%s://%s:%s" % (originalHttp, originalServer, originalPort)
if frominsert:
# Found a match, in case there's more than one substitution.
substitutes.remove(substitute)
etree.ElementTree(root).write(xmlpath)
settings('pathsub', "false")
def settings(setting, value = None):
# Get or add addon setting
addon = xbmcaddon.Addon()

View file

@ -271,19 +271,23 @@ class WriteKodiMusicDB():
bio = API().getOverview(MBitem)
duration = timeInfo.get('TotalTime')
# Get the path and filename
playurl = PlayUtils().directPlay(MBitem)
try:
if utils.settings('directstreammusic') == "true":
WINDOW = xbmcgui.Window(10000)
username = WINDOW.getProperty('currUser')
server = WINDOW.getProperty('server%s' % username)
playurl = PlayUtils().directStream(MBitem, server, embyId, "Audio")
filename = "stream.mp3"
path = playurl.replace(filename, "")
else:
# Get the path and filename
playurl = PlayUtils().directPlay(MBitem)
path, filename = ntsplit(playurl)
if "/" in playurl:
path = "%s/" % path
elif "\\" in playurl:
path = "%s\\" % path
except: # playurl returned false - using server streaming path, because could not figure out plugin paths for music DB
playurl = PlayUtils().directstream(MBitem, self.server, embyId, "Audio")
filename = "stream.mp3"
path = playurl.replace(filename, "")
# Validate the path in database

View file

@ -2,23 +2,28 @@
<settings>
<category label="30014"> <!-- Emby -->
<setting id="ipaddress" type="text" label="30000" default="" visible="true" enable="true" />
<setting id="altip" type="bool" label="Use alternate address" default="false" visible="true" enable="true" />
<setting id="secondipaddress" type="text" label="Secondary Server Address" default="" visible="eq(-1,true)" enable="true" />
<setting id="https" type="bool" label="30243" visible="true" enable="true" default="false" />
<setting id="port" type="number" label="30030" default="8096" visible="true" enable="true" />
<setting id="username" type="text" label="30024" default="" />
<setting type="sep" />
<setting id="https" type="bool" label="30243" visible="true" enable="true" default="false" />
<setting id="sslverify" type="bool" label="Verify Host SSL Certificate" visible="eq(-1,true)" enable="true" default="false" />
<setting id="sslcert" type="file" label="Client SSL certificate" visible="eq(-2,true)" enable="true" default="None" />
<setting id="altip" type="bool" label="Use alternate address" default="false" visible="true" enable="true" />
<setting id="secondipaddress" type="text" label="Secondary Server Address" default="" visible="eq(-1,true)" enable="true" />
<setting id="secondport" type="number" label="30030" default="8096" visible="eq(-2,true)" enable="true" />
<setting id="secondhttps" type="bool" label="30243" visible="true" enable="eq(-3,true)" default="false" />
<setting id="secondsslverify" type="bool" label="Verify Host SSL Certificate" visible="eq(-1,true)" enable="true" default="false" />
<setting id="secondsslcert" type="file" label="Client SSL certificate" visible="eq(-2,true)" enable="true" default="None" />
<setting id="pathsub" type="bool" visible="false" default="false" />
<setting id="username" type="text" label="30024" default="" />
<setting type="sep" />
<setting id="deviceNameOpt" type="bool" label="Use altername Device Name" visible="true" enable="true" default="true" />
<setting id="deviceName" type="text" label="30016" visible="eq(-1,true)" enable="true" default="Kodi" />
<setting id="accessToken" type="text" visible="false" default="" />
<setting label="[COLOR yellow]Reset login attempts[/COLOR]" type="action" visible="eq(-1,) + !eq(-9,)" enable="true" action="RunPlugin(plugin://plugin.video.emby?mode=resetauth)" option="close" />
</category>
<category label="Sync Options">
<!-- <setting id="syncMovieBoxSets" type="bool" label="30238" default="true" visible="true" enable="true" /> -->
<setting id="dbSyncIndication" type="bool" label="Show sync progress on screen" default="false" visible="true" enable="true" />
<setting id="enableMusicSync" type="bool" label="Enable Music Library Sync" default="true" visible="true" enable="true" />
<setting id="directstreammusic" type="bool" label="- Direct stream music library" default="false" visible="eq(-1,true)" enable="true" />
<setting id="useDirectPaths" type="bool" label="30250" default="false" visible="true" enable="true" />
<setting id="enableTextureCache" type="bool" label="Auto add images to the Kodi texture cache" default="true" visible="true" enable="true" />
<setting id="useIncSync" type="bool" label="Use incremental sync at startup (Requires Server Plugin)" default="false" visible="true" enable="true" />
@ -46,6 +51,5 @@
<setting id="supressConnectMsg" type="bool" label="30249" default="false" visible="true" enable="true" />
<setting id="supressRestartMsg" type="bool" label="Enable server message when it's restarting" default="false" visible="true" enable="true" />
<setting label="30239" type="action" action="RunPlugin(plugin://plugin.video.emby?mode=reset)" />
</category>
</settings>

View file

@ -239,6 +239,21 @@ class Service():
# Abort was requested while waiting. We should exit
break
# If music is enable and direct stream for music is enabled
# We use Kodi pathsubstitution to allow for music to play outside network
# The setting needs to be set before Kodi starts.
if utils.settings('enableMusicSync') == "true" and utils.settings('directstreammusic') == "true":
# We need to keep track of the settings
alternate = utils.settings('altip') == "true"
pathsub = utils.settings('pathsub') == "true"
if pathsub and not alternate:
# Path sub in place, but primary address in use, remove it
utils.pathsubstitution(False)
elif not pathsub and alternate:
# Path sub not in place, but secondary address in use, add it
utils.pathsubstitution()
if (self.newWebSocketThread is not None):
ws.stopClient()