mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-21 00:14:02 +01:00
Fixed plex notifications for version 12
This commit is contained in:
+26
-6
@@ -345,6 +345,19 @@ class Plex(object):
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
def _sendjson(self, host, method, params={}):
|
||||||
|
data = [{'id': 0, 'jsonrpc': '2.0', 'method': method, 'params': params}]
|
||||||
|
headers = {'Content-Type': 'application/json'}
|
||||||
|
url = host + '/jsonrpc'
|
||||||
|
|
||||||
|
if self.password:
|
||||||
|
response = request.request_json(url, method="post", data=json.dumps(data), headers=headers, auth=(self.username, self.password))
|
||||||
|
else:
|
||||||
|
response = request.request_json(url, method="post", data=json.dumps(data), headers=headers)
|
||||||
|
|
||||||
|
if response:
|
||||||
|
return response[0]['result']
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
||||||
# From what I read you can't update the music library on a per directory or per path basis
|
# From what I read you can't update the music library on a per directory or per path basis
|
||||||
@@ -382,17 +395,24 @@ class Plex(object):
|
|||||||
time = "3000" # in ms
|
time = "3000" # in ms
|
||||||
|
|
||||||
for host in hosts:
|
for host in hosts:
|
||||||
logger.info('Sending notification command to Plex Media Server @ ' + host)
|
logger.info('Sending notification command to Plex client @ ' + host)
|
||||||
try:
|
try:
|
||||||
notification = header + "," + message + "," + time + "," + albumartpath
|
version = self._sendjson(host, 'Application.GetProperties', {'properties': ['version']})['version']['major']
|
||||||
notifycommand = {'command': 'ExecBuiltIn', 'parameter': 'Notification(' + notification + ')'}
|
|
||||||
request = self._sendhttp(host, notifycommand)
|
if version < 12: #Eden
|
||||||
|
notification = header + "," + message + "," + time + "," + albumartpath
|
||||||
|
notifycommand = {'command': 'ExecBuiltIn', 'parameter': 'Notification(' + notification + ')'}
|
||||||
|
request = self._sendhttp(host, notifycommand)
|
||||||
|
|
||||||
|
else: #Frodo
|
||||||
|
params = {'title': header, 'message': message, 'displaytime': int(time), 'image': albumartpath}
|
||||||
|
request = self._sendjson(host, 'GUI.ShowNotification', params)
|
||||||
|
|
||||||
if not request:
|
if not request:
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
except:
|
except Exception:
|
||||||
logger.warn('Error sending notification request to Plex Media Server')
|
logger.error('Error sending notification request to Plex client @ ' + host)
|
||||||
|
|
||||||
|
|
||||||
class NMA(object):
|
class NMA(object):
|
||||||
|
|||||||
@@ -1436,9 +1436,9 @@ class WebInterface(object):
|
|||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def testPlex(self):
|
def testPlex(self):
|
||||||
logger.info(u"Testing plex updates")
|
logger.info(u"Testing plex notifications")
|
||||||
plex = notifiers.Plex()
|
plex = notifiers.Plex()
|
||||||
plex.update()
|
plex.notify("hellooooo", "test album!", "")
|
||||||
|
|
||||||
class Artwork(object):
|
class Artwork(object):
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
|
|||||||
Reference in New Issue
Block a user