Skip to content

Commit d121172

Browse files
authored
Use pagination for /all endpoints (#990)
1 parent c8854c6 commit d121172

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

plexapi/audio.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from plexapi import media, utils
66
from plexapi.base import Playable, PlexPartialObject, PlexSession
7-
from plexapi.exceptions import BadRequest
7+
from plexapi.exceptions import BadRequest, NotFound
88
from plexapi.mixins import (
99
AdvancedSettingsMixin, SplitMergeMixin, UnmatchMatchMixin, ExtrasMixin, HubsMixin, PlayedUnplayedMixin, RatingMixin,
1010
ArtUrlMixin, ArtMixin, PosterUrlMixin, PosterMixin, ThemeMixin, ThemeUrlMixin,
@@ -181,13 +181,14 @@ def album(self, title):
181181
Parameters:
182182
title (str): Title of the album to return.
183183
"""
184-
key = f"/library/sections/{self.librarySectionID}/all?artist.id={self.ratingKey}&type=9"
185-
return self.fetchItem(key, Album, title__iexact=title)
184+
try:
185+
return self.section().search(title, libtype='album', filters={'artist.id': self.ratingKey})[0]
186+
except IndexError:
187+
raise NotFound(f"Unable to find album '{title}'") from None
186188

187189
def albums(self, **kwargs):
188190
""" Returns a list of :class:`~plexapi.audio.Album` objects by the artist. """
189-
key = f"/library/sections/{self.librarySectionID}/all?artist.id={self.ratingKey}&type=9"
190-
return self.fetchItems(key, Album, **kwargs)
191+
return self.section().search(libtype='album', filters={'artist.id': self.ratingKey}, **kwargs)
191192

192193
def track(self, title=None, album=None, track=None):
193194
""" Returns the :class:`~plexapi.audio.Track` that matches the specified title.

plexapi/library.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
import re
33
from datetime import datetime
4-
from urllib.parse import quote, quote_plus, urlencode
4+
from urllib.parse import quote_plus, urlencode
55

66
from plexapi import X_PLEX_CONTAINER_SIZE, log, media, utils
77
from plexapi.base import OPERATORS, PlexObject
@@ -614,8 +614,10 @@ def get(self, title):
614614
Raises:
615615
:exc:`~plexapi.exceptions.NotFound`: The title is not found in the library.
616616
"""
617-
key = '/library/sections/%s/all?includeGuids=1&title=%s' % (self.key, quote(title, safe=''))
618-
return self.fetchItem(key, title__iexact=title)
617+
try:
618+
return self.search(title)[0]
619+
except IndexError:
620+
raise NotFound(f"Unable to find item '{title}'") from None
619621

620622
def getGuid(self, guid):
621623
""" Returns the media item with the specified external Plex, IMDB, TMDB, or TVDB ID.

0 commit comments

Comments
 (0)