Handle Plex Live TV sessions (#36919)

pull/36942/head
jjlawren 2020-06-19 10:12:47 -05:00 committed by GitHub
parent e4df0481da
commit d445c16697
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 12 deletions

View File

@ -36,6 +36,8 @@ from .const import (
SERVERS,
)
LIVE_TV_SECTION = "-4"
_LOGGER = logging.getLogger(__name__)
@ -246,17 +248,23 @@ class PlexMediaPlayer(MediaPlayerEntity):
if self._is_player_active and self.session is not None:
self._session_type = self.session.type
self._media_duration = int(self.session.duration / 1000)
if self.session.duration:
self._media_duration = int(self.session.duration / 1000)
else:
self._media_duration = None
# title (movie name, tv episode name, music song name)
self._media_summary = self.session.summary
self._media_title = self.session.title
# media type
self._set_media_type()
self._app_name = (
self.session.section().title
if self.session.section() is not None
else ""
)
if self.session.librarySectionID == LIVE_TV_SECTION:
self._app_name = "Live TV"
else:
self._app_name = (
self.session.section().title
if self.session.section() is not None
else ""
)
self._set_media_image()
else:
self._session_type = None
@ -267,7 +275,10 @@ class PlexMediaPlayer(MediaPlayerEntity):
self.media_content_type is MEDIA_TYPE_TVSHOW
and not self.plex_server.option_use_episode_art
):
thumb_url = self.session.url(self.session.grandparentThumb)
if self.session.librarySectionID == LIVE_TV_SECTION:
thumb_url = self.session.grandparentThumb
else:
thumb_url = self.session.url(self.session.grandparentThumb)
if thumb_url is None:
_LOGGER.debug(
@ -301,7 +312,7 @@ class PlexMediaPlayer(MediaPlayerEntity):
self._media_series_title = self.session.grandparentTitle
# episode number (00)
if self.session.index is not None:
self._media_episode = str(self.session.index).zfill(2)
self._media_episode = self.session.index
elif self._session_type == "movie":
self._media_content_type = MEDIA_TYPE_MOVIE

View File

@ -87,14 +87,19 @@ class PlexSensor(Entity):
# "Supernatural (2005) - s01e13 - Route 666"
def sync_io_attributes(session):
return (session.show(), session.seasonEpisode)
year = None
try:
year = session.show().year
except TypeError:
pass
return (year, session.seasonEpisode)
show, season_episode = await self.hass.async_add_executor_job(
year, season_episode = await self.hass.async_add_executor_job(
sync_io_attributes, sess
)
season_title = sess.grandparentTitle
if show.year is not None:
season_title += f" ({show.year!s})"
if year is not None:
season_title += f" ({year!s})"
episode_title = sess.title
now_playing_title = (
f"{season_title} - {season_episode} - {episode_title}"

View File

@ -249,6 +249,11 @@ class MockPlexSession:
"""Mock the duration attribute."""
return 10000000
@property
def librarySectionID(self):
"""Mock the librarySectionID attribute."""
return 1
@property
def ratingKey(self):
"""Mock the ratingKey attribute."""