@@ -144,34 +144,9 @@ def fetchItem(self, ekey, cls=None, **kwargs):
144144 it only returns those items. By default we convert the xml elements
145145 with the best guess PlexObjects based on tag and type attrs.
146146 etag (str): Only fetch items with the specified tag.
147- **kwargs (dict): Optionally add attribute filters on the items to fetch. For
148- example, passing in viewCount=0 will only return matching items. Filtering
149- is done before the Python objects are built to help keep things speedy.
150- Note: Because some attribute names are already used as arguments to this
151- function, such as 'tag', you may still reference the attr tag byappending
152- an underscore. For example, passing in _tag='foobar' will return all items
153- where tag='foobar'. Also Note: Case very much matters when specifying kwargs
154- -- Optionally, operators can be specified by append it
155- to the end of the attribute name for more complex lookups. For example,
156- passing in viewCount__gte=0 will return all items where viewCount >= 0.
157- Available operations include:
158-
159- * __contains: Value contains specified arg.
160- * __endswith: Value ends with specified arg.
161- * __exact: Value matches specified arg.
162- * __exists (bool): Value is or is not present in the attrs.
163- * __gt: Value is greater than specified arg.
164- * __gte: Value is greater than or equal to specified arg.
165- * __icontains: Case insensative value contains specified arg.
166- * __iendswith: Case insensative value ends with specified arg.
167- * __iexact: Case insensative value matches specified arg.
168- * __in: Value is in a specified list or tuple.
169- * __iregex: Case insensative value matches the specified regular expression.
170- * __istartswith: Case insensative value starts with specified arg.
171- * __lt: Value is less than specified arg.
172- * __lte: Value is less than or equal to specified arg.
173- * __regex: Value matches the specified regular expression.
174- * __startswith: Value starts with specified arg.
147+ **kwargs (dict): Optionally add XML attribute to filter the items.
148+ See :func:`~plexapi.base.PlexObject.fetchItems` for more details
149+ on how this is used.
175150 """
176151 if ekey is None :
177152 raise BadRequest ('ekey was not provided' )
@@ -185,12 +160,76 @@ def fetchItem(self, ekey, cls=None, **kwargs):
185160
186161 def fetchItems (self , ekey , cls = None , container_start = None , container_size = None , ** kwargs ):
187162 """ Load the specified key to find and build all items with the specified tag
188- and attrs. See :func:`~plexapi.base.PlexObject.fetchItem` for more details
189- on how this is used.
163+ and attrs.
190164
191165 Parameters:
166+ ekey (str): API URL path in Plex to fetch items from.
167+ cls (:class:`~plexapi.base.PlexObject`): If you know the class of the
168+ items to be fetched, passing this in will help the parser ensure
169+ it only returns those items. By default we convert the xml elements
170+ with the best guess PlexObjects based on tag and type attrs.
171+ etag (str): Only fetch items with the specified tag.
192172 container_start (None, int): offset to get a subset of the data
193173 container_size (None, int): How many items in data
174+ **kwargs (dict): Optionally add XML attribute to filter the items.
175+ See the details below for more info.
176+
177+ **Filtering XML Attributes**
178+
179+ Any XML attribute can be filtered when fetching results. Filtering is done before
180+ the Python objects are built to help keep things speedy. For example, passing in
181+ ``viewCount=0`` will only return matching items where the view count is ``0``.
182+ Note that case matters when specifying attributes. Attributes futher down in the XML
183+ tree can be filtered by *prepending* the attribute with each element tag ``Tag__``.
184+
185+ Examples:
186+
187+ .. code-block:: python
188+
189+ fetchItem(ekey, viewCount=0)
190+ fetchItem(ekey, contentRating="PG")
191+ fetchItem(ekey, Genre__tag="Animation")
192+ fetchItem(ekey, Media__videoCodec="h265")
193+ fetchItem(ekey, Media__Part__container="mp4)
194+
195+ Note that because some attribute names are already used as arguments to this
196+ function, such as ``tag``, you may still reference the attr tag by prepending an
197+ underscore. For example, passing in ``_tag='foobar'`` will return all items where
198+ ``tag='foobar'``.
199+
200+ **Using PlexAPI Operators**
201+
202+ Optionally, PlexAPI operators can be specified by *appending* it to the end of the
203+ attribute for more complex lookups. For example, passing in ``viewCount__gte=0``
204+ will return all items where ``viewCount >= 0``.
205+
206+ List of Available Operators:
207+
208+ * ``__contains``: Value contains specified arg.
209+ * ``__endswith``: Value ends with specified arg.
210+ * ``__exact``: Value matches specified arg.
211+ * ``__exists`` (*bool*): Value is or is not present in the attrs.
212+ * ``__gt``: Value is greater than specified arg.
213+ * ``__gte``: Value is greater than or equal to specified arg.
214+ * ``__icontains``: Case insensative value contains specified arg.
215+ * ``__iendswith``: Case insensative value ends with specified arg.
216+ * ``__iexact``: Case insensative value matches specified arg.
217+ * ``__in``: Value is in a specified list or tuple.
218+ * ``__iregex``: Case insensative value matches the specified regular expression.
219+ * ``__istartswith``: Case insensative value starts with specified arg.
220+ * ``__lt``: Value is less than specified arg.
221+ * ``__lte``: Value is less than or equal to specified arg.
222+ * ``__regex``: Value matches the specified regular expression.
223+ * ``__startswith``: Value starts with specified arg.
224+
225+ Examples:
226+
227+ .. code-block:: python
228+
229+ fetchItem(ekey, viewCount__gte=0)
230+ fetchItem(ekey, Media__container__in=["mp4", "mkv"])
231+ fetchItem(ekey, guid__iregex=r"(imdb:\/\/|themoviedb:\/\/)")
232+ fetchItem(ekey, Media__Part__file__startswith="D:\\ Movies")
194233
195234 """
196235 url_kw = {}
@@ -204,7 +243,7 @@ def fetchItems(self, ekey, cls=None, container_start=None, container_size=None,
204243 data = self ._server .query (ekey , params = url_kw )
205244 items = self .findItems (data , cls , ekey , ** kwargs )
206245
207- librarySectionID = data .attrib .get ('librarySectionID' )
246+ librarySectionID = utils . cast ( int , data .attrib .get ('librarySectionID' ) )
208247 if librarySectionID :
209248 for item in items :
210249 item .librarySectionID = librarySectionID
0 commit comments