inital dunder on Playlist

This commit is contained in:
Hellowlol 2017-10-05 22:24:49 +02:00
parent b385b7626b
commit a39326fab8

View file

@ -32,11 +32,24 @@ class Playlist(PlexPartialObject, Playable):
self.title = data.attrib.get('title') self.title = data.attrib.get('title')
self.type = data.attrib.get('type') self.type = data.attrib.get('type')
self.updatedAt = toDatetime(data.attrib.get('updatedAt')) self.updatedAt = toDatetime(data.attrib.get('updatedAt'))
self._items = None # cache for self.items
def __len__(self):
return len(self.items())
def __contains__(self, other):
return any(i.key == other.key for i in self.items())
def __getitem__(self, key):
return self.items()[key]
def items(self): def items(self):
""" Returns a list of all items in the playlist. """ """ Returns a list of all items in the playlist. """
if self._items is None:
key = '%s/items' % self.key key = '%s/items' % self.key
return self.fetchItems(key) items = self.fetchItems(key)
self._items = items
return self._items
def addItems(self, items): def addItems(self, items):
""" Add items to a playlist. """ """ Add items to a playlist. """