2016-03-21 04:26:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-01-19 09:31:45 +00:00
|
|
|
"""
|
2016-03-21 04:26:02 +00:00
|
|
|
PlexAPI Audio
|
2016-01-19 09:31:45 +00:00
|
|
|
"""
|
2016-03-21 04:26:02 +00:00
|
|
|
from plexapi import media, utils
|
2016-04-04 03:55:29 +00:00
|
|
|
from plexapi.utils import Playable, PlexPartialObject
|
2016-03-17 05:14:31 +00:00
|
|
|
NA = utils.NA
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
|
2016-04-04 03:55:29 +00:00
|
|
|
class Audio(PlexPartialObject):
|
2016-04-11 03:49:23 +00:00
|
|
|
TYPE = None
|
2016-04-04 03:55:29 +00:00
|
|
|
|
|
|
|
def __init__(self, server, data, initpath):
|
|
|
|
super(Audio, self).__init__(data, initpath, server)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
2016-01-19 10:56:16 +00:00
|
|
|
def _loadData(self, data):
|
2016-04-12 02:43:21 +00:00
|
|
|
self.listType = 'audio'
|
2016-03-21 04:26:02 +00:00
|
|
|
self.addedAt = utils.toDatetime(data.attrib.get('addedAt', NA))
|
|
|
|
self.index = data.attrib.get('index', NA)
|
2016-01-19 10:56:16 +00:00
|
|
|
self.key = data.attrib.get('key', NA)
|
2016-03-21 04:26:02 +00:00
|
|
|
self.lastViewedAt = utils.toDatetime(data.attrib.get('lastViewedAt', NA))
|
2016-01-19 10:56:16 +00:00
|
|
|
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)
|
2016-03-21 04:26:02 +00:00
|
|
|
self.title = data.attrib.get('title', NA)
|
|
|
|
self.titleSort = data.attrib.get('titleSort', self.title)
|
|
|
|
self.type = data.attrib.get('type', NA)
|
2016-03-17 05:14:31 +00:00
|
|
|
self.updatedAt = utils.toDatetime(data.attrib.get('updatedAt', NA))
|
2016-03-21 04:26:02 +00:00
|
|
|
self.viewCount = utils.cast(int, data.attrib.get('viewCount', 0))
|
2016-04-04 03:55:29 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def thumbUrl(self):
|
|
|
|
return self.server.url(self.thumb)
|
|
|
|
|
|
|
|
def refresh(self):
|
|
|
|
self.server.query('%s/refresh' % self.key, method=self.server.session.put)
|
2016-04-12 02:43:21 +00:00
|
|
|
|
|
|
|
def section(self):
|
|
|
|
return self.server.library.sectionByID(self.librarySectionID)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
2016-03-15 02:20:02 +00:00
|
|
|
|
2016-03-17 05:14:31 +00:00
|
|
|
@utils.register_libtype
|
2016-01-19 09:31:45 +00:00
|
|
|
class Artist(Audio):
|
|
|
|
TYPE = 'artist'
|
|
|
|
|
|
|
|
def _loadData(self, data):
|
2016-04-07 05:39:04 +00:00
|
|
|
Audio._loadData(self, data)
|
2016-03-21 04:26:02 +00:00
|
|
|
self.art = data.attrib.get('art', NA)
|
|
|
|
self.guid = data.attrib.get('guid', NA)
|
2016-04-04 03:55:29 +00:00
|
|
|
self.key = self.key.replace('/children', '') # FIX_BUG_50
|
2016-04-12 02:43:21 +00:00
|
|
|
self.location = utils.findLocations(data, single=True)
|
2016-03-21 04:26:02 +00:00
|
|
|
if self.isFullObject():
|
2016-03-22 03:12:12 +00:00
|
|
|
self.countries = [media.Country(self.server, e) for e in data if e.tag == media.Country.TYPE]
|
|
|
|
self.genres = [media.Genre(self.server, e) for e in data if e.tag == media.Genre.TYPE]
|
|
|
|
self.similar = [media.Similar(self.server, e) for e in data if e.tag == media.Similar.TYPE]
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def albums(self):
|
2016-04-04 03:55:29 +00:00
|
|
|
path = '%s/children' % self.key
|
2016-03-21 04:26:02 +00:00
|
|
|
return utils.listItems(self.server, path, Album.TYPE)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def album(self, title):
|
2016-04-04 03:55:29 +00:00
|
|
|
path = '%s/children' % self.key
|
2016-03-21 04:26:02 +00:00
|
|
|
return utils.findItem(self.server, path, title)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def tracks(self, watched=None):
|
2016-04-04 03:55:29 +00:00
|
|
|
path = '%s/allLeaves' % self.key
|
|
|
|
return utils.listItems(self.server, path, watched=watched)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def track(self, title):
|
2016-04-04 03:55:29 +00:00
|
|
|
path = '%s/allLeaves' % self.key
|
2016-03-21 04:26:02 +00:00
|
|
|
return utils.findItem(self.server, path, title)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def get(self, title):
|
|
|
|
return self.track(title)
|
|
|
|
|
|
|
|
|
2016-03-17 05:14:31 +00:00
|
|
|
@utils.register_libtype
|
2016-01-19 09:31:45 +00:00
|
|
|
class Album(Audio):
|
|
|
|
TYPE = 'album'
|
|
|
|
|
|
|
|
def _loadData(self, data):
|
2016-04-07 05:39:04 +00:00
|
|
|
Audio._loadData(self, data)
|
2016-03-21 04:26:02 +00:00
|
|
|
self.art = data.attrib.get('art', NA)
|
2016-04-04 03:55:29 +00:00
|
|
|
self.key = self.key.replace('/children', '') # FIX_BUG_50
|
2016-03-21 04:26:02 +00:00
|
|
|
self.originallyAvailableAt = utils.toDatetime(data.attrib.get('originallyAvailableAt', NA), '%Y-%m-%d')
|
2016-01-19 09:31:45 +00:00
|
|
|
self.parentKey = data.attrib.get('parentKey', NA)
|
2016-03-21 04:26:02 +00:00
|
|
|
self.parentRatingKey = data.attrib.get('parentRatingKey', NA)
|
2016-01-19 09:31:45 +00:00
|
|
|
self.parentThumb = data.attrib.get('parentThumb', NA)
|
2016-03-21 04:26:02 +00:00
|
|
|
self.parentTitle = data.attrib.get('parentTitle', NA)
|
|
|
|
self.studio = data.attrib.get('studio', NA)
|
2016-03-17 05:14:31 +00:00
|
|
|
self.year = utils.cast(int, data.attrib.get('year', NA))
|
2016-03-21 04:26:02 +00:00
|
|
|
if self.isFullObject():
|
2016-03-22 03:12:12 +00:00
|
|
|
self.genres = [media.Genre(self.server, e) for e in data if e.tag == media.Genre.TYPE]
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def tracks(self, watched=None):
|
2016-04-04 03:55:29 +00:00
|
|
|
path = '%s/children' % self.key
|
|
|
|
return utils.listItems(self.server, path, watched=watched)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def track(self, title):
|
2016-04-04 03:55:29 +00:00
|
|
|
path = '%s/children' % self.key
|
2016-03-21 04:26:02 +00:00
|
|
|
return utils.findItem(self.server, path, title)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def get(self, title):
|
|
|
|
return self.track(title)
|
|
|
|
|
|
|
|
def artist(self):
|
2016-03-21 04:26:02 +00:00
|
|
|
return utils.listItems(self.server, self.parentKey)[0]
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def watched(self):
|
|
|
|
return self.tracks(watched=True)
|
|
|
|
|
|
|
|
def unwatched(self):
|
|
|
|
return self.tracks(watched=False)
|
|
|
|
|
|
|
|
|
2016-03-17 05:14:31 +00:00
|
|
|
@utils.register_libtype
|
2016-04-04 03:55:29 +00:00
|
|
|
class Track(Audio, Playable):
|
2016-01-19 09:31:45 +00:00
|
|
|
TYPE = 'track'
|
|
|
|
|
|
|
|
def _loadData(self, data):
|
2016-04-07 05:39:04 +00:00
|
|
|
Audio._loadData(self, data)
|
|
|
|
Playable._loadData(self, data)
|
2016-03-21 04:26:02 +00:00
|
|
|
self.art = data.attrib.get('art', NA)
|
|
|
|
self.chapterSource = data.attrib.get('chapterSource', NA)
|
|
|
|
self.duration = utils.cast(int, data.attrib.get('duration', NA))
|
|
|
|
self.grandparentArt = data.attrib.get('grandparentArt', NA)
|
2016-01-19 09:31:45 +00:00
|
|
|
self.grandparentKey = data.attrib.get('grandparentKey', NA)
|
2016-03-21 04:26:02 +00:00
|
|
|
self.grandparentRatingKey = data.attrib.get('grandparentRatingKey', NA)
|
2016-01-19 09:31:45 +00:00
|
|
|
self.grandparentThumb = data.attrib.get('grandparentThumb', NA)
|
2016-03-21 04:26:02 +00:00
|
|
|
self.grandparentTitle = data.attrib.get('grandparentTitle', NA)
|
|
|
|
self.guid = data.attrib.get('guid', NA)
|
|
|
|
self.originalTitle = data.attrib.get('originalTitle', NA)
|
2016-01-19 09:31:45 +00:00
|
|
|
self.parentIndex = data.attrib.get('parentIndex', NA)
|
2016-03-21 04:26:02 +00:00
|
|
|
self.parentKey = data.attrib.get('parentKey', NA)
|
|
|
|
self.parentRatingKey = data.attrib.get('parentRatingKey', NA)
|
2016-01-19 09:31:45 +00:00
|
|
|
self.parentThumb = data.attrib.get('parentThumb', NA)
|
2016-03-21 04:26:02 +00:00
|
|
|
self.parentTitle = data.attrib.get('parentTitle', NA)
|
|
|
|
self.primaryExtraKey = data.attrib.get('primaryExtraKey', NA)
|
|
|
|
self.ratingCount = utils.cast(int, data.attrib.get('ratingCount', NA))
|
|
|
|
self.viewOffset = utils.cast(int, data.attrib.get('viewOffset', 0))
|
|
|
|
self.year = utils.cast(int, data.attrib.get('year', NA))
|
|
|
|
if self.isFullObject():
|
2016-03-22 03:12:12 +00:00
|
|
|
self.moods = [media.Mood(self.server, e) for e in data if e.tag == media.Mood.TYPE]
|
|
|
|
self.media = [media.Media(self.server, e, self.initpath, self) for e in data if e.tag == media.Media.TYPE]
|
2016-04-07 05:39:04 +00:00
|
|
|
# data for active sessions and history
|
2016-03-21 04:26:02 +00:00
|
|
|
self.sessionKey = utils.cast(int, data.attrib.get('sessionKey', NA))
|
2016-04-07 05:39:04 +00:00
|
|
|
self.username = utils.findUsername(data)
|
2016-04-04 03:17:29 +00:00
|
|
|
self.player = utils.findPlayer(self.server, data)
|
|
|
|
self.transcodeSession = utils.findTranscodeSession(self.server, data)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def thumbUrl(self):
|
2016-03-21 04:26:02 +00:00
|
|
|
return self.server.url(self.parentThumb)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def album(self):
|
2016-03-21 04:26:02 +00:00
|
|
|
return utils.listItems(self.server, self.parentKey)[0]
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def artist(self):
|
2016-03-21 04:26:02 +00:00
|
|
|
return utils.listItems(self.server, self.grandparentKey)[0]
|