Merge pull request #597 from jjlawren/get_playqueue

Add method to retrieve a PlayQueue
This commit is contained in:
Steffen Fredriksen 2020-12-05 14:13:23 +01:00 committed by GitHub
commit f22fa5694b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 0 deletions

View file

@ -66,6 +66,8 @@ class PlayQueue(PlexObject):
self.selectedItem = self[self.playQueueSelectedItemOffset]
def __getitem__(self, key):
if not self.items:
return None
return self.items[key]
def __len__(self):
@ -93,6 +95,45 @@ class PlayQueue(PlexObject):
else:
raise BadRequest("{item} not valid for this PlayQueue".format(item=item))
@classmethod
def get(
cls,
server,
playQueueID,
own=False,
center=None,
window=50,
includeBefore=True,
includeAfter=True,
):
"""Retrieve an existing :class:`~plexapi.playqueue.PlayQueue` by identifier.
Parameters:
server (:class:`~plexapi.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.
"""
args = {
"own": utils.cast(int, own),
"window": window,
"includeBefore": utils.cast(int, includeBefore),
"includeAfter": utils.cast(int, includeAfter),
}
if center:
args["center"] = center
path = "/playQueues/{playQueueID}{args}".format(playQueueID=playQueueID, args=utils.joinArgs(args))
data = server.query(path, method=server._session.get)
c = cls(server, data, initpath=path)
c._server = server
return c
@classmethod
def create(
cls,

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from plexapi.exceptions import BadRequest
from plexapi.playqueue import PlayQueue
import pytest
@ -138,3 +139,11 @@ def test_create_playqueue_from_playlist(plex, album):
assert len(pq) == 2 * len(playlist)
finally:
playlist.delete()
def test_lookup_playqueue(plex, movie):
pq = PlayQueue.create(plex, movie)
pq_id = pq.playQueueID
pq2 = PlayQueue.get(plex, pq_id)
assert pq.playQueueID == pq2.playQueueID
assert pq.items == pq2.items