diff --git a/plexapi/photo.py b/plexapi/photo.py index a0d1b7f3..8a4fb217 100644 --- a/plexapi/photo.py +++ b/plexapi/photo.py @@ -46,6 +46,7 @@ class Photoalbum(PlexPartialObject): self.type = data.attrib.get('type') self.updatedAt = utils.toDatetime(data.attrib.get('updatedAt')) + def albums(self, **kwargs): """ Returns a list of :class:`~plexapi.photo.Photoalbum` objects in this album. """ key = '/library/metadata/%s/children' % self.ratingKey @@ -54,10 +55,11 @@ class Photoalbum(PlexPartialObject): def album(self, title): """ Returns the :class:`~plexapi.photo.Photoalbum` that matches the specified title. """ for album in self.albums(): - if album.attrib.get('title').lower() == title.lower(): + if album.title.lower() == title.lower(): return album raise NotFound('Unable to find album: %s' % title) + def photos(self, **kwargs): """ Returns a list of :class:`~plexapi.photo.Photo` objects in this album. """ key = '/library/metadata/%s/children' % self.ratingKey @@ -66,7 +68,7 @@ class Photoalbum(PlexPartialObject): def photo(self, title): """ Returns the :class:`~plexapi.photo.Photo` that matches the specified title. """ for photo in self.photos(): - if photo.attrib.get('title').lower() == title.lower(): + if photo.title.lower() == title.lower(): return photo raise NotFound('Unable to find photo: %s' % title) diff --git a/tests/test_photo.py b/tests/test_photo.py new file mode 100644 index 00000000..0a7a6c3f --- /dev/null +++ b/tests/test_photo.py @@ -0,0 +1,9 @@ + + +def test_photo_Photoalbum(photoalbum): + assert len(photoalbum.albums()) == 3 + assert len(photoalbum.photos()) == 3 + cats_in_bed = photoalbum.album('Cats in bed') + assert len(cats_in_bed.photos()) == 7 + a_pic = cats_in_bed.photo('maxresdefault') + assert a_pic