From 437ffc8337d778a1815424f57e6e8dc69e9bab76 Mon Sep 17 00:00:00 2001 From: Kevin Raddatz Date: Sun, 18 Mar 2018 17:25:25 +0100 Subject: [PATCH] Update plex.py (#12157) * Update plex.py show information about media depending if it is a movie or an episode set time_between_scans to 10 s to match with plex media_player component * Update plex.py lint * Update plex.py linting * Update plex.py linting * Update plex.py linting * Update plex.py added catch for tracks and everything else if no release year is given, instead of () it now show nothing * Update plex.py Remove the album year to match with the Plex UI * Update README.rst * Update README.rst * Update plex.py reformat code to make it more readable recorded tv shows might not have episode numbers assigned -> check before adding to title * Update plex.py cleanup excessive whitespace * Update plex.py cleanup excessive whitespace --- homeassistant/components/sensor/plex.py | 40 ++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/sensor/plex.py b/homeassistant/components/sensor/plex.py index 87af51d2bbd..505983cb3a7 100644 --- a/homeassistant/components/sensor/plex.py +++ b/homeassistant/components/sensor/plex.py @@ -115,9 +115,41 @@ class PlexSensor(Entity): sessions = self._server.sessions() now_playing = [] for sess in sessions: - user = sess.usernames[0] if sess.usernames is not None else "" - title = sess.title if sess.title is not None else "" - year = sess.year if sess.year is not None else "" - now_playing.append((user, "{0} ({1})".format(title, year))) + user = sess.usernames[0] + device = sess.players[0].title + now_playing_user = "{0} - {1}".format(user, device) + now_playing_title = "" + + if sess.TYPE == 'episode': + # example: + # "Supernatural (2005) - S01 · E13 - Route 666" + season_title = sess.grandparentTitle + if sess.show().year is not None: + season_title += " ({0})".format(sess.show().year) + season_episode = "S{0}".format(sess.parentIndex) + if sess.index is not None: + season_episode += " · E{1}".format(sess.index) + episode_title = sess.title + now_playing_title = "{0} - {1} - {2}".format(season_title, + season_episode, + episode_title) + elif sess.TYPE == 'track': + # example: + # "Billy Talent - Afraid of Heights - Afraid of Heights" + track_artist = sess.grandparentTitle + track_album = sess.parentTitle + track_title = sess.title + now_playing_title = "{0} - {1} - {2}".format(track_artist, + track_album, + track_title) + else: + # example: + # "picture_of_last_summer_camp (2015)" + # "The Incredible Hulk (2008)" + now_playing_title = sess.title + if sess.year is not None: + now_playing_title += " ({0})".format(sess.year) + + now_playing.append((now_playing_user, now_playing_title)) self._state = len(sessions) self._now_playing = now_playing