mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 22:24:12 +00:00
commit
f533cb7450
5 changed files with 52 additions and 7 deletions
|
@ -78,6 +78,10 @@ class Artist(Audio):
|
|||
self.similar = self.findItems(data, media.Similar)
|
||||
self.collections = self.findItems(data, media.Collection)
|
||||
|
||||
def __iter__(self):
|
||||
for album in self.albums():
|
||||
yield album
|
||||
|
||||
def album(self, title):
|
||||
""" Returns the :class:`~plexapi.audio.Album` that matches the specified title.
|
||||
|
||||
|
@ -151,6 +155,10 @@ class Album(Audio):
|
|||
TAG = 'Directory'
|
||||
TYPE = 'album'
|
||||
|
||||
def __iter__(self):
|
||||
for track in self.tracks:
|
||||
yield track
|
||||
|
||||
def _loadData(self, data):
|
||||
""" Load attribute values from Plex XML response. """
|
||||
Audio._loadData(self, data)
|
||||
|
|
|
@ -269,6 +269,12 @@ class PlexPartialObject(PlexObject):
|
|||
def __eq__(self, other):
|
||||
return other is not None and self.key == other.key
|
||||
|
||||
def __hash__(self):
|
||||
return hash(repr(self))
|
||||
|
||||
def __iter__(self):
|
||||
yield self
|
||||
|
||||
def __getattribute__(self, attr):
|
||||
# Dragons inside.. :-/
|
||||
value = utils.getattributeOrNone(PlexPartialObject, self, attr)
|
||||
|
|
|
@ -32,11 +32,24 @@ class Playlist(PlexPartialObject, Playable):
|
|||
self.title = data.attrib.get('title')
|
||||
self.type = data.attrib.get('type')
|
||||
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):
|
||||
""" Returns a list of all items in the playlist. """
|
||||
key = '%s/items' % self.key
|
||||
return self.fetchItems(key)
|
||||
if self._items is None:
|
||||
key = '%s/items' % self.key
|
||||
items = self.fetchItems(key)
|
||||
self._items = items
|
||||
return self._items
|
||||
|
||||
def addItems(self, items):
|
||||
""" Add items to a playlist. """
|
||||
|
@ -53,24 +66,32 @@ class Playlist(PlexPartialObject, Playable):
|
|||
key = '%s/items%s' % (self.key, utils.joinArgs({
|
||||
'uri': 'library://%s/directory//library/metadata/%s' % (uuid, ratingKeys)
|
||||
}))
|
||||
return self._server.query(key, method=self._server._session.put)
|
||||
result = self._server.query(key, method=self._server._session.put)
|
||||
self.reload()
|
||||
return result
|
||||
|
||||
def removeItem(self, item):
|
||||
""" Remove a file from a playlist. """
|
||||
key = '%s/items/%s' % (self.key, item.playlistItemID)
|
||||
return self._server.query(key, method=self._server._session.delete)
|
||||
result = self._server.query(key, method=self._server._session.delete)
|
||||
self.reload()
|
||||
return result
|
||||
|
||||
def moveItem(self, item, after=None):
|
||||
""" Move a to a new position in playlist. """
|
||||
key = '%s/items/%s/move' % (self.key, item.playlistItemID)
|
||||
if after:
|
||||
key += '?after=%s' % after.playlistItemID
|
||||
return self._server.query(key, method=self._server._session.put)
|
||||
result = self._server.query(key, method=self._server._session.put)
|
||||
self.reload()
|
||||
return result
|
||||
|
||||
def edit(self, title=None, summary=None):
|
||||
""" Edit playlist. """
|
||||
key = '/library/metadata/%s%s' % (self.ratingKey, utils.joinArgs({'title': title, 'summary': summary}))
|
||||
return self._server.query(key, method=self._server._session.put)
|
||||
result = self._server.query(key, method=self._server._session.put)
|
||||
self.reload()
|
||||
return result
|
||||
|
||||
def delete(self):
|
||||
""" Delete playlist. """
|
||||
|
|
|
@ -24,6 +24,7 @@ class Video(PlexPartialObject):
|
|||
updatedAt (datatime): Datetime this item was updated.
|
||||
viewCount (int): Count of times this item was accessed.
|
||||
"""
|
||||
|
||||
def _loadData(self, data):
|
||||
""" Load attribute values from Plex XML response. """
|
||||
self._data = data
|
||||
|
@ -214,6 +215,10 @@ class Show(Video):
|
|||
TAG = 'Directory'
|
||||
TYPE = 'show'
|
||||
|
||||
def __iter__(self):
|
||||
for season in self.seasons():
|
||||
yield season
|
||||
|
||||
def _loadData(self, data):
|
||||
""" Load attribute values from Plex XML response. """
|
||||
Video._loadData(self, data)
|
||||
|
@ -335,6 +340,10 @@ class Season(Video):
|
|||
TAG = 'Directory'
|
||||
TYPE = 'season'
|
||||
|
||||
def __iter__(self):
|
||||
for episode in self.episodes():
|
||||
yield episode
|
||||
|
||||
def _loadData(self, data):
|
||||
""" Load attribute values from Plex XML response. """
|
||||
Video._loadData(self, data)
|
||||
|
|
|
@ -233,7 +233,8 @@ def test_server_account(plex):
|
|||
assert account.signInState == 'ok'
|
||||
assert isinstance(account.subscriptionActive, bool)
|
||||
if account.subscriptionActive: assert len(account.subscriptionFeatures)
|
||||
else: assert sorted(account.subscriptionFeatures) == ['download_certificates', 'federated-auth', 'news']
|
||||
else: assert sorted(account.subscriptionFeatures) == ['adaptive_bitrate', 'download_certificates',
|
||||
'federated-auth', 'news']
|
||||
assert account.subscriptionState == 'Active' if account.subscriptionActive else 'Unknown'
|
||||
assert re.match(utils.REGEX_EMAIL, account.username)
|
||||
|
||||
|
|
Loading…
Reference in a new issue