Patch plexapi.library.Collections to PlexPartialObject

This commit is contained in:
JonnyWong16 2020-10-20 15:49:29 -07:00
parent ecbe79b5b9
commit ec9e2fe0f0
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
5 changed files with 48 additions and 25 deletions

View file

@ -231,7 +231,7 @@ class Album(Audio):
self.guid = data.attrib.get('guid') self.guid = data.attrib.get('guid')
self.leafCount = utils.cast(int, data.attrib.get('leafCount')) self.leafCount = utils.cast(int, data.attrib.get('leafCount'))
self.loudnessAnalysisVersion = utils.cast(int, data.attrib.get('loudnessAnalysisVersion')) 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.originallyAvailableAt = utils.toDatetime(data.attrib.get('originallyAvailableAt'), '%Y-%m-%d')
self.parentGuid = data.attrib.get('parentGuid') self.parentGuid = data.attrib.get('parentGuid')
self.parentKey = data.attrib.get('parentKey') self.parentKey = data.attrib.get('parentKey')

View file

@ -334,7 +334,7 @@ class PlexPartialObject(PlexObject):
search result for a movie often only contain a portion of the attributes a full search result for a movie often only contain a portion of the attributes a full
object (main url) for that movie contain. 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): def isPartialObject(self):
""" Returns True if this is not a full object. """ """ Returns True if this is not a full object. """

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from plexapi import X_PLEX_CONTAINER_SIZE, log, utils, media 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.compat import quote, quote_plus, unquote, urlencode
from plexapi.exceptions import BadRequest, NotFound from plexapi.exceptions import BadRequest, NotFound
from plexapi.media import MediaTag from plexapi.media import MediaTag
@ -1106,7 +1106,35 @@ class Hub(PlexObject):
@utils.registerPlexObject @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/<ratingkey>).
labels (List<:class:`~plexapi.media.Label`>): List of field objects.
librarySectionID (int): :class:`~plexapi.library.LibrarySection` ID.
librarySectionKey (str): API URL (/library/sections/<sectionkey>).
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' TAG = 'Directory'
TYPE = 'collection' TYPE = 'collection'
@ -1114,30 +1142,30 @@ class Collections(PlexObject):
def _loadData(self, data): def _loadData(self, data):
self.ratingKey = utils.cast(int, data.attrib.get('ratingKey')) 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.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.contentRating = data.attrib.get('contentRating')
self.fields = self.findItems(data, media.Field)
self.guid = data.attrib.get('guid') 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.librarySectionID = data.attrib.get('librarySectionID')
self.librarySectionKey = data.attrib.get('librarySectionKey') self.librarySectionKey = data.attrib.get('librarySectionKey')
self.librarySectionTitle = data.attrib.get('librarySectionTitle') self.librarySectionTitle = data.attrib.get('librarySectionTitle')
self.type = data.attrib.get('type') self.maxYear = utils.cast(int, data.attrib.get('maxYear'))
self.title = data.attrib.get('title') self.minYear = utils.cast(int, data.attrib.get('minYear'))
self.titleSort = data.attrib.get('titleSort')
self.subtype = data.attrib.get('subtype') self.subtype = data.attrib.get('subtype')
self.summary = data.attrib.get('summary') self.summary = data.attrib.get('summary')
self.index = utils.cast(int, data.attrib.get('index'))
self.thumb = data.attrib.get('thumb') 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.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 @property
def children(self): def children(self):
@ -1162,14 +1190,12 @@ class Collections(PlexObject):
def modeUpdate(self, mode=None): def modeUpdate(self, mode=None):
""" Update Collection Mode """ Update Collection Mode
Parameters: Parameters:
mode: default (Library default) mode: default (Library default)
hide (Hide Collection) hide (Hide Collection)
hideItems (Hide Items in this Collection) hideItems (Hide Items in this Collection)
showItems (Show this Collection and its Items) showItems (Show this Collection and its Items)
Example: Example:
collection = 'plexapi.library.Collections' collection = 'plexapi.library.Collections'
collection.updateMode(mode="hide") collection.updateMode(mode="hide")
""" """
@ -1185,13 +1211,10 @@ class Collections(PlexObject):
def sortUpdate(self, sort=None): def sortUpdate(self, sort=None):
""" Update Collection Sorting """ Update Collection Sorting
Parameters: Parameters:
sort: realease (Order Collection by realease dates) sort: realease (Order Collection by realease dates)
alpha (Order Collection Alphabetically) alpha (Order Collection Alphabetically)
Example: Example:
colleciton = 'plexapi.library.Collections' colleciton = 'plexapi.library.Collections'
collection.updateSort(mode="alpha") collection.updateSort(mode="alpha")
""" """

View file

@ -38,7 +38,7 @@ class Photoalbum(PlexPartialObject):
self.composite = data.attrib.get('composite') self.composite = data.attrib.get('composite')
self.guid = data.attrib.get('guid') self.guid = data.attrib.get('guid')
self.index = utils.cast(int, data.attrib.get('index')) 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.librarySectionID = data.attrib.get('librarySectionID')
self.librarySectionKey = data.attrib.get('librarySectionKey') self.librarySectionKey = data.attrib.get('librarySectionKey')
self.librarySectionTitle = data.attrib.get('librarySectionTitle') self.librarySectionTitle = data.attrib.get('librarySectionTitle')

View file

@ -402,7 +402,7 @@ class Show(Video):
""" Load attribute values from Plex XML response. """ """ Load attribute values from Plex XML response. """
Video._loadData(self, data) Video._loadData(self, data)
# fix key if loaded from search # 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.art = data.attrib.get('art')
self.banner = data.attrib.get('banner') self.banner = data.attrib.get('banner')
self.childCount = utils.cast(int, data.attrib.get('childCount')) self.childCount = utils.cast(int, data.attrib.get('childCount'))