python-plexapi/plexapi/playqueue.py

65 lines
2.5 KiB
Python

# -*- coding: utf-8 -*-
import requests
from plexapi import utils
from plexapi.base import PlexObject
class PlayQueue(PlexObject):
""" Summary
Attributes:
identifier (TYPE): Description
initpath (TYPE): Description
items (TYPE): Description
mediaTagPrefix (TYPE): Description
mediaTagVersion (TYPE): Description
playQueueID (TYPE): Description
playQueueSelectedItemID (TYPE): Description
playQueueSelectedItemOffset (TYPE): Description
playQueueTotalCount (TYPE): Description
playQueueVersion (TYPE): Description
server (TYPE): Description
"""
def _loadData(self, data):
self._data = data
self.identifier = data.attrib.get('identifier')
self.mediaTagPrefix = data.attrib.get('mediaTagPrefix')
self.mediaTagVersion = data.attrib.get('mediaTagVersion')
self.playQueueID = data.attrib.get('playQueueID')
self.playQueueSelectedItemID = data.attrib.get('playQueueSelectedItemID')
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]
@classmethod
def create(cls, server, item, shuffle=0, repeat=0, includeChapters=1, includeRelated=1):
""" Create a new playqueue
Paramaters:
server (TYPE): Description
item (TYPE): Description
shuffle (int, optional): Description
repeat (int, optional): Description
includeChapters (int, optional): Description
includeRelated (int, optional): Description
Returns:
TYPE: Description
"""
args = {}
args['includeChapters'] = includeChapters
args['includeRelated'] = includeRelated
args['repeat'] = repeat
args['shuffle'] = shuffle
if item.type == 'playlist':
args['playlistID'] = item.ratingKey
args['type'] = item.playlistType
else:
uuid = item.section().uuid
args['key'] = item.key
args['type'] = item.listType
args['uri'] = 'library://%s/item/%s' % (uuid, item.key)
path = '/playQueues%s' % utils.joinArgs(args)
data = server._query(path, method=requests.post)
return cls(server, data, initpath=path)