python-plexapi/plexapi/playlist.py

38 lines
1.4 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2016-02-03 18:07:53 +00:00
"""
PlexPlaylist
"""
from plexapi import utils
2016-02-03 18:07:53 +00:00
from plexapi.utils import cast, toDatetime
from plexapi.utils import PlexPartialObject
NA = utils.NA
2016-02-03 18:07:53 +00:00
@utils.register_libtype
class Playlist(PlexPartialObject):
2016-02-03 18:07:53 +00:00
TYPE = 'playlist'
def __init__(self, server, data, initpath):
super(Playlist, self).__init__(data, initpath, server)
2016-02-03 18:07:53 +00:00
def _loadData(self, data):
self.addedAt = toDatetime(data.attrib.get('addedAt', NA))
self.composite = data.attrib.get('composite', NA) # url to thumbnail
2016-02-03 18:07:53 +00:00
self.duration = cast(int, data.attrib.get('duration', NA))
self.durationInSeconds = cast(int, data.attrib.get('durationInSeconds', NA))
self.guid = data.attrib.get('guid', NA)
self.key = data.attrib.get('key', NA)
if self.key: self.key = self.key.replace('/items', '') # FIX_BUG_50
self.leafCount = cast(int, data.attrib.get('leafCount', NA))
self.playlistType = data.attrib.get('playlistType', NA)
self.ratingKey = data.attrib.get('ratingKey', NA)
self.smart = cast(bool, data.attrib.get('smart', NA))
self.summary = data.attrib.get('summary', NA)
self.title = data.attrib.get('title', NA)
self.type = data.attrib.get('type', NA)
self.updatedAt = toDatetime(data.attrib.get('updatedAt', NA))
2016-02-03 18:07:53 +00:00
def items(self):
path = '%s/items' % self.key
return utils.listItems(self.server, path)