mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-22 08:53:59 +01:00
Initial commit to add plex tokens. Plex notifications need to be updated to requests, and the get request to the server might need to be cleaned up - but want to make sure it works first
This commit is contained in:
@@ -907,6 +907,10 @@
|
|||||||
<label>Plex Password</label><input type="password" name="plex_password" value="${config['plex_password']}" size="30">
|
<label>Plex Password</label><input type="password" name="plex_password" value="${config['plex_password']}" size="30">
|
||||||
<small>Password of your Plex client API (blank for none)</small>
|
<small>Password of your Plex client API (blank for none)</small>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<label>Plex Token</label><input type="text" name="plex_token" value="${config['plex_token']}" size="30">
|
||||||
|
<small>Plex Token (for use with Plex Home)</small>
|
||||||
|
</div>
|
||||||
<div class="checkbox row">
|
<div class="checkbox row">
|
||||||
<input type="checkbox" name="plex_update" value="1" ${config['plex_update']} /><label>Update Plex Library</label>
|
<input type="checkbox" name="plex_update" value="1" ${config['plex_update']} /><label>Update Plex Library</label>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ _CONFIG_DEFINITIONS = {
|
|||||||
'PLEX_SERVER_HOST': (str, 'Plex', ''),
|
'PLEX_SERVER_HOST': (str, 'Plex', ''),
|
||||||
'PLEX_UPDATE': (int, 'Plex', 0),
|
'PLEX_UPDATE': (int, 'Plex', 0),
|
||||||
'PLEX_USERNAME': (str, 'Plex', ''),
|
'PLEX_USERNAME': (str, 'Plex', ''),
|
||||||
|
'PLEX_TOKEN': (str, 'Plex', ''),
|
||||||
'PREFERRED_BITRATE': (str, 'General', ''),
|
'PREFERRED_BITRATE': (str, 'General', ''),
|
||||||
'PREFERRED_BITRATE_ALLOW_LOSSLESS': (int, 'General', 0),
|
'PREFERRED_BITRATE_ALLOW_LOSSLESS': (int, 'General', 0),
|
||||||
'PREFERRED_BITRATE_HIGH_BUFFER': (int, 'General', 0),
|
'PREFERRED_BITRATE_HIGH_BUFFER': (int, 'General', 0),
|
||||||
|
|||||||
+11
-12
@@ -316,6 +316,7 @@ class Plex(object):
|
|||||||
self.client_hosts = headphones.CONFIG.PLEX_CLIENT_HOST
|
self.client_hosts = headphones.CONFIG.PLEX_CLIENT_HOST
|
||||||
self.username = headphones.CONFIG.PLEX_USERNAME
|
self.username = headphones.CONFIG.PLEX_USERNAME
|
||||||
self.password = headphones.CONFIG.PLEX_PASSWORD
|
self.password = headphones.CONFIG.PLEX_PASSWORD
|
||||||
|
self.token = headphones.CONFIG.PLEX_TOKEN
|
||||||
|
|
||||||
def _sendhttp(self, host, command):
|
def _sendhttp(self, host, command):
|
||||||
|
|
||||||
@@ -354,13 +355,15 @@ class Plex(object):
|
|||||||
for host in hosts:
|
for host in hosts:
|
||||||
logger.info('Sending library update command to Plex Media Server@ ' + host)
|
logger.info('Sending library update command to Plex Media Server@ ' + host)
|
||||||
url = "%s/library/sections" % host
|
url = "%s/library/sections" % host
|
||||||
try:
|
if self.token:
|
||||||
xml_sections = minidom.parse(urllib.urlopen(url))
|
params = {'X-Plex-Token': self.token}
|
||||||
except IOError, e:
|
else:
|
||||||
logger.warn("Error while trying to contact Plex Media Server: %s" % e)
|
params = False
|
||||||
return False
|
|
||||||
|
r = request.request_minidom(url, params=params)
|
||||||
|
|
||||||
|
sections = r.getElementsByTagName('Directory')
|
||||||
|
|
||||||
sections = xml_sections.getElementsByTagName('Directory')
|
|
||||||
if not sections:
|
if not sections:
|
||||||
logger.info(u"Plex Media Server not running on: " + host)
|
logger.info(u"Plex Media Server not running on: " + host)
|
||||||
return False
|
return False
|
||||||
@@ -368,11 +371,7 @@ class Plex(object):
|
|||||||
for s in sections:
|
for s in sections:
|
||||||
if s.getAttribute('type') == "artist":
|
if s.getAttribute('type') == "artist":
|
||||||
url = "%s/library/sections/%s/refresh" % (host, s.getAttribute('key'))
|
url = "%s/library/sections/%s/refresh" % (host, s.getAttribute('key'))
|
||||||
try:
|
request.request_response(url, params=params)
|
||||||
urllib.urlopen(url)
|
|
||||||
except Exception as e:
|
|
||||||
logger.warn("Error updating library section for Plex Media Server: %s" % e)
|
|
||||||
return False
|
|
||||||
|
|
||||||
def notify(self, artist, album, albumartpath):
|
def notify(self, artist, album, albumartpath):
|
||||||
|
|
||||||
@@ -862,4 +861,4 @@ class Email(object):
|
|||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.warn('Error sending Email: %s' % e)
|
logger.warn('Error sending Email: %s' % e)
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -1121,6 +1121,7 @@ class WebInterface(object):
|
|||||||
"plex_client_host": headphones.CONFIG.PLEX_CLIENT_HOST,
|
"plex_client_host": headphones.CONFIG.PLEX_CLIENT_HOST,
|
||||||
"plex_username": headphones.CONFIG.PLEX_USERNAME,
|
"plex_username": headphones.CONFIG.PLEX_USERNAME,
|
||||||
"plex_password": headphones.CONFIG.PLEX_PASSWORD,
|
"plex_password": headphones.CONFIG.PLEX_PASSWORD,
|
||||||
|
"plex_token": headphones.CONFIG.PLEX_TOKEN,
|
||||||
"plex_update": checked(headphones.CONFIG.PLEX_UPDATE),
|
"plex_update": checked(headphones.CONFIG.PLEX_UPDATE),
|
||||||
"plex_notify": checked(headphones.CONFIG.PLEX_NOTIFY),
|
"plex_notify": checked(headphones.CONFIG.PLEX_NOTIFY),
|
||||||
"nma_enabled": checked(headphones.CONFIG.NMA_ENABLED),
|
"nma_enabled": checked(headphones.CONFIG.NMA_ENABLED),
|
||||||
@@ -1432,6 +1433,12 @@ class WebInterface(object):
|
|||||||
result = pushover.notify("hooray!", "This is a test")
|
result = pushover.notify("hooray!", "This is a test")
|
||||||
return str(result)
|
return str(result)
|
||||||
|
|
||||||
|
@cherrypy.expose
|
||||||
|
def testPlex(self):
|
||||||
|
logger.info(u"Testing plex updates")
|
||||||
|
plex = notifiers.Plex()
|
||||||
|
plex.update()
|
||||||
|
|
||||||
class Artwork(object):
|
class Artwork(object):
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def index(self):
|
def index(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user