Skip to content

Commit 42260aa

Browse files
authored
Add libtype argument for creating smart playlists (#799)
* Add libtype keyword argument for smart playlists * Update docs, remove libtype collection from smart playlists/collections * Cannot create a smart playlist or collection from other collections * Update smart playlist filter test for libtype
1 parent 6cacc4a commit 42260aa

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

plexapi/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def create(cls, server, title, section, items=None, smart=False, limit=None,
442442
smart (bool): True to create a smart collection. Default False.
443443
limit (int): Smart collections only, limit the number of items in the collection.
444444
libtype (str): Smart collections only, the specific type of content to filter
445-
(movie, show, season, episode, artist, album, track, photoalbum, photo, collection).
445+
(movie, show, season, episode, artist, album, track, photoalbum, photo).
446446
sort (str or list, optional): Smart collections only, a string of comma separated sort fields
447447
or a list of sort fields in the format ``column:dir``.
448448
See :func:`~plexapi.library.LibrarySection.search` for more info.

plexapi/playlist.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,15 @@ def _create(cls, server, title, items):
341341
return cls(server, data, initpath=key)
342342

343343
@classmethod
344-
def _createSmart(cls, server, title, section, limit=None, sort=None, filters=None, **kwargs):
344+
def _createSmart(cls, server, title, section, limit=None, libtype=None, sort=None, filters=None, **kwargs):
345345
""" Create a smart playlist. """
346346
if not isinstance(section, LibrarySection):
347347
section = server.library.section(section)
348348

349+
libtype = libtype or section.METADATA_TYPE
350+
349351
searchKey = section._buildSearchKey(
350-
sort=sort, libtype=section.METADATA_TYPE, limit=limit, filters=filters, **kwargs)
352+
sort=sort, libtype=libtype, limit=limit, filters=filters, **kwargs)
351353
uri = '%s%s' % (server._uriRoot(), searchKey)
352354

353355
key = '/playlists%s' % utils.joinArgs({
@@ -361,7 +363,7 @@ def _createSmart(cls, server, title, section, limit=None, sort=None, filters=Non
361363

362364
@classmethod
363365
def create(cls, server, title, section=None, items=None, smart=False, limit=None,
364-
sort=None, filters=None, **kwargs):
366+
libtype=None, sort=None, filters=None, **kwargs):
365367
""" Create a playlist.
366368
367369
Parameters:
@@ -373,6 +375,8 @@ def create(cls, server, title, section=None, items=None, smart=False, limit=None
373375
:class:`~plexapi.video.Video`, or :class:`~plexapi.photo.Photo` objects to be added to the playlist.
374376
smart (bool): True to create a smart playlist. Default False.
375377
limit (int): Smart playlists only, limit the number of items in the playlist.
378+
libtype (str): Smart playlists only, the specific type of content to filter
379+
(movie, show, season, episode, artist, album, track, photoalbum, photo).
376380
sort (str or list, optional): Smart playlists only, a string of comma separated sort fields
377381
or a list of sort fields in the format ``column:dir``.
378382
See :func:`~plexapi.library.LibrarySection.search` for more info.
@@ -389,7 +393,7 @@ def create(cls, server, title, section=None, items=None, smart=False, limit=None
389393
:class:`~plexapi.playlist.Playlist`: A new instance of the created Playlist.
390394
"""
391395
if smart:
392-
return cls._createSmart(server, title, section, limit, sort, filters, **kwargs)
396+
return cls._createSmart(server, title, section, limit, libtype, sort, filters, **kwargs)
393397
else:
394398
return cls._create(server, title, items)
395399

plexapi/server.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ def createCollection(self, title, section, items=None, smart=False, limit=None,
427427
smart (bool): True to create a smart collection. Default False.
428428
limit (int): Smart collections only, limit the number of items in the collection.
429429
libtype (str): Smart collections only, the specific type of content to filter
430-
(movie, show, season, episode, artist, album, track, photoalbum, photo, collection).
430+
(movie, show, season, episode, artist, album, track, photoalbum, photo).
431431
sort (str or list, optional): Smart collections only, a string of comma separated sort fields
432432
or a list of sort fields in the format ``column:dir``.
433433
See :func:`~plexapi.library.LibrarySection.search` for more info.
@@ -448,7 +448,7 @@ def createCollection(self, title, section, items=None, smart=False, limit=None,
448448
libtype=libtype, sort=sort, filters=filters, **kwargs)
449449

450450
def createPlaylist(self, title, section=None, items=None, smart=False, limit=None,
451-
sort=None, filters=None, **kwargs):
451+
libtype=None, sort=None, filters=None, **kwargs):
452452
""" Creates and returns a new :class:`~plexapi.playlist.Playlist`.
453453
454454
Parameters:
@@ -459,6 +459,8 @@ def createPlaylist(self, title, section=None, items=None, smart=False, limit=Non
459459
:class:`~plexapi.video.Video`, or :class:`~plexapi.photo.Photo` objects to be added to the playlist.
460460
smart (bool): True to create a smart playlist. Default False.
461461
limit (int): Smart playlists only, limit the number of items in the playlist.
462+
libtype (str): Smart playlists only, the specific type of content to filter
463+
(movie, show, season, episode, artist, album, track, photoalbum, photo).
462464
sort (str or list, optional): Smart playlists only, a string of comma separated sort fields
463465
or a list of sort fields in the format ``column:dir``.
464466
See :func:`~plexapi.library.LibrarySection.search` for more info.
@@ -476,7 +478,7 @@ def createPlaylist(self, title, section=None, items=None, smart=False, limit=Non
476478
"""
477479
return Playlist.create(
478480
self, title, section=section, items=items, smart=smart, limit=limit,
479-
sort=sort, filters=filters, **kwargs)
481+
libtype=libtype, sort=sort, filters=filters, **kwargs)
480482

481483
def createPlayQueue(self, item, **kwargs):
482484
""" Creates and returns a new :class:`~plexapi.playqueue.PlayQueue`.

tests/test_playlist.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,12 @@ def test_Playlist_smartFilters(plex, tvshows):
189189
smart=True,
190190
section=tvshows,
191191
limit=5,
192+
libtype='show',
192193
sort=["season.index:nullsLast", "episode.index:nullsLast", "show.titleSort"],
193194
filters={"or": [{"show.title": "game"}, {'show.title': "100"}]}
194195
)
195196
filters = playlist.filters()
197+
filters['libtype'] = tvshows.METADATA_TYPE # Override libtype to check playlist items
196198
assert tvshows.search(**filters) == playlist.items()
197199
finally:
198200
playlist.delete()

0 commit comments

Comments
 (0)