2016-03-21 04:26:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-01-02 21:06:40 +00:00
|
|
|
import requests
|
2014-12-29 03:21:58 +00:00
|
|
|
from plexapi import utils
|
2017-02-06 04:52:10 +00:00
|
|
|
from plexapi.base import PlexObject
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
|
|
|
2017-02-06 04:52:10 +00:00
|
|
|
class PlayQueue(PlexObject):
|
|
|
|
""" Summary
|
2014-12-29 03:21:58 +00:00
|
|
|
|
2017-02-06 04:52:10 +00:00
|
|
|
Attributes:
|
|
|
|
identifier (TYPE): Description
|
2017-01-02 21:06:40 +00:00
|
|
|
initpath (TYPE): Description
|
2017-02-06 04:52:10 +00:00
|
|
|
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
|
2014-12-29 03:21:58 +00:00
|
|
|
self.identifier = data.attrib.get('identifier')
|
|
|
|
self.mediaTagPrefix = data.attrib.get('mediaTagPrefix')
|
|
|
|
self.mediaTagVersion = data.attrib.get('mediaTagVersion')
|
|
|
|
self.playQueueID = data.attrib.get('playQueueID')
|
2017-02-02 03:53:05 +00:00
|
|
|
self.playQueueSelectedItemID = data.attrib.get('playQueueSelectedItemID')
|
|
|
|
self.playQueueSelectedItemOffset = data.attrib.get('playQueueSelectedItemOffset')
|
2014-12-29 03:21:58 +00:00
|
|
|
self.playQueueTotalCount = data.attrib.get('playQueueTotalCount')
|
|
|
|
self.playQueueVersion = data.attrib.get('playQueueVersion')
|
2017-02-06 04:52:10 +00:00
|
|
|
self.items = [self._buildItem(elem, self._initpath) for elem in data]
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
|
|
@classmethod
|
2016-04-14 02:36:12 +00:00
|
|
|
def create(cls, server, item, shuffle=0, repeat=0, includeChapters=1, includeRelated=1):
|
2017-02-06 04:52:10 +00:00
|
|
|
""" Create a new playqueue
|
2017-01-02 21:06:40 +00:00
|
|
|
|
2017-02-06 04:52:10 +00:00
|
|
|
Paramaters:
|
|
|
|
server (TYPE): Description
|
|
|
|
item (TYPE): Description
|
|
|
|
shuffle (int, optional): Description
|
|
|
|
repeat (int, optional): Description
|
|
|
|
includeChapters (int, optional): Description
|
|
|
|
includeRelated (int, optional): Description
|
2017-01-02 21:06:40 +00:00
|
|
|
|
2017-02-06 04:52:10 +00:00
|
|
|
Returns:
|
|
|
|
TYPE: Description
|
2017-01-02 21:06:40 +00:00
|
|
|
"""
|
2016-04-14 02:36:12 +00:00
|
|
|
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)
|
2017-02-06 04:52:10 +00:00
|
|
|
data = server._query(path, method=requests.post)
|
2014-12-29 03:21:58 +00:00
|
|
|
return cls(server, data, initpath=path)
|