Factor out playQueue() method to PlexPartialObject (#1058)

* Factor out `playQueue` to `PlexPartialObject`

* Update `PlayQueue.create()`

* Fix playqueue tests
This commit is contained in:
JonnyWong16 2022-12-21 11:43:26 -08:00 committed by GitHub
parent e5d3ebe273
commit be42435ed3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 24 deletions

View file

@ -666,6 +666,13 @@ class PlexPartialObject(PlexObject):
"""
return self._getWebURL(base=base)
def playQueue(self, *args, **kwargs):
""" Returns a new :class:`~plexapi.playqueue.PlayQueue` from this media item.
See :func:`~plexapi.playqueue.PlayQueue.create` for available parameters.
"""
from plexapi.playqueue import PlayQueue
return PlayQueue.create(self._server, self, *args, **kwargs)
class Playable:
""" This is a general place to store functions specific to media that is Playable.

View file

@ -11,7 +11,6 @@ from plexapi.mixins import (
ContentRatingMixin, SortTitleMixin, SummaryMixin, TitleMixin,
LabelMixin
)
from plexapi.playqueue import PlayQueue
from plexapi.utils import deprecated
@ -427,10 +426,6 @@ class Collection(
""" Delete the collection. """
super(Collection, self).delete()
def playQueue(self, *args, **kwargs):
""" Returns a new :class:`~plexapi.playqueue.PlayQueue` from the collection. """
return PlayQueue.create(self._server, self.items(), *args, **kwargs)
@classmethod
def _create(cls, server, title, section, items):
""" Create a regular collection. """

View file

@ -7,7 +7,6 @@ from plexapi.base import Playable, PlexPartialObject
from plexapi.exceptions import BadRequest, NotFound, Unsupported
from plexapi.library import LibrarySection, MusicSection
from plexapi.mixins import SmartFilterMixin, ArtMixin, PosterMixin
from plexapi.playqueue import PlayQueue
from plexapi.utils import deprecated
@ -330,10 +329,6 @@ class Playlist(
""" Delete the playlist. """
self._server.query(self.key, method=self._server._session.delete)
def playQueue(self, *args, **kwargs):
""" Returns a new :class:`~plexapi.playqueue.PlayQueue` from the playlist. """
return PlayQueue.create(self._server, self, *args, **kwargs)
@classmethod
def _create(cls, server, title, items):
""" Create a regular playlist. """

View file

@ -150,8 +150,8 @@ class PlayQueue(PlexObject):
Parameters:
server (:class:`~plexapi.server.PlexServer`): Server you are connected to.
items (:class:`~plexapi.base.Playable` or :class:`~plexapi.playlist.Playlist`):
A media item, list of media items, or Playlist.
items (:class:`~plexapi.base.PlexPartialObject`):
A media item or a list of media items.
startItem (:class:`~plexapi.base.Playable`, optional):
Media item in the PlayQueue where playback should begin.
shuffle (int, optional): Start the playqueue shuffled.
@ -174,16 +174,13 @@ class PlayQueue(PlexObject):
uri_args = quote_plus(f"/library/metadata/{item_keys}")
args["uri"] = f"library:///directory/{uri_args}"
args["type"] = items[0].listType
elif items.type == "playlist":
args["type"] = items.playlistType
if items.radio:
args["uri"] = f"server://{server.machineIdentifier}/{server.library.identifier}{items.key}"
else:
if items.type == "playlist":
args["type"] = items.playlistType
args["playlistID"] = items.ratingKey
else:
uuid = items.section().uuid
args["type"] = items.listType
args["uri"] = f"library://{uuid}/item/{items.key}"
args["uri"] = f"server://{server.machineIdentifier}/{server.library.identifier}{items.key}"
if startItem:
args["key"] = startItem.key

View file

@ -133,7 +133,6 @@ def test_create_playqueue_from_playlist(plex, album):
playlist = plex.createPlaylist("test_playlist", items=album)
pq = playlist.playQueue(shuffle=1)
assert pq.playQueueShuffled is True
assert len(playlist) == len(album.tracks())
assert len(pq) == len(playlist)
pq.addItem(playlist)
assert len(pq) == 2 * len(playlist)
@ -146,8 +145,7 @@ def test_create_playqueue_from_collection(plex, music, album):
collection = plex.createCollection("test_collection", music, album)
pq = collection.playQueue(shuffle=1)
assert pq.playQueueShuffled is True
assert len(collection) == len(album.tracks())
assert len(pq) == len(collection)
assert len(pq) == len(album.tracks())
pq.addItem(collection.items()[0])
assert len(pq) == len(collection) + 1
finally: