Skip to content

Commit 057967a

Browse files
andrey-yantsenHellowlol
authored andcommitted
Library section id for all (#292)
* add librarySectionID for each item if MediaContainer had one * fix getting section for photos which are not in album yet * another approach
1 parent 68fc970 commit 057967a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

plexapi/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ def fetchItems(self, ekey, cls=None, **kwargs):
145145
on how this is used.
146146
"""
147147
data = self._server.query(ekey)
148-
return self.findItems(data, cls, ekey, **kwargs)
148+
items = self.findItems(data, cls, ekey, **kwargs)
149+
librarySectionID = data.attrib.get('librarySectionID')
150+
if librarySectionID:
151+
for item in items:
152+
item.librarySectionID = librarySectionID
153+
return items
149154

150155
def findItems(self, data, cls=None, initpath=None, **kwargs):
151156
""" Load the specified data to find and build all items with the specified tag

plexapi/photo.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
from plexapi import media, utils
33
from plexapi.base import PlexPartialObject
4+
from plexapi.exceptions import NotFound, BadRequest
45
from plexapi.exceptions import NotFound
56
from plexapi.compat import quote_plus
67

@@ -124,7 +125,12 @@ def photoalbum(self):
124125

125126
def section(self):
126127
""" Returns the :class:`~plexapi.library.LibrarySection` this item belongs to. """
127-
return self._server.library.sectionByID(self.photoalbum().librarySectionID)
128+
if hasattr(self, 'librarySectionID'):
129+
return self._server.library.sectionByID(self.librarySectionID)
130+
elif self.parentKey:
131+
return self._server.library.sectionByID(self.photoalbum().librarySectionID)
132+
else:
133+
raise BadRequest('Unable to get section for photo, can`t find librarySectionID')
128134

129135
def sync(self, resolution, client=None, clientId=None, limit=None, title=None):
130136
""" Add current photo as sync item for specified device.

0 commit comments

Comments
 (0)