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) 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: class Playable:
""" This is a general place to store functions specific to media that is 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, ContentRatingMixin, SortTitleMixin, SummaryMixin, TitleMixin,
LabelMixin LabelMixin
) )
from plexapi.playqueue import PlayQueue
from plexapi.utils import deprecated from plexapi.utils import deprecated
@ -427,10 +426,6 @@ class Collection(
""" Delete the collection. """ """ Delete the collection. """
super(Collection, self).delete() 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 @classmethod
def _create(cls, server, title, section, items): def _create(cls, server, title, section, items):
""" Create a regular collection. """ """ 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.exceptions import BadRequest, NotFound, Unsupported
from plexapi.library import LibrarySection, MusicSection from plexapi.library import LibrarySection, MusicSection
from plexapi.mixins import SmartFilterMixin, ArtMixin, PosterMixin from plexapi.mixins import SmartFilterMixin, ArtMixin, PosterMixin
from plexapi.playqueue import PlayQueue
from plexapi.utils import deprecated from plexapi.utils import deprecated
@ -330,10 +329,6 @@ class Playlist(
""" Delete the playlist. """ """ Delete the playlist. """
self._server.query(self.key, method=self._server._session.delete) 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 @classmethod
def _create(cls, server, title, items): def _create(cls, server, title, items):
""" Create a regular playlist. """ """ Create a regular playlist. """

View file

@ -150,8 +150,8 @@ class PlayQueue(PlexObject):
Parameters: Parameters:
server (:class:`~plexapi.server.PlexServer`): Server you are connected to. server (:class:`~plexapi.server.PlexServer`): Server you are connected to.
items (:class:`~plexapi.base.Playable` or :class:`~plexapi.playlist.Playlist`): items (:class:`~plexapi.base.PlexPartialObject`):
A media item, list of media items, or Playlist. A media item or a list of media items.
startItem (:class:`~plexapi.base.Playable`, optional): startItem (:class:`~plexapi.base.Playable`, optional):
Media item in the PlayQueue where playback should begin. Media item in the PlayQueue where playback should begin.
shuffle (int, optional): Start the playqueue shuffled. shuffle (int, optional): Start the playqueue shuffled.
@ -174,16 +174,13 @@ class PlayQueue(PlexObject):
uri_args = quote_plus(f"/library/metadata/{item_keys}") uri_args = quote_plus(f"/library/metadata/{item_keys}")
args["uri"] = f"library:///directory/{uri_args}" args["uri"] = f"library:///directory/{uri_args}"
args["type"] = items[0].listType 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:
args["playlistID"] = items.ratingKey
else: else:
uuid = items.section().uuid if items.type == "playlist":
args["type"] = items.listType args["type"] = items.playlistType
args["uri"] = f"library://{uuid}/item/{items.key}" args["playlistID"] = items.ratingKey
else:
args["type"] = items.listType
args["uri"] = f"server://{server.machineIdentifier}/{server.library.identifier}{items.key}"
if startItem: if startItem:
args["key"] = startItem.key 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) playlist = plex.createPlaylist("test_playlist", items=album)
pq = playlist.playQueue(shuffle=1) pq = playlist.playQueue(shuffle=1)
assert pq.playQueueShuffled is True assert pq.playQueueShuffled is True
assert len(playlist) == len(album.tracks())
assert len(pq) == len(playlist) assert len(pq) == len(playlist)
pq.addItem(playlist) pq.addItem(playlist)
assert len(pq) == 2 * len(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) collection = plex.createCollection("test_collection", music, album)
pq = collection.playQueue(shuffle=1) pq = collection.playQueue(shuffle=1)
assert pq.playQueueShuffled is True assert pq.playQueueShuffled is True
assert len(collection) == len(album.tracks()) assert len(pq) == len(album.tracks())
assert len(pq) == len(collection)
pq.addItem(collection.items()[0]) pq.addItem(collection.items()[0])
assert len(pq) == len(collection) + 1 assert len(pq) == len(collection) + 1
finally: finally: