mirror of
https://github.com/pkkid/python-plexapi
synced 2025-02-16 12:58:26 +00:00
Merge pull request #617 from JonnyWong16/feature/library_collections_playlists
Change LibrarySection collections method to plural and add playlists method
This commit is contained in:
commit
16a63f131c
3 changed files with 48 additions and 14 deletions
|
@ -1,4 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import warnings
|
||||
from urllib.parse import quote, quote_plus, unquote, urlencode
|
||||
|
||||
from plexapi import X_PLEX_CONTAINER_SIZE, log, utils
|
||||
|
@ -7,6 +8,8 @@ from plexapi.exceptions import BadRequest, NotFound
|
|||
from plexapi.media import MediaTag
|
||||
from plexapi.settings import Setting
|
||||
|
||||
warnings.simplefilter('default')
|
||||
|
||||
|
||||
class Library(PlexObject):
|
||||
""" Represents a PlexServer library. This contains all sections of media defined
|
||||
|
@ -842,6 +845,23 @@ class LibrarySection(PlexObject):
|
|||
"""
|
||||
return self._server.history(maxresults=maxresults, mindate=mindate, librarySectionID=self.key, accountID=1)
|
||||
|
||||
def collection(self, **kwargs):
|
||||
msg = 'LibrarySection.collection() will be deprecated in the future, use collections() (plural) instead.'
|
||||
warnings.warn(msg, DeprecationWarning)
|
||||
log.warning(msg)
|
||||
return self.collections()
|
||||
|
||||
def collections(self, **kwargs):
|
||||
""" Returns a list of collections from this library section.
|
||||
See description of :func:`plexapi.library.LibrarySection.search` for details about filtering / sorting.
|
||||
"""
|
||||
return self.search(libtype='collection', **kwargs)
|
||||
|
||||
def playlists(self, **kwargs):
|
||||
""" Returns a list of playlists from this library section. """
|
||||
key = '/playlists?type=15&playlistType=%s§ionID=%s' % (self.CONTENT_TYPE, self.key)
|
||||
return self.fetchItems(key, **kwargs)
|
||||
|
||||
|
||||
class MovieSection(LibrarySection):
|
||||
""" Represents a :class:`~plexapi.library.LibrarySection` section containing movies.
|
||||
|
@ -855,10 +875,6 @@ class MovieSection(LibrarySection):
|
|||
METADATA_TYPE = 'movie'
|
||||
CONTENT_TYPE = 'video'
|
||||
|
||||
def collection(self, **kwargs):
|
||||
""" Returns a list of collections from this library section. """
|
||||
return self.search(libtype='collection', **kwargs)
|
||||
|
||||
def sync(self, videoQuality, limit=None, unwatched=False, **kwargs):
|
||||
""" Add current Movie library section as sync item for specified device.
|
||||
See description of :func:`~plexapi.library.LibrarySection.search` for details about filtering / sorting and
|
||||
|
@ -924,10 +940,6 @@ class ShowSection(LibrarySection):
|
|||
"""
|
||||
return self.search(sort='episode.addedAt:desc', libtype=libtype, maxresults=maxresults)
|
||||
|
||||
def collection(self, **kwargs):
|
||||
""" Returns a list of collections from this library section. """
|
||||
return self.search(libtype='collection', **kwargs)
|
||||
|
||||
def sync(self, videoQuality, limit=None, unwatched=False, **kwargs):
|
||||
""" Add current Show library section as sync item for specified device.
|
||||
See description of :func:`~plexapi.library.LibrarySection.search` for details about filtering / sorting and
|
||||
|
@ -999,10 +1011,6 @@ class MusicSection(LibrarySection):
|
|||
""" Search for a track. See :func:`~plexapi.library.LibrarySection.search` for usage. """
|
||||
return self.search(libtype='track', **kwargs)
|
||||
|
||||
def collection(self, **kwargs):
|
||||
""" Returns a list of collections from this library section. """
|
||||
return self.search(libtype='collection', **kwargs)
|
||||
|
||||
def sync(self, bitrate, limit=None, **kwargs):
|
||||
""" Add current Music library section as sync item for specified device.
|
||||
See description of :func:`~plexapi.library.LibrarySection.search` for details about filtering / sorting and
|
||||
|
@ -1050,6 +1058,9 @@ class PhotoSection(LibrarySection):
|
|||
CONTENT_TYPE = 'photo'
|
||||
METADATA_TYPE = 'photo'
|
||||
|
||||
def collections(self, **kwargs):
|
||||
raise NotImplementedError('Collections are not available for a Photo library.')
|
||||
|
||||
def searchAlbums(self, title, **kwargs):
|
||||
""" Search for an album. See :func:`~plexapi.library.LibrarySection.search` for usage. """
|
||||
return self.search(libtype='photoalbum', title=title, **kwargs)
|
||||
|
|
|
@ -222,13 +222,13 @@ def movie(movies):
|
|||
@pytest.fixture()
|
||||
def collection(plex):
|
||||
try:
|
||||
return plex.library.section("Movies").collection()[0]
|
||||
return plex.library.section("Movies").collections()[0]
|
||||
except IndexError:
|
||||
movie = plex.library.section("Movies").get("Elephants Dream")
|
||||
movie.addCollection(["marvel"])
|
||||
|
||||
n = plex.library.section("Movies").reload()
|
||||
return n.collection()[0]
|
||||
return n.collections()[0]
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
|
|
|
@ -181,6 +181,10 @@ def test_library_MovieSection_analyze(movies):
|
|||
movies.analyze()
|
||||
|
||||
|
||||
def test_library_MovieSection_collections(movies, collection):
|
||||
assert len(movies.collections())
|
||||
|
||||
|
||||
def test_library_ShowSection_searchShows(tvshows):
|
||||
assert tvshows.searchShows(title="The 100")
|
||||
|
||||
|
@ -193,6 +197,15 @@ def test_library_ShowSection_recentlyAdded(tvshows):
|
|||
assert len(tvshows.recentlyAdded())
|
||||
|
||||
|
||||
def test_library_ShowSection_playlists(plex, tvshows, show):
|
||||
episodes = show.episodes()
|
||||
playlist = plex.createPlaylist("test_library_ShowSection_playlists", episodes[:3])
|
||||
try:
|
||||
assert len(tvshows.playlists())
|
||||
finally:
|
||||
playlist.delete()
|
||||
|
||||
|
||||
def test_library_MusicSection_albums(music):
|
||||
assert len(music.albums())
|
||||
|
||||
|
@ -277,6 +290,16 @@ def test_library_Colletion_edit(collection):
|
|||
collection.edit(**{'titleSort.value': collectionTitleSort, 'titleSort.locked': 0})
|
||||
|
||||
|
||||
def test_library_Collection_delete(movies, movie):
|
||||
delete_collection = 'delete_collection'
|
||||
movie.addCollection(delete_collection)
|
||||
collections = movies.collections(title=delete_collection)
|
||||
assert len(collections) == 1
|
||||
collections[0].delete()
|
||||
collections = movies.collections(title=delete_collection)
|
||||
assert len(collections) == 0
|
||||
|
||||
|
||||
def test_search_with_weird_a(plex):
|
||||
ep_title = "Coup de Grâce"
|
||||
result_root = plex.search(ep_title)
|
||||
|
|
Loading…
Add table
Reference in a new issue