Add Plex play_media logging and troubleshooting tools (#34412)
This commit is contained in:
parent
4fa268ecb4
commit
f922128a14
2 changed files with 36 additions and 12 deletions
|
@ -7,9 +7,12 @@ import requests.exceptions
|
|||
|
||||
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN, MediaPlayerDevice
|
||||
from homeassistant.components.media_player.const import (
|
||||
MEDIA_TYPE_EPISODE,
|
||||
MEDIA_TYPE_MOVIE,
|
||||
MEDIA_TYPE_MUSIC,
|
||||
MEDIA_TYPE_PLAYLIST,
|
||||
MEDIA_TYPE_TVSHOW,
|
||||
MEDIA_TYPE_VIDEO,
|
||||
SUPPORT_NEXT_TRACK,
|
||||
SUPPORT_PAUSE,
|
||||
SUPPORT_PLAY,
|
||||
|
@ -553,27 +556,44 @@ class PlexMediaPlayer(MediaPlayerDevice):
|
|||
def play_media(self, media_type, media_id, **kwargs):
|
||||
"""Play a piece of media."""
|
||||
if not (self.device and "playback" in self._device_protocol_capabilities):
|
||||
_LOGGER.debug(
|
||||
"Client is not currently accepting playback controls: %s", self.name
|
||||
)
|
||||
return
|
||||
|
||||
media_type = media_type.lower()
|
||||
src = json.loads(media_id)
|
||||
library = src.get("library_name")
|
||||
shuffle = src.get("shuffle", 0)
|
||||
if media_type == PLEX_DOMAIN and isinstance(src, int):
|
||||
try:
|
||||
media = self.plex_server.fetch_item(src)
|
||||
except plexapi.exceptions.NotFound:
|
||||
_LOGGER.error("Media for key %s not found", src)
|
||||
return
|
||||
shuffle = 0
|
||||
else:
|
||||
library = src.get("library_name")
|
||||
shuffle = src.get("shuffle", 0)
|
||||
media = None
|
||||
|
||||
media = None
|
||||
|
||||
if media_type == "MUSIC":
|
||||
media = self._get_music_media(library, src)
|
||||
elif media_type == "EPISODE":
|
||||
media = self._get_tv_media(library, src)
|
||||
elif media_type == "PLAYLIST":
|
||||
media = self.plex_server.playlist(src["playlist_name"])
|
||||
elif media_type == "VIDEO":
|
||||
media = self.plex_server.library.section(library).get(src["video_name"])
|
||||
try:
|
||||
if media_type == MEDIA_TYPE_MUSIC:
|
||||
media = self._get_music_media(library, src)
|
||||
elif media_type == MEDIA_TYPE_EPISODE:
|
||||
media = self._get_tv_media(library, src)
|
||||
elif media_type == MEDIA_TYPE_PLAYLIST:
|
||||
media = self.plex_server.playlist(src["playlist_name"])
|
||||
elif media_type == MEDIA_TYPE_VIDEO:
|
||||
media = self.plex_server.library.section(library).get(src["video_name"])
|
||||
except plexapi.exceptions.NotFound:
|
||||
_LOGGER.error("Media could not be found: %s", media_id)
|
||||
return
|
||||
|
||||
if media is None:
|
||||
_LOGGER.error("Media could not be found: %s", media_id)
|
||||
return
|
||||
|
||||
_LOGGER.debug("Attempting to play %s on %s", media, self.name)
|
||||
|
||||
playqueue = self.plex_server.create_playqueue(media, shuffle=shuffle)
|
||||
try:
|
||||
self.device.playMedia(playqueue)
|
||||
|
|
|
@ -332,3 +332,7 @@ class PlexServer:
|
|||
def create_playqueue(self, media, **kwargs):
|
||||
"""Create playqueue on Plex server."""
|
||||
return plexapi.playqueue.PlayQueue.create(self._plex_server, media, **kwargs)
|
||||
|
||||
def fetch_item(self, item):
|
||||
"""Fetch item from Plex server."""
|
||||
return self._plex_server.fetchItem(item)
|
||||
|
|
Loading…
Add table
Reference in a new issue