Prettify
This commit is contained in:
parent
9496785f5d
commit
92cf5bd517
1 changed files with 45 additions and 21 deletions
|
@ -4,7 +4,7 @@ import string
|
||||||
|
|
||||||
import xbmc
|
import xbmc
|
||||||
|
|
||||||
from utils import logging, tryDecode
|
from utils import logging
|
||||||
import embydb_functions as embydb
|
import embydb_functions as embydb
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,7 +59,9 @@ def getOKMsg():
|
||||||
|
|
||||||
|
|
||||||
def timeToMillis(time):
|
def timeToMillis(time):
|
||||||
return (time['hours']*3600 + time['minutes']*60 + time['seconds'])*1000 + time['milliseconds']
|
return (time['hours']*3600 +
|
||||||
|
time['minutes']*60 +
|
||||||
|
time['seconds'])*1000 + time['milliseconds']
|
||||||
|
|
||||||
|
|
||||||
def millisToTime(t):
|
def millisToTime(t):
|
||||||
|
@ -70,7 +72,10 @@ def millisToTime(t):
|
||||||
seconds = seconds % 60
|
seconds = seconds % 60
|
||||||
minutes = minutes % 60
|
minutes = minutes % 60
|
||||||
millis = millis % 1000
|
millis = millis % 1000
|
||||||
return {'hours':hours,'minutes':minutes,'seconds':seconds,'milliseconds':millis}
|
return {'hours': hours,
|
||||||
|
'minutes': minutes,
|
||||||
|
'seconds': seconds,
|
||||||
|
'milliseconds': millis}
|
||||||
|
|
||||||
|
|
||||||
def textFromXml(element):
|
def textFromXml(element):
|
||||||
|
@ -87,39 +92,55 @@ class jsonClass():
|
||||||
def jsonrpc(self, action, arguments={}):
|
def jsonrpc(self, action, arguments={}):
|
||||||
""" put some JSON together for the JSON-RPC APIv6 """
|
""" put some JSON together for the JSON-RPC APIv6 """
|
||||||
if action.lower() == "sendkey":
|
if action.lower() == "sendkey":
|
||||||
request=json.dumps({ "jsonrpc" : "2.0" , "method" : "Input.SendText", "params" : { "text" : arguments[0], "done" : False }} )
|
request = json.dumps({
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": "Input.SendText",
|
||||||
|
"params": {
|
||||||
|
"text": arguments[0],
|
||||||
|
"done": False
|
||||||
|
}
|
||||||
|
})
|
||||||
elif action.lower() == "ping":
|
elif action.lower() == "ping":
|
||||||
request=json.dumps({ "jsonrpc" : "2.0",
|
request = json.dumps({
|
||||||
"id" : 1 ,
|
"jsonrpc": "2.0",
|
||||||
"method" : "JSONRPC.Ping" })
|
"id": 1,
|
||||||
|
"method": "JSONRPC.Ping"
|
||||||
|
})
|
||||||
elif action.lower() == "playmedia":
|
elif action.lower() == "playmedia":
|
||||||
xbmc.Player().play("plugin://plugin.video.plexkodiconnect/"
|
xbmc.Player().play("plugin://plugin.video.plexkodiconnect/"
|
||||||
"?mode=companion&arguments=%s"
|
"?mode=companion&arguments=%s"
|
||||||
% arguments)
|
% arguments)
|
||||||
return True
|
return True
|
||||||
elif arguments:
|
elif arguments:
|
||||||
request=json.dumps({ "id" : 1,
|
request = json.dumps({
|
||||||
"jsonrpc" : "2.0",
|
"id": 1,
|
||||||
"method" : action,
|
"jsonrpc": "2.0",
|
||||||
"params" : arguments})
|
"method": action,
|
||||||
|
"params": arguments})
|
||||||
else:
|
else:
|
||||||
request=json.dumps({ "id" : 1,
|
request = json.dumps({
|
||||||
"jsonrpc" : "2.0",
|
"id": 1,
|
||||||
"method" : action})
|
"jsonrpc": "2.0",
|
||||||
|
"method": action
|
||||||
|
})
|
||||||
|
|
||||||
result = self.parseJSONRPC(xbmc.executeJSONRPC(request))
|
result = self.parseJSONRPC(xbmc.executeJSONRPC(request))
|
||||||
|
|
||||||
if not result and self.settings['webserver_enabled']:
|
if not result and self.settings['webserver_enabled']:
|
||||||
# xbmc.executeJSONRPC appears to fail on the login screen, but going
|
# xbmc.executeJSONRPC appears to fail on the login screen, but
|
||||||
# through the network stack works, so let's try the request again
|
# going through the network stack works, so let's try the request
|
||||||
|
# again
|
||||||
result = self.parseJSONRPC(self.requestMgr.post(
|
result = self.parseJSONRPC(self.requestMgr.post(
|
||||||
"127.0.0.1",
|
"127.0.0.1",
|
||||||
self.settings['port'],
|
self.settings['port'],
|
||||||
"/jsonrpc",
|
"/jsonrpc",
|
||||||
request,
|
request,
|
||||||
{ 'Content-Type' : 'application/json',
|
{'Content-Type': 'application/json',
|
||||||
'Authorization' : 'Basic ' + string.strip(base64.encodestring(self.settings['user'] + ':' + self.settings['passwd'])) }))
|
'Authorization': 'Basic %s' % string.strip(
|
||||||
|
base64.encodestring('%s:%s'
|
||||||
|
% (self.settings['user'],
|
||||||
|
self.settings['passwd'])))
|
||||||
|
}))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def skipTo(self, plexId, typus):
|
def skipTo(self, plexId, typus):
|
||||||
|
@ -159,7 +180,7 @@ class jsonClass():
|
||||||
self.logMsg("Empty response from XBMC", 1)
|
self.logMsg("Empty response from XBMC", 1)
|
||||||
return {}
|
return {}
|
||||||
else:
|
else:
|
||||||
parsed=json.loads(jsonraw)
|
parsed = json.loads(jsonraw)
|
||||||
if parsed.get('error', False):
|
if parsed.get('error', False):
|
||||||
self.logMsg("XBMC returned an error: %s" % parsed.get('error'), -1)
|
self.logMsg("XBMC returned an error: %s" % parsed.get('error'), -1)
|
||||||
return parsed.get('result', {})
|
return parsed.get('result', {})
|
||||||
|
@ -215,7 +236,10 @@ class jsonClass():
|
||||||
return players.get(xbmc_photo(), {}).get('playerid', None)
|
return players.get(xbmc_photo(), {}).get('playerid', None)
|
||||||
|
|
||||||
def getVolume(self):
|
def getVolume(self):
|
||||||
answ = self.jsonrpc('Application.GetProperties', { "properties": [ "volume", 'muted' ] })
|
answ = self.jsonrpc('Application.GetProperties',
|
||||||
|
{
|
||||||
|
"properties": ["volume", 'muted']
|
||||||
|
})
|
||||||
vol = str(answ.get('volume', 100))
|
vol = str(answ.get('volume', 100))
|
||||||
mute = ("0", "1")[answ.get('muted', False)]
|
mute = ("0", "1")[answ.get('muted', False)]
|
||||||
return (vol, mute)
|
return (vol, mute)
|
||||||
|
|
Loading…
Reference in a new issue