Skip to content

Commit 1804fad

Browse files
authored
Create PlayQueue from a radio station key (#877)
* Create PlayQueue from a station key * Rework docstring * Move example into proper code block * Switch to camel case
1 parent ef55158 commit 1804fad

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

plexapi/playqueue.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,42 @@ def create(
195195
c._server = server
196196
return c
197197

198+
@classmethod
199+
def fromStationKey(cls, server, key):
200+
"""Create and return a new :class:`~plexapi.playqueue.PlayQueue`.
201+
202+
This is a convenience method to create a `PlayQueue` for
203+
radio stations when only the `key` string is available.
204+
205+
Parameters:
206+
server (:class:`~plexapi.server.PlexServer`): Server you are connected to.
207+
key (str): A station key as provided by :func:`~plexapi.library.LibrarySection.hubs()`
208+
or :func:`~plexapi.audio.Artist.station()`
209+
210+
Example:
211+
212+
.. code-block:: python
213+
214+
from plexapi.playqueue import PlayQueue
215+
music = server.library.section("Music")
216+
artist = music.get("Artist Name")
217+
station = artist.station()
218+
key = station.key # "/library/metadata/12855/station/8bd39616-dbdb-459e-b8da-f46d0b170af4?type=10"
219+
pq = PlayQueue.fromStationKey(server, key)
220+
client = server.clients()[0]
221+
client.playMedia(pq)
222+
"""
223+
args = {
224+
"type": "audio",
225+
"uri": f"server://{server.machineIdentifier}/{server.library.identifier}{key}"
226+
}
227+
path = f"/playQueues{utils.joinArgs(args)}"
228+
data = server.query(path, method=server._session.post)
229+
c = cls(server, data, initpath=path)
230+
c.playQueueType = args["type"]
231+
c._server = server
232+
return c
233+
198234
def addItem(self, item, playNext=False, refresh=True):
199235
"""
200236
Append the provided item to the "Up Next" section of the PlayQueue.

0 commit comments

Comments
 (0)