@lethic - Test this code out. Follow the instructions with the file I posted earlier. Then rename _get_episode (should be about 2 references found to _get_tv_media and then replace the functions _get_tv_media and _client_play_media (both towards the end of the file) with this:
def _get_tv_media(self, library_name, show_name, season_number,
episode_number):
"""Find TV media and return a Plex media object."""
target_season = None
target_episode = None
show = self.device.server.library.section(library_name).get(
show_name)
if not season_number:
playlist_name = (self.entity_id + ' - ' + show_name + ' Episodes')
return self.device.server.createPlaylist(
playlist_name, show.episodes())
for season in show.seasons():
if int(season.seasonNumber) == int(season_number):
target_season = season
break
if target_season is None:
_LOGGER.error('Season not found: %s\\%s - S%sE%s', library_name,
show_name,
str(season_number).zfill(2),
str(episode_number).zfill(2))
else:
if not episode_number:
playlist_name = (self.entity_id + ' - ' + show_name +
' Season ' + str(season_number) + ' Episodes')
return self.device.server.createPlaylist(
playlist_name, target_season.episodes())
for episode in target_season.episodes():
if int(episode.index) == int(episode_number):
target_episode = episode
break
if target_episode is None:
_LOGGER.error('Episode not found: %s\\%s - S%sE%s',
library_name, show_name,
str(season_number).zfill(2),
str(episode_number).zfill(2))
return target_episode
def _client_play_media(self, media, delete=False, **params):
"""Instruct Plex client to play a piece of media."""
if not (self.device and
'playback' in self._device_protocol_capabilities):
_LOGGER.error('Client cannot play media: %s', self.entity_id)
return
import plexapi.playqueue
playqueue = plexapi.playqueue.PlayQueue.create(self.device.server,
media, **params)
self._local_client_control_fix()
server_url = self.device.server.baseurl.split(':')
self.device.sendCommand('playback/playMedia', **dict({
'machineIdentifier':
self.device.server.machineIdentifier,
'address':
server_url[1].strip('/'),
'port':
server_url[-1],
'key':
media.key,
'containerKey':
'/playQueues/%s?window=100&own=1' % playqueue.playQueueID,
}, **params))
# delete dynamic playlists used to build playqueue (ex. play tv season)
if delete:
media.delete()
Then just call the service like you previously did but leave season_number OR season_number and episode_number blank like this:
{
"entity_id" : "media_player.plex_7b8c4c63_38ff_417d_ac14_0457796ee1c1",
"media_content_id": "{ \"library_name\" : \"Adult TV\", \"show_name\" : \"Rick and Morty\", \"season_number\" : \"\", \"episode_number\" : \"\", \"shuffle\": \"1\" }",
"media_content_type": "EPISODE"
}