diff --git a/lib/plexapi/audio.py b/lib/plexapi/audio.py index 90f7be64..d410da29 100644 --- a/lib/plexapi/audio.py +++ b/lib/plexapi/audio.py @@ -231,7 +231,7 @@ class Album(Audio): self.guid = data.attrib.get('guid') self.leafCount = utils.cast(int, data.attrib.get('leafCount')) self.loudnessAnalysisVersion = utils.cast(int, data.attrib.get('loudnessAnalysisVersion')) - self.key = self.key.replace('/children', '') # fixes bug #50 + self.key = self.key.replace('/children', '') # FIX_BUG_50 self.originallyAvailableAt = utils.toDatetime(data.attrib.get('originallyAvailableAt'), '%Y-%m-%d') self.parentGuid = data.attrib.get('parentGuid') self.parentKey = data.attrib.get('parentKey') diff --git a/lib/plexapi/base.py b/lib/plexapi/base.py index 6e5c6c2f..d553e5b1 100644 --- a/lib/plexapi/base.py +++ b/lib/plexapi/base.py @@ -334,7 +334,7 @@ class PlexPartialObject(PlexObject): search result for a movie often only contain a portion of the attributes a full object (main url) for that movie contain. """ - return not self.key or self.key == self._initpath + return not self.key or (self._details_key or self.key) == self._initpath def isPartialObject(self): """ Returns True if this is not a full object. """ diff --git a/lib/plexapi/library.py b/lib/plexapi/library.py index 499a9c2b..b7d462be 100644 --- a/lib/plexapi/library.py +++ b/lib/plexapi/library.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from plexapi import X_PLEX_CONTAINER_SIZE, log, utils, media -from plexapi.base import PlexObject +from plexapi.base import PlexObject, PlexPartialObject from plexapi.compat import quote, quote_plus, unquote, urlencode from plexapi.exceptions import BadRequest, NotFound from plexapi.media import MediaTag @@ -1106,7 +1106,35 @@ class Hub(PlexObject): @utils.registerPlexObject -class Collections(PlexObject): +class Collections(PlexPartialObject): + """ Represents a single Collection. + Attributes: + TAG (str): 'Directory' + TYPE (str): 'collection' + ratingKey (int): Unique key identifying this item. + addedAt (datetime): Datetime this item was added to the library. + childCount (int): Count of child object(s) + collectionMode (str): How the items in the collection are displayed. + collectionSort (str): How to sort the items in the collection. + contentRating (str) Content rating (PG-13; NR; TV-G). + fields (list): List of :class:`~plexapi.media.Field`. + guid (str): Plex GUID (collection://XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX). + index (int): Unknown + key (str): API URL (/library/metadata/). + labels (List<:class:`~plexapi.media.Label`>): List of field objects. + librarySectionID (int): :class:`~plexapi.library.LibrarySection` ID. + librarySectionKey (str): API URL (/library/sections/). + librarySectionTitle (str): Section Title + maxYear (int): Year + minYear (int): Year + subtype (str): Media type + summary (str): Summary of the collection + thumb (str): URL to thumbnail image. + title (str): Collection Title + titleSort (str): Title to use when sorting (defaults to title). + type (str): Hardcoded 'collection' + updatedAt (datatime): Datetime this item was updated. + """ TAG = 'Directory' TYPE = 'collection' @@ -1114,30 +1142,30 @@ class Collections(PlexObject): def _loadData(self, data): self.ratingKey = utils.cast(int, data.attrib.get('ratingKey')) - self._details_key = "/library/metadata/%s%s" % (self.ratingKey, self._include) + self.key = data.attrib.get('key').replace('/children', '') # FIX_BUG_50 + self._details_key = self.key + self._include + self.addedAt = utils.toDatetime(data.attrib.get('addedAt')) self.art = data.attrib.get('art') + self.childCount = utils.cast(int, data.attrib.get('childCount')) + self.collectionMode = utils.cast(int, data.attrib.get('collectionMode')) + self.collectionSort = utils.cast(int, data.attrib.get('collectionSort')) self.contentRating = data.attrib.get('contentRating') + self.fields = self.findItems(data, media.Field) self.guid = data.attrib.get('guid') - self.key = data.attrib.get('key') + self.index = utils.cast(int, data.attrib.get('index')) + self.labels = self.findItems(data, media.Label) self.librarySectionID = data.attrib.get('librarySectionID') self.librarySectionKey = data.attrib.get('librarySectionKey') self.librarySectionTitle = data.attrib.get('librarySectionTitle') - self.type = data.attrib.get('type') - self.title = data.attrib.get('title') - self.titleSort = data.attrib.get('titleSort') + self.maxYear = utils.cast(int, data.attrib.get('maxYear')) + self.minYear = utils.cast(int, data.attrib.get('minYear')) self.subtype = data.attrib.get('subtype') self.summary = data.attrib.get('summary') - self.index = utils.cast(int, data.attrib.get('index')) self.thumb = data.attrib.get('thumb') - self.addedAt = utils.toDatetime(data.attrib.get('addedAt')) + self.title = data.attrib.get('title') + self.titleSort = data.attrib.get('titleSort') + self.type = data.attrib.get('type') self.updatedAt = utils.toDatetime(data.attrib.get('updatedAt')) - self.childCount = utils.cast(int, data.attrib.get('childCount')) - self.minYear = utils.cast(int, data.attrib.get('minYear')) - self.maxYear = utils.cast(int, data.attrib.get('maxYear')) - self.collectionMode = utils.cast(int, data.attrib.get('collectionMode')) - self.collectionSort = utils.cast(int, data.attrib.get('collectionSort')) - self.labels = self.findItems(data, media.Label) - self.fields = self.findItems(data, media.Field) @property def children(self): @@ -1162,14 +1190,12 @@ class Collections(PlexObject): def modeUpdate(self, mode=None): """ Update Collection Mode - Parameters: mode: default (Library default) hide (Hide Collection) hideItems (Hide Items in this Collection) showItems (Show this Collection and its Items) Example: - collection = 'plexapi.library.Collections' collection.updateMode(mode="hide") """ @@ -1185,13 +1211,10 @@ class Collections(PlexObject): def sortUpdate(self, sort=None): """ Update Collection Sorting - Parameters: sort: realease (Order Collection by realease dates) alpha (Order Collection Alphabetically) - Example: - colleciton = 'plexapi.library.Collections' collection.updateSort(mode="alpha") """ diff --git a/lib/plexapi/photo.py b/lib/plexapi/photo.py index 437216fe..68b77a58 100644 --- a/lib/plexapi/photo.py +++ b/lib/plexapi/photo.py @@ -38,7 +38,7 @@ class Photoalbum(PlexPartialObject): self.composite = data.attrib.get('composite') self.guid = data.attrib.get('guid') self.index = utils.cast(int, data.attrib.get('index')) - self.key = data.attrib.get('key', '').replace('/children', '') + self.key = data.attrib.get('key', '').replace('/children', '') # FIX_BUG_50 self.librarySectionID = data.attrib.get('librarySectionID') self.librarySectionKey = data.attrib.get('librarySectionKey') self.librarySectionTitle = data.attrib.get('librarySectionTitle') diff --git a/lib/plexapi/video.py b/lib/plexapi/video.py index f7bb71ed..2ca35aa9 100644 --- a/lib/plexapi/video.py +++ b/lib/plexapi/video.py @@ -402,7 +402,7 @@ class Show(Video): """ Load attribute values from Plex XML response. """ Video._loadData(self, data) # fix key if loaded from search - self.key = self.key.replace('/children', '') + self.key = self.key.replace('/children', '') # FIX_BUG_50 self.art = data.attrib.get('art') self.banner = data.attrib.get('banner') self.childCount = utils.cast(int, data.attrib.get('childCount'))