From b21960e655592318764bae9bb23f69203b0546e1 Mon Sep 17 00:00:00 2001 From: Andrey Yantsen Date: Sun, 2 Sep 2018 22:33:58 +0100 Subject: [PATCH 1/3] add librarySectionID for each item if MediaContainer had one --- plexapi/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plexapi/base.py b/plexapi/base.py index 7aeb98598..46c7e1272 100644 --- a/plexapi/base.py +++ b/plexapi/base.py @@ -159,10 +159,13 @@ def findItems(self, data, cls=None, initpath=None, **kwargs): kwargs['type'] = cls.TYPE # loop through all data elements to find matches items = [] + librarySectionID = data.attrib.get('librarySectionID') for elem in data: if self._checkAttrs(elem, **kwargs): item = self._buildItemOrNone(elem, cls, initpath) if item is not None: + if librarySectionID: + item.librarySectionID = librarySectionID items.append(item) return items From 62afc1bd82ac8716ef717fc8ab3ed72c3a174aa4 Mon Sep 17 00:00:00 2001 From: Andrey Yantsen Date: Sun, 2 Sep 2018 22:34:41 +0100 Subject: [PATCH 2/3] fix getting section for photos which are not in album yet --- plexapi/photo.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plexapi/photo.py b/plexapi/photo.py index 50db79f56..8190beb34 100644 --- a/plexapi/photo.py +++ b/plexapi/photo.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from plexapi import media, utils from plexapi.base import PlexPartialObject -from plexapi.exceptions import NotFound +from plexapi.exceptions import NotFound, BadRequest @utils.registerPlexObject @@ -122,4 +122,9 @@ def photoalbum(self): def section(self): """ Returns the :class:`~plexapi.library.LibrarySection` this item belongs to. """ - return self._server.library.sectionByID(self.photoalbum().librarySectionID) + if hasattr(self, 'librarySectionID'): + return self._server.library.sectionByID(self.librarySectionID) + elif self.parentKey: + return self._server.library.sectionByID(self.photoalbum().librarySectionID) + else: + raise BadRequest('Unable to get section for photo, can`t find librarySectionID') From 5d9df1a482f37be2d5acdc1fac2db81364d200a6 Mon Sep 17 00:00:00 2001 From: Andrey Yantsen Date: Tue, 4 Sep 2018 13:05:00 +0100 Subject: [PATCH 3/3] another approach --- plexapi/base.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plexapi/base.py b/plexapi/base.py index 46c7e1272..4c3217f31 100644 --- a/plexapi/base.py +++ b/plexapi/base.py @@ -145,7 +145,12 @@ def fetchItems(self, ekey, cls=None, **kwargs): on how this is used. """ data = self._server.query(ekey) - return self.findItems(data, cls, ekey, **kwargs) + items = self.findItems(data, cls, ekey, **kwargs) + librarySectionID = data.attrib.get('librarySectionID') + if librarySectionID: + for item in items: + item.librarySectionID = librarySectionID + return items def findItems(self, data, cls=None, initpath=None, **kwargs): """ Load the specified data to find and build all items with the specified tag @@ -159,13 +164,10 @@ def findItems(self, data, cls=None, initpath=None, **kwargs): kwargs['type'] = cls.TYPE # loop through all data elements to find matches items = [] - librarySectionID = data.attrib.get('librarySectionID') for elem in data: if self._checkAttrs(elem, **kwargs): item = self._buildItemOrNone(elem, cls, initpath) if item is not None: - if librarySectionID: - item.librarySectionID = librarySectionID items.append(item) return items