Skip to content

Commit

Permalink
Allow adding items from different server to playlist (#1411)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyWong16 authored May 11, 2024
1 parent 4f6723c commit bbdb238
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions plexapi/playlist.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import re
from itertools import groupby
from pathlib import Path
from urllib.parse import quote_plus, unquote

Expand Down Expand Up @@ -212,19 +213,23 @@ def addItems(self, items):
if items and not isinstance(items, (list, tuple)):
items = [items]

ratingKeys = []
for item in items:
if item.listType != self.playlistType: # pragma: no cover
raise BadRequest(f'Can not mix media types when building a playlist: '
f'{self.playlistType} and {item.listType}')
ratingKeys.append(str(item.ratingKey))
# Group items by server to maintain order when adding items from multiple servers
for server, _items in groupby(items, key=lambda item: item._server):

ratingKeys = ','.join(ratingKeys)
uri = f'{self._server._uriRoot()}/library/metadata/{ratingKeys}'
ratingKeys = []
for item in _items:
if item.listType != self.playlistType: # pragma: no cover
raise BadRequest(f'Can not mix media types when building a playlist: '
f'{self.playlistType} and {item.listType}')
ratingKeys.append(str(item.ratingKey))

ratingKeys = ','.join(ratingKeys)
uri = f'{server._uriRoot()}/library/metadata/{ratingKeys}'

args = {'uri': uri}
key = f"{self.key}/items{utils.joinArgs(args)}"
self._server.query(key, method=self._server._session.put)

args = {'uri': uri}
key = f"{self.key}/items{utils.joinArgs(args)}"
self._server.query(key, method=self._server._session.put)
return self

@deprecated('use "removeItems" instead')
Expand Down

0 comments on commit bbdb238

Please sign in to comment.