Skip to content

Commit 39bc3a0

Browse files
committed
Add PlexClient createPlayQueue method
1 parent 026414f commit 39bc3a0

2 files changed

Lines changed: 62 additions & 19 deletions

File tree

plexapi/client.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,23 @@ def setVideoStream(self, videoStreamID, mtype=DEFAULT_MTYPE):
481481
"""
482482
self.setStreams(videoStreamID=videoStreamID, mtype=mtype)
483483

484+
def createPlayQueue(self, server, items, **kwargs):
485+
""" Create a playqueue and start playback of the specified media item.
486+
487+
Parameters:
488+
server (:class:`~plexapi.server.PlexServer`): Server you are connected to.
489+
items (:class:`~plexapi.base.PlexPartialObject`):
490+
A media item or a list of media items.
491+
**kwargs (dict): Additional options to apply to the playqueue.
492+
See :func:`~plexapi.playqueue.PlayQueue.create` for available parameters.
493+
"""
494+
args = PlayQueue._createArgs(server=server, items=items, **kwargs)
495+
self.sendCommand("playback/createPlayQueue", **args)
496+
484497
def playMedia(self, media, offset=0, **params):
485-
""" Start playback of the specified media item. See also:
498+
""" Start playback of the specified media item.
499+
Note: This is a legacy command for older clients.
500+
Use :func:`~plexapi.client.PlexClient.createPlayQueue` instead for modern clients.
486501
487502
Parameters:
488503
media (:class:`~plexapi.media.Media`): Media item to be played back

plexapi/playqueue.py

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,8 @@ def get(
136136
c._server = server
137137
return c
138138

139-
@classmethod
140-
def create(
141-
cls,
139+
@staticmethod
140+
def _createArgs(
142141
server,
143142
items,
144143
startItem=None,
@@ -147,28 +146,15 @@ def create(
147146
includeChapters=1,
148147
includeRelated=1,
149148
continuous=0,
149+
**kwargs
150150
):
151-
"""Create and return a new :class:`~plexapi.playqueue.PlayQueue`.
152-
153-
Parameters:
154-
server (:class:`~plexapi.server.PlexServer`): Server you are connected to.
155-
items (:class:`~plexapi.base.PlexPartialObject`):
156-
A media item or a list of media items.
157-
startItem (:class:`~plexapi.base.Playable`, optional):
158-
Media item in the PlayQueue where playback should begin.
159-
shuffle (int, optional): Start the playqueue shuffled.
160-
repeat (int, optional): Start the playqueue shuffled.
161-
includeChapters (int, optional): include Chapters.
162-
includeRelated (int, optional): include Related.
163-
continuous (int, optional): include additional items after the initial item.
164-
For a show this would be the next episodes, for a movie it does nothing.
165-
"""
166151
args = {
167152
"includeChapters": includeChapters,
168153
"includeRelated": includeRelated,
169154
"repeat": repeat,
170155
"shuffle": shuffle,
171156
"continuous": continuous,
157+
**kwargs
172158
}
173159

174160
if isinstance(items, list):
@@ -187,6 +173,48 @@ def create(
187173
if startItem:
188174
args["key"] = startItem.key
189175

176+
return args
177+
178+
@classmethod
179+
def create(
180+
cls,
181+
server,
182+
items,
183+
startItem=None,
184+
shuffle=0,
185+
repeat=0,
186+
includeChapters=1,
187+
includeRelated=1,
188+
continuous=0,
189+
**kwargs
190+
):
191+
"""Create and return a new :class:`~plexapi.playqueue.PlayQueue`.
192+
193+
Parameters:
194+
server (:class:`~plexapi.server.PlexServer`): Server you are connected to.
195+
items (:class:`~plexapi.base.PlexPartialObject`):
196+
A media item or a list of media items.
197+
startItem (:class:`~plexapi.base.Playable`, optional):
198+
Media item in the PlayQueue where playback should begin.
199+
shuffle (int, optional): Start the playqueue shuffled.
200+
repeat (int, optional): Start the playqueue shuffled.
201+
includeChapters (int, optional): include Chapters.
202+
includeRelated (int, optional): include Related.
203+
continuous (int, optional): include additional items after the initial item.
204+
For a show this would be the next episodes, for a movie it does nothing.
205+
**kwargs (dict): Additional options to apply to the playqueue.
206+
"""
207+
args = cls._createArgs(
208+
server=server,
209+
items=items,
210+
startItem=startItem,
211+
shuffle=shuffle,
212+
repeat=repeat,
213+
includeChapters=includeChapters,
214+
includeRelated=includeRelated,
215+
continuous=continuous,
216+
**kwargs
217+
)
190218
path = f"/playQueues{utils.joinArgs(args)}"
191219
data = server.query(path, method=server._session.post)
192220
c = cls(server, data, initpath=path)

0 commit comments

Comments
 (0)