Playqueue plexapi.playqueue
- class plexapi.playqueue.PlayQueue(server, data, initpath=None, parent=None)[source]
Bases:
PlexObject
Control a PlayQueue.
- Variables:
TAG (str) – ‘PlayQueue’
TYPE (str) – ‘playqueue’
identifier (str) – com.plexapp.plugins.library
mediaTagPrefix (str) – Fx /system/bundle/media/flags/
mediaTagVersion (int) – Fx 1485957738
playQueueID (int) – ID of the PlayQueue.
playQueueLastAddedItemID (int) – Defines where the “Up Next” region starts. Empty unless PlayQueue is modified after creation.
playQueueSelectedItemID (int) – The queue item ID of the currently selected item.
playQueueSelectedItemOffset (int) – The offset of the selected item in the PlayQueue, from the beginning of the queue.
playQueueSelectedMetadataItemID (int) – ID of the currently selected item, matches ratingKey.
playQueueShuffled (bool) – True if shuffled.
playQueueSourceURI (str) – Original URI used to create the PlayQueue.
playQueueTotalCount (int) – How many items in the PlayQueue.
playQueueVersion (int) – Version of the PlayQueue. Increments every time a change is made to the PlayQueue.
selectedItem (
Playable
) – Media object for the currently selected item._server (
PlexServer
) – PlexServer associated with the PlayQueue.size (int) – Alias for playQueueTotalCount.
- getQueueItem(item)[source]
Accepts a media item and returns a similar object from this PlayQueue. Useful for looking up playQueueItemIDs using items obtained from the Library.
- classmethod get(server, playQueueID, own=False, center=None, window=50, includeBefore=True, includeAfter=True)[source]
Retrieve an existing
PlayQueue
by identifier.- Parameters:
server (
PlexServer
) – Server you are connected to.playQueueID (int) – Identifier of an existing PlayQueue.
own (bool, optional) – If server should transfer ownership.
center (int, optional) – The playQueueItemID of the center of the window. Does not change selectedItem.
window (int, optional) – Number of items to return from each side of the center item.
includeBefore (bool, optional) – Include items before the center, defaults True. Does not include center if False.
includeAfter (bool, optional) – Include items after the center, defaults True. Does not include center if False.
- classmethod create(server, items, startItem=None, shuffle=0, repeat=0, includeChapters=1, includeRelated=1, continuous=0)[source]
Create and return a new
PlayQueue
.- Parameters:
server (
PlexServer
) – Server you are connected to.items (
PlexPartialObject
) – A media item or a list of media items.startItem (
Playable
, optional) – Media item in the PlayQueue where playback should begin.shuffle (int, optional) – Start the playqueue shuffled.
repeat (int, optional) – Start the playqueue shuffled.
includeChapters (int, optional) – include Chapters.
includeRelated (int, optional) – include Related.
continuous (int, optional) – include additional items after the initial item. For a show this would be the next episodes, for a movie it does nothing.
- classmethod fromStationKey(server, key)[source]
Create and return a new
PlayQueue
.This is a convenience method to create a PlayQueue for radio stations when only the key string is available.
- Parameters:
server (
PlexServer
) – Server you are connected to.key (str) – A station key as provided by
hubs()
orstation()
Example
from plexapi.playqueue import PlayQueue music = server.library.section("Music") artist = music.get("Artist Name") station = artist.station() key = station.key # "/library/metadata/12855/station/8bd39616-dbdb-459e-b8da-f46d0b170af4?type=10" pq = PlayQueue.fromStationKey(server, key) client = server.clients()[0] client.playMedia(pq)
- addItem(item, playNext=False, refresh=True)[source]
Append the provided item to the “Up Next” section of the PlayQueue. Items can only be added to the section immediately following the current playing item.
- Parameters:
item (
Playable
orPlaylist
) – Single media item or Playlist.playNext (bool, optional) – If True, add this item to the front of the “Up Next” section. If False, the item will be appended to the end of the “Up Next” section. Only has an effect if an item has already been added to the “Up Next” section. See https://support.plex.tv/articles/202188298-play-queues/ for more details.
refresh (bool, optional) – Refresh the PlayQueue from the server before updating.
- moveItem(item, after=None, refresh=True)[source]
Moves an item to the beginning of the PlayQueue. If after is provided, the item will be placed immediately after the specified item.