1 """Models to represent various Plex objects used in the integration."""
9 LIVE_TV_SECTION =
"Live TV"
10 TRANSIENT_SECTION =
"Preroll"
11 UNKNOWN_SECTION =
"Unknown"
13 -2: TRANSIENT_SECTION,
17 _LOGGER = logging.getLogger(__name__)
21 """Represents a Plex playback session."""
24 """Initialize the object."""
47 self.
playerplayer = next(iter(session.players),
None)
52 self.
usernameusername = next(iter(session.usernames),
None)
57 self.
sensor_usersensor_user =
" - ".join(filter(
None, sensor_user_list))
62 """Return representation of the session."""
63 return f
"<{self.session_key}:{self.sensor_title}>"
66 """Update attributes from a media object."""
76 if media.librarySectionID
in SPECIAL_SECTIONS:
78 elif media.librarySectionID
and media.librarySectionID < 1:
82 "Unknown library section ID (%s) for title '%s',"
83 " please create an issue"
85 media.librarySectionID,
90 media.section().title
if media.librarySectionID
is not None else ""
93 if media.type ==
"episode":
97 if media.index
is not None:
100 f
"{self.media_series_title} -"
101 f
" {media.seasonEpisode} -"
102 f
" {self.media_title}"
104 elif media.type ==
"movie":
106 if media.year
is not None and media.title
is not None:
107 self.
media_titlemedia_title += f
" ({media.year!s})"
109 elif media.type ==
"track":
116 f
"{self.media_artist} - {self.media_album_name} - {self.media_title}"
118 elif media.type ==
"clip":
126 """Return the current playback position."""
129 @media_position.setter
131 """Set the current playback position."""
136 """Get the image URL from a media object."""
137 thumb_url = media.thumbUrl
138 if media.type ==
"episode" and not self.
plex_serverplex_server.option_use_episode_art:
139 if SPECIAL_SECTIONS.get(media.librarySectionID) == LIVE_TV_SECTION:
140 thumb_url = media.grandparentThumb
142 thumb_url = media.url(media.grandparentThumb)
144 if thumb_url
is None:
145 thumb_url = media.url(media.art)
151 """Represents results from a Plex media media_content_id search.
153 Results are used by media_player.play_media implementations.
157 """Initialize the result."""
163 """Provide the appropriate offset in ms based on payload contents."""
164 if offset := self.
_params_params.
get(
"offset", 0):
166 resume = self.
_params_params.
get(
"resume",
False)
167 if isinstance(resume, str):
170 return self.
mediamedia.viewOffset
175 """Return value of shuffle parameter."""
176 shuffle = self.
_params_params.
get(
"shuffle",
False)
177 if isinstance(shuffle, str):
def __init__(self, plex_server, session)
media_position_updated_at
def media_position(self, offset)
def update_media(self, media)
def get_media_image_url(self, media)
web.Response get(self, web.Request request, str config_key)
bool result_as_boolean(Any|None template_result)