diff --git a/i3pystatus/plexstatus.py b/i3pystatus/plexstatus.py
index 50f5b13..c419139 100644
--- a/i3pystatus/plexstatus.py
+++ b/i3pystatus/plexstatus.py
@@ -6,18 +6,27 @@ from urllib.request import urlopen
class Plexstatus(IntervalModule):
"""
Displays what is currently being streamed from your Plex Media Server.
+
+ If you dont have an apikey you will need to follow this
+ https://support.plex.tv/hc/en-us/articles/204059436-Finding-your-account-token-X-Plex-Token
+
+ .. rubric:: Formatters
+
+ * `{title}` - title currently being streamed
+ * `{platform}` - plex recognised platform of the streamer
+ * `{product}` - plex product name on the streamer (Plex Web, Plex Media Player)
+ * `{address}` - address of the streamer
+ * `{streamer_os}` - operating system on the streaming device
"""
settings = (
- ("apikey", "Your Plex API authentication key "
- "(https://support.plex.tv/hc/en-us/articles/204059436-Finding-your-"
- "account-token-X-Plex-Token) ."),
- ("address", "Hostname or IP address of the Plex Media Server."),
- ("port", "Port which Plex Media Server is running on."),
- ("interval", "Update interval (in seconds)."),
- ("format_no_streams", "String that is shown if nothing is being "
- "streamed."),
- "format"
+ "format",
+ ("apikey", "Your Plex API authentication key"),
+ ("address", "Hostname or IP address of the Plex Media Server"),
+ ("port", "Port which Plex Media Server is running on"),
+ ("interval", "Update interval"),
+ ("stream_divider", "divider between stream info when multiple streams are active"),
+ ("format_no_streams", "String that is shown if nothing is being streamed"),
)
required = ("apikey", "address")
color = "#00FF00" # green
@@ -26,6 +35,7 @@ class Plexstatus(IntervalModule):
interval = 120
format_no_streams = None
format = "{platform}: {title}"
+ stream_divider = '-'
def run(self):
PMS_URL = '%s%s%s%s' % ('http://', self.address, ':', self.port)
@@ -35,29 +45,38 @@ class Plexstatus(IntervalModule):
xml_response = response.read()
tree = ET.fromstring(xml_response)
- cdict = {'title': '',
- 'platform': ''}
-
+ streams = []
for vid in tree.iter('Video'):
+ info = {'title': '',
+ 'platform': '',
+ 'product': '',
+ 'address': '',
+ 'streamer_os': ''}
try:
- cdict['title'] = vid.attrib['title']
- except AttributeError:
- pass
+ info['title'] = vid.attrib['title']
+ except AttributeError as e:
+ self.logger.error(e)
- for play in tree.iter('Player'):
- try:
- cdict['platform'] = play.attrib['platform']
- except AttributeError:
- pass
+ for play in vid.iter('Player'):
+ try:
+ info['platform'] = play.attrib['platform']
+ info['product'] = play.attrib['product']
+ info['address'] = play.attrib['address']
+ info['streamer_os'] = play.attrib['device']
+ except AttributeError as e:
+ self.logger.error(e)
+ streams.append(info)
- self.data = cdict
- if not cdict['title'] or not cdict['platform']:
+ self.data = streams
+
+ if len(streams) < 1:
self.output = {} if not self.format_no_streams else {
- "full_text": self.format_no_stream,
+ "full_text": self.format_no_streams,
"color": self.no_stream_color
}
else:
+ full_text = self.stream_divider.join(self.format.format(**s) for s in streams)
self.output = {
- "full_text": self.format.format(**cdict),
+ "full_text": full_text,
"color": self.color
}
diff --git a/tests/test_plexstatus.py b/tests/test_plexstatus.py
index 5399c62..d7e8dff 100644
--- a/tests/test_plexstatus.py
+++ b/tests/test_plexstatus.py
@@ -24,7 +24,7 @@ STREAM = b'''
-
+
'''