Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions plexapi/playqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def _loadData(self, data):
self.selectedItem = self[self.playQueueSelectedItemOffset]

def __getitem__(self, key):
if not self.items:
return None
return self.items[key]

def __len__(self):
Expand Down Expand Up @@ -93,6 +95,45 @@ def getQueueItem(self, item):
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,
Expand Down
9 changes: 9 additions & 0 deletions tests/test_playqueue.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from plexapi.exceptions import BadRequest
from plexapi.playqueue import PlayQueue
import pytest


Expand Down Expand Up @@ -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