python-plexapi/plexapi/photo.py

177 lines
5.1 KiB
Python
Raw Normal View History

2016-04-10 03:59:47 +00:00
# -*- coding: utf-8 -*-
"""
PlexPhoto
2017-01-02 21:06:40 +00:00
Attributes:
NA (TYPE): Description
2016-04-10 03:59:47 +00:00
"""
from plexapi import media, utils
from plexapi.utils import PlexPartialObject
NA = utils.NA
@utils.register_libtype
class Photoalbum(PlexPartialObject):
2017-01-02 21:06:40 +00:00
"""Summary
Attributes:
addedAt (TYPE): Description
art (TYPE): Description
composite (TYPE): Description
guid (TYPE): Description
index (TYPE): Description
key (TYPE): Description
librarySectionID (TYPE): Description
listType (str): Description
ratingKey (TYPE): Description
summary (TYPE): Description
thumb (TYPE): Description
title (TYPE): Description
TYPE (str): Description
type (TYPE): Description
updatedAt (TYPE): Description
"""
2016-04-10 03:59:47 +00:00
TYPE = 'photoalbum'
def __init__(self, server, data, initpath):
2017-01-02 21:06:40 +00:00
"""Summary
Args:
server (TYPE): Description
data (TYPE): Description
initpath (TYPE): Description
"""
2016-04-10 03:59:47 +00:00
super(Photoalbum, self).__init__(data, initpath, server)
def _loadData(self, data):
2017-01-02 21:06:40 +00:00
"""Summary
Args:
data (TYPE): Description
Returns:
TYPE: Description
"""
self.listType = 'photo'
2016-04-10 03:59:47 +00:00
self.addedAt = utils.toDatetime(data.attrib.get('addedAt', NA))
self.art = data.attrib.get('art', NA)
self.composite = data.attrib.get('composite', NA)
self.guid = data.attrib.get('guid', NA)
self.index = utils.cast(int, data.attrib.get('index', NA))
self.key = data.attrib.get('key', NA)
self.librarySectionID = data.attrib.get('librarySectionID', NA)
self.ratingKey = data.attrib.get('ratingKey', NA)
self.summary = data.attrib.get('summary', NA)
self.thumb = data.attrib.get('thumb', NA)
self.title = data.attrib.get('title', NA)
self.type = data.attrib.get('type', NA)
self.updatedAt = utils.toDatetime(data.attrib.get('updatedAt', NA))
2017-01-02 21:06:40 +00:00
2016-04-10 03:59:47 +00:00
def photos(self):
2017-01-02 21:06:40 +00:00
"""Summary
Returns:
TYPE: Description
"""
2016-04-10 03:59:47 +00:00
path = '/library/metadata/%s/children' % self.ratingKey
return utils.listItems(self.server, path, Photo.TYPE)
def photo(self, title):
2017-01-02 21:06:40 +00:00
"""Summary
Args:
title (TYPE): Description
Returns:
TYPE: Description
"""
2016-04-10 03:59:47 +00:00
path = '/library/metadata/%s/children' % self.ratingKey
return utils.findItem(self.server, path, title)
2017-01-02 21:06:40 +00:00
def section(self):
2017-01-02 21:06:40 +00:00
"""Summary
Returns:
TYPE: Description
"""
return self.server.library.sectionByID(self.librarySectionID)
2016-04-10 03:59:47 +00:00
@utils.register_libtype
class Photo(PlexPartialObject):
2017-01-02 21:06:40 +00:00
"""Summary
Attributes:
addedAt (TYPE): Description
index (TYPE): Description
key (TYPE): Description
listType (str): Description
media (TYPE): Description
originallyAvailableAt (TYPE): Description
parentKey (TYPE): Description
parentRatingKey (TYPE): Description
ratingKey (TYPE): Description
summary (TYPE): Description
thumb (TYPE): Description
title (TYPE): Description
TYPE (str): Description
type (TYPE): Description
updatedAt (TYPE): Description
year (TYPE): Description
"""
2016-04-10 03:59:47 +00:00
TYPE = 'photo'
def __init__(self, server, data, initpath):
2017-01-02 21:06:40 +00:00
"""Summary
Args:
server (TYPE): Description
data (TYPE): Description
initpath (TYPE): Description
"""
2016-04-10 03:59:47 +00:00
super(Photo, self).__init__(data, initpath, server)
def _loadData(self, data):
2017-01-02 21:06:40 +00:00
"""Summary
Args:
data (TYPE): Description
Returns:
TYPE: Description
"""
self.listType = 'photo'
2016-04-10 03:59:47 +00:00
self.addedAt = utils.toDatetime(data.attrib.get('addedAt', NA))
self.index = utils.cast(int, data.attrib.get('index', NA))
self.key = data.attrib.get('key', NA)
2017-01-02 21:06:40 +00:00
self.originallyAvailableAt = utils.toDatetime(
data.attrib.get('originallyAvailableAt', NA), '%Y-%m-%d')
2016-04-10 03:59:47 +00:00
self.parentKey = data.attrib.get('parentKey', NA)
self.parentRatingKey = data.attrib.get('parentRatingKey', NA)
self.ratingKey = data.attrib.get('ratingKey', NA)
self.summary = data.attrib.get('summary', NA)
self.thumb = data.attrib.get('thumb', NA)
self.title = data.attrib.get('title', NA)
self.type = data.attrib.get('type', NA)
self.updatedAt = utils.toDatetime(data.attrib.get('updatedAt', NA))
self.year = utils.cast(int, data.attrib.get('year', NA))
if self.isFullObject():
2017-01-02 21:06:40 +00:00
self.media = [media.Media(self.server, e, self.initpath, self)
for e in data if e.tag == media.Media.TYPE]
2016-04-10 03:59:47 +00:00
def photoalbum(self):
2017-01-02 21:06:40 +00:00
"""Summary
Returns:
TYPE: Description
"""
2016-04-10 03:59:47 +00:00
return utils.listItems(self.server, self.parentKey)[0]
def section(self):
2017-01-02 21:06:40 +00:00
"""Summary
Returns:
TYPE: Description
"""
return self.server.library.sectionByID(self.photoalbum().librarySectionID)