Uh oh!
There was an error while loading. Please reload this page.
Allow adding items from different servers to playlist - #1411
Merged
JonnyWong16 merged 1 commit intoMay 11, 2024
Merged
Conversation
glensc
reviewed
May 5, 2024
Uh oh!
There was an error while loading. Please reload this page.
Contributor
This assumes all items to be added have ...should somehow use |
glensc
commented
Sep 1, 2024
Contributor
I currently put together something like this. this is able to take existing playlist (via defaddItems(self, items):
""" Add items to the playlist. Parameters: items (List): List of :class:`~plexapi.audio.Audio`, :class:`~plexapi.video.Video`, or :class:`~plexapi.photo.Photo` objects to be added to the playlist. Raises: :class:`plexapi.exceptions.BadRequest`: When trying to add items to a smart playlist. """ifself.smart:
raiseBadRequest('Cannot add items to a smart playlist.')
ifitemsandnotisinstance(items, (list, tuple)):
items= [items]
# Group items by server to maintain order when adding items from multiple servers# for server, _items in groupby(items, key=lambda item: item._server):forsourceURI, _itemsingroupby(items, key=lambdaitem: item.sourceURI):
ratingKeys= []
foritemin_items:
ifitem.listType!=self.playlistType: # pragma: no coverraiseBadRequest(f'Can not mix media types when building a playlist: 'f'{self.playlistType} and {item.listType}')
sourceURI=item._server._uriRoot() ifsourceURIisNoneelsesourceURIratingKeys.append(str(item.ratingKey))
ratingKeys=','.join(ratingKeys)
# uri = f'{server._uriRoot()}/library/metadata/{ratingKeys}'uri=f'{sourceURI}/library/metadata/{ratingKeys}'args= {'uri': uri}
key=f"{self.key}/items{utils.joinArgs(args)}"self._server.query(key, method=self._server._session.put)
returnself |
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Allow adding items from different servers to playlist.
Playlist.addItems(items)automatically splits theitemsinto separate API calls since Plex only allows adding items from one server at a time. This will keep the items in the order they added in the list.Closes#1409
Type of change
Please delete options that are not relevant.
Checklist: