This plugin supports playback from a linked Plex music service. See: https://support.plex.tv/articles/218168898-installing-plex-for-sonos/
- Plex music service must be linked in the Sonos app
- Use of ‘plexapi’ library (https://github.com/pkkid/python-plexapi)
- Plex server URI used in ‘plexapi’ must be reachable from Sonos speakers
>>> from plexapi.server import PlexServer >>> from soco import SoCo >>> from soco.plugins.plex import PlexPlugin >>> >>> s = SoCo("<SPEAKER_IP>") >>> plugin = PlexPlugin(s) >>> >>> plex_uri = "http://184.108.40.206:32400" >>> plex_token = "<YOUR_PLEX_TOKEN>" >>> plex = PlexServer(plex_uri, token=plex_token) >>> music = plex.library.section("Music") >>> artist = music.get("Stevie Wonder") >>> album = artist.album("Innervisions") >>> track = album.tracks() >>> playlist = plex.playlist("My Playlist") >>> >>> plugin.play_now(artist) # Play all tracks from an artist >>> plugin.add_to_queue(track) # Add track to the end of queue >>> pos = plugin.add_to_queue([album, playlist]) # Enqueue multiple >>> s.play_from_queue(pos) # Play items just enqueued
A SoCo plugin for playing Plex media using the plexapi library.
Initialize the plugin.
Return the name of the plugin.
Return the service name of the Plex music service.
Cache and return the service info of the Plex music service.
Return the service ID of the Plex music service.
Return the service type of the Plex music service.
Add the media to the end of the queue and immediately begin playback.
add_to_queue(plex_media, position=0, as_next=False, **kwargs)¶
Add the provided media to the speaker’s playback queue.
- plex_media (plexapi) – The plexapi object representing the Plex media to be enqueued. Can be one of plexapi.audio.Track, plexapi.audio.Album, plexapi.audio.Artist or plexapi.playlist.Playlist. Can also be a list of the above items.
- position (int) – The index (1-based) at which the media should be added. Default is 0 (append to the end of the queue).
- as_next (bool) –
Whether this media should be played as the next track in shuffle mode. This only works if “play_mode=SHUFFLE”.
Note: Enqueuing multi-track items like albums or playlists will select one track randomly as the next item and shuffle the remaining tracks throughout the queue.
The index of the first item added to the queue.