mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-22 19:53:17 +00:00
myplex tests passing
This commit is contained in:
parent
8212ca9c46
commit
bc421490db
4 changed files with 18 additions and 13 deletions
|
@ -20,7 +20,7 @@ class PlexObject(object):
|
|||
def __repr__(self):
|
||||
return '<%s>' % ':'.join([p for p in [
|
||||
self.__class__.__name__,
|
||||
self.__firstattr('_baseurl', 'key', 'id', 'uri'),
|
||||
self.__firstattr('_baseurl', 'key', 'id', 'playQueueID', 'uri'),
|
||||
self.__firstattr('title', 'name', 'username', 'librarySectionTitle', 'product')
|
||||
] if p])
|
||||
|
||||
|
@ -34,26 +34,28 @@ class PlexObject(object):
|
|||
value = value.replace('/library/metadata/','').replace('/children','')
|
||||
if value: return value[:20]
|
||||
|
||||
def _buildItem(self, elem, initpath, cls=None, bytag=False):
|
||||
def _buildItem(self, elem, cls=None, initpath=None, bytag=False):
|
||||
""" Factory function to build objects based on registered LIBRARY_TYPES. """
|
||||
initpath = initpath or self._initpath
|
||||
if cls: return cls(self._root, elem, initpath)
|
||||
libtype = elem.tag if bytag else elem.attrib.get('type')
|
||||
if libtype == 'photo' and elem.tag == 'Directory':
|
||||
libtype = 'photoalbum'
|
||||
if libtype in utils.LIBRARY_TYPES:
|
||||
cls = cls or utils.LIBRARY_TYPES[libtype]
|
||||
cls = utils.LIBRARY_TYPES[libtype]
|
||||
return cls(self._root, elem, initpath)
|
||||
raise UnknownType("Unknown library type <%s type='%s'../>" % (elem.tag, libtype))
|
||||
|
||||
def _buildItemOrNone(self, elem, initpath, cls=None, bytag=False):
|
||||
def _buildItemOrNone(self, elem, cls=None, initpath=None, bytag=False):
|
||||
""" Calls :func:`~plexapi.base.PlexObject._buildItem()` but returns
|
||||
None if elem is an unknown type.
|
||||
"""
|
||||
try:
|
||||
return self._buildItem(elem, initpath, cls, bytag)
|
||||
return self._buildItem(elem, cls, initpath, bytag)
|
||||
except UnknownType:
|
||||
return None
|
||||
|
||||
def _buildItems(self, data, cls=None):
|
||||
def _buildItems(self, data, cls=None, initpath=None, bytag=False):
|
||||
""" Build and return a list of items (optionally filtered by tag).
|
||||
|
||||
Parameters:
|
||||
|
@ -63,10 +65,8 @@ class PlexObject(object):
|
|||
guess item will be built.
|
||||
"""
|
||||
items = []
|
||||
tag = cls.TYPE if cls else None
|
||||
for elem in data:
|
||||
if elem.tag == tag:
|
||||
items.append(self._buildItemOrNone(elem, self._initpath, cls))
|
||||
items.append(self._buildItemOrNone(elem, cls, initpath, bytag))
|
||||
return [item for item in items if item]
|
||||
|
||||
def fetchItem(self, key, cls=None, bytag=False, tag=None, **attrs):
|
||||
|
@ -79,7 +79,7 @@ class PlexObject(object):
|
|||
continue
|
||||
if not all(elem.attrib.get(a,'').lower() == str(v).lower() for a,v in attrs.items()):
|
||||
continue
|
||||
return self._buildItem(elem, key, cls, bytag)
|
||||
return self._buildItem(elem, cls, key, bytag)
|
||||
raise NotFound('Unable to find elem: tag=%s, attrs=%s' % (tag, attrs))
|
||||
|
||||
def fetchItems(self, key, cls=None, bytag=False, tag=None, **attrs):
|
||||
|
@ -92,7 +92,7 @@ class PlexObject(object):
|
|||
continue
|
||||
if not all(elem.attrib.get(a,'').lower() == str(v).lower() for a,v in attrs.items()):
|
||||
continue
|
||||
items.append(self._buildItemOrNone(elem, key, cls, bytag))
|
||||
items.append(self._buildItemOrNone(elem, cls, key, bytag))
|
||||
return [item for item in items if item]
|
||||
|
||||
def _loadData(self, data):
|
||||
|
|
|
@ -246,7 +246,7 @@ class MyPlexResource(PlexObject):
|
|||
self.home = utils.cast(bool, data.attrib.get('home'))
|
||||
self.synced = utils.cast(bool, data.attrib.get('synced'))
|
||||
self.presence = utils.cast(bool, data.attrib.get('presence'))
|
||||
self.connections = self._buildItems(data, ResourceConnection)
|
||||
self.connections = self._buildItems(data, ResourceConnection, bytag=True)
|
||||
|
||||
def connect(self, ssl=None, safe=False):
|
||||
""" Returns a new :class:`~server.PlexServer` object. Often times there is more than
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from plexapi import utils
|
||||
from plexapi.base import PlexPartialObject, Playable
|
||||
from plexapi.exceptions import BadRequest
|
||||
from plexapi.playqueue import PlayQueue
|
||||
from plexapi.utils import cast, toDatetime
|
||||
|
||||
|
||||
|
@ -69,6 +70,10 @@ class Playlist(PlexPartialObject, Playable):
|
|||
"""Delete playlist."""
|
||||
return self._root._query(self.key, method=self._root._session.delete)
|
||||
|
||||
def playQueue(self, *args, **kwargs):
|
||||
""" Create a playqueue from this playlist. """
|
||||
return PlayQueue.create(self._root, self, *args, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def create(cls, server, title, items):
|
||||
"""Create a playlist."""
|
||||
|
|
|
@ -30,7 +30,7 @@ class PlayQueue(PlexObject):
|
|||
self.playQueueSelectedItemOffset = data.attrib.get('playQueueSelectedItemOffset')
|
||||
self.playQueueTotalCount = data.attrib.get('playQueueTotalCount')
|
||||
self.playQueueVersion = data.attrib.get('playQueueVersion')
|
||||
self.items = [self._buildItem(elem, self._initpath) for elem in data]
|
||||
self.items = self._buildItems(data)
|
||||
|
||||
@classmethod
|
||||
def create(cls, server, item, shuffle=0, repeat=0, includeChapters=1, includeRelated=1):
|
||||
|
|
Loading…
Reference in a new issue