Finish updating audio.py for Sphinx docs

This commit is contained in:
Michael Shepanski 2017-01-22 01:37:39 -05:00
parent 10a285ec90
commit 5ba1c4df8e
3 changed files with 100 additions and 159 deletions

View file

@ -44,7 +44,7 @@ napoleon_use_ivar = True
napoleon_use_param = True napoleon_use_param = True
napoleon_use_rtype = True napoleon_use_rtype = True
napoleon_use_keyword = True napoleon_use_keyword = True
autodoc_member_order = 'bysource'
# -- General Configuration ------------------------------------------------ # -- General Configuration ------------------------------------------------
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.

View file

@ -7,45 +7,32 @@ NA = utils.NA
class Audio(PlexPartialObject): class Audio(PlexPartialObject):
"""Base class for audio. """ Base class for audio :class:`~plexapi.audio.Artist`, :class:`~plexapi.audio.Album`
and :class:`~plexapi.audio.Track` objects.
Attributes: Attributes:
addedAt (int): int from epoch, datetime.datetime addedAt (datetime): Datetime this item was added to the library.
index (sting): 1 index (sting): Index Number (often the track number).
key (str): Fx /library/metadata/102631 key (str): API URL (/library/metadata/<ratingkey>).
lastViewedAt (datetime.datetime): parse int into datetime.datetime. lastViewedAt (datetime): Datetime item was last accessed.
librarySectionID (int): librarySectionID (int): :class:`~plexapi.library.LibrarySection` ID.
listType (str): audio listType (str): Hardcoded as 'audio' (useful for search filters).
ratingKey (int): Unique key to identify this item ratingKey (int): Unique key identifying this item.
summary (str): Summery of the artist, track, album summary (str): Summary of the artist, track, or album.
thumb (str): Url to thumb image thumb (str): URL to thumbnail image.
title (str): Fx Aerosmith title (str): Artist, Album or Track title. (Jason Mraz, We Sing, Lucky, etc.)
titleSort (str): Defaults title if None titleSort (str): Title to use when sorting (defaults to title).
TYPE (str): overwritten by subclass type (str): 'artist', 'album', or 'track'.
type (string, NA): Description updatedAt (datatime): Datetime this item was updated.
updatedAt (datatime.datetime): parse int to datetime.datetime viewCount (int): Count of times this item was accessed.
viewCount (int): How many time has this item been played
""" """
TYPE = None TYPE = None
def __init__(self, server, data, initpath): def __init__(self, server, data, initpath):
"""Used to set the attributes.
Args:
server (Plexserver): PMS your connected to
data (Element): XML reponse from PMS as Element
normally built from server.query
initpath (str): Fx /library/sections/7/all
"""
super(Audio, self).__init__(data, initpath, server) super(Audio, self).__init__(data, initpath, server)
def _loadData(self, data): def _loadData(self, data):
"""Used to set the attributes. """ Load attribute values from Plex XML response. """
Args:
data (Element): XML reponse from PMS as Element
normally built from server.query
"""
self.listType = 'audio' self.listType = 'audio'
self.addedAt = utils.toDatetime(data.attrib.get('addedAt', NA)) self.addedAt = utils.toDatetime(data.attrib.get('addedAt', NA))
self.index = data.attrib.get('index', NA) self.index = data.attrib.get('index', NA)
@ -63,125 +50,104 @@ class Audio(PlexPartialObject):
@property @property
def thumbUrl(self): def thumbUrl(self):
"""Return url to thumb image.""" """ Returns the URL to this items thumbnail image. """
if self.thumb: if self.thumb:
return self.server.url(self.thumb) return self.server.url(self.thumb)
def refresh(self): def refresh(self):
"""Refresh the metadata.""" """ Tells Plex to refresh the metadata for this and all subitems. """
self.server.query('%s/refresh' % self.key, method=self.server.session.put) self.server.query('%s/refresh' % self.key, method=self.server.session.put)
def section(self): def section(self):
"""Library section.""" """ Returns the :class:`~plexapi.library.LibrarySection` this item belongs to. """
return self.server.library.sectionByID(self.librarySectionID) return self.server.library.sectionByID(self.librarySectionID)
@utils.register_libtype @utils.register_libtype
class Artist(Audio): class Artist(Audio):
"""Artist. """ Represents a single audio artist.
Attributes: Attributes:
art (str): /library/metadata/102631/art/1469310342 art (str): Artist artwork (/library/metadata/<ratingkey>/art/<artid>)
countries (list): List of media.County fx [<Country:24200:United.States>] countries (list): List of :class:`~plexapi.media.Country` objects this artist respresents.
genres (list): List of media.Genre fx [<Genre:25555:Classic.Rock>] genres (list): List of :class:`~plexapi.media.Genre` objects this artist respresents.
guid (str): Fx guid com.plexapp.agents.plexmusic://gracenote/artist/05517B8701668D28?lang=en guid (str): Unknown (unique ID; com.plexapp.agents.plexmusic://gracenote/artist/05517B8701668D28?lang=en)
key (str): Fx /library/metadata/102631 key (str): API URL (/library/metadata/<ratingkey>).
location (str): Filepath location (str): Filepath this artist is found on disk.
similar (list): List of media.Similar fx [<Similar:25220:Guns.N'.Roses>] similar (list): List of :class:`~plexapi.media.Similar` artists.
TYPE (str): artist
""" """
TYPE = 'artist' TYPE = 'artist'
def _loadData(self, data): def _loadData(self, data):
"""Used to set the attributes. """ Load attribute values from Plex XML response. """
Args:
data (Element): XML reponse from PMS as Element
normally built from server.query
"""
Audio._loadData(self, data) Audio._loadData(self, data)
self.art = data.attrib.get('art', NA) self.art = data.attrib.get('art', NA)
self.guid = data.attrib.get('guid', NA) self.guid = data.attrib.get('guid', NA)
self.key = self.key.replace('/children', '') # FIX_BUG_50 self.key = self.key.replace('/children', '') # FIX_BUG_50
self.location = utils.findLocations(data, single=True) self.location = utils.findLocations(data, single=True)
if self.isFullObject(): # check if this is needed if self.isFullObject(): # check if this is needed
self.countries = [media.Country(self.server, e) self.countries = [media.Country(self.server, e) for e in data if e.tag == media.Country.TYPE]
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.genres = [media.Genre(self.server, e) self.similar = [media.Similar(self.server, e) for e in data if e.tag == media.Similar.TYPE]
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]
def albums(self): def albums(self):
"""Return a list of Albums by thus artist.""" """ Returns a list of :class:`plexapi.audio.Album` objects by this artist. """
path = '%s/children' % self.key path = '%s/children' % self.key
return utils.listItems(self.server, path, Album.TYPE) return utils.listItems(self.server, path, Album.TYPE)
def album(self, title): def album(self, title):
"""Return a album from this artist that match title.""" """ Returns the :class:`plexapi.audio.Album` that matches the specified title.
Parameters:
title (str): Title of the album to return.
"""
path = '%s/children' % self.key path = '%s/children' % self.key
return utils.findItem(self.server, path, title) return utils.findItem(self.server, path, title)
def tracks(self, watched=None): def tracks(self):
"""Return all tracks to this artist. """ Returns a list of :class:`plexapi.audio.Track` objects by this artist. """
Args:
watched(None, False, True): Default to None.
Returns:
List: of Track
"""
path = '%s/allLeaves' % self.key path = '%s/allLeaves' % self.key
return utils.listItems(self.server, path, watched=watched) return utils.listItems(self.server, path)
def track(self, title): def track(self, title):
"""Return a Track that matches title. """ Returns the :class:`plexapi.audio.Track` that matches the specified title.
Args: Parameters:
title (str): Fx song name title (str): Title of the track to return.
Returns:
Track:
""" """
path = '%s/allLeaves' % self.key path = '%s/allLeaves' % self.key
return utils.findItem(self.server, path, title) return utils.findItem(self.server, path, title)
def get(self, title): def get(self, title):
"""Alias. See track.""" """ Alias of :func:`~plexapi.audio.Artist.track`. """
return self.track(title) return self.track(title)
@utils.register_libtype @utils.register_libtype
class Album(Audio): class Album(Audio):
"""Album. """ Represents a single audio album.
Attributes: Attributes:
art (str): Fx /library/metadata/102631/art/1469310342 art (str): Album artwork (/library/metadata/<ratingkey>/art/<artid>)
genres (list): List of media.Genre genres (list): List of :class:`~plexapi.media.Genre` objects this album respresents.
key (str): Fx /library/metadata/102632 key (str): API URL (/library/metadata/<ratingkey>).
originallyAvailableAt (TYPE): Description originallyAvailableAt (datetime): Datetime this album was released.
parentKey (str): /library/metadata/102631 parentKey (str): API URL of this artist.
parentRatingKey (int): Fx 1337 parentRatingKey (int): Unique key identifying artist.
parentThumb (TYPE): Relative url to parent thumb image parentThumb (str): URL to artist thumbnail image.
parentTitle (str): Aerosmith parentTitle (str): Name of the artist for this album.
studio (str): studio (str): Studio that released this album.
TYPE (str): album year (int): Year this album was released.
year (int): 1999
""" """
TYPE = 'album' TYPE = 'album'
def _loadData(self, data): def _loadData(self, data):
"""Used to set the attributes. """ Load attribute values from Plex XML response. """
Args:
data (Element): XML reponse from PMS as Element
normally built from server.query
"""
Audio._loadData(self, data) Audio._loadData(self, data)
self.art = data.attrib.get('art', NA) self.art = data.attrib.get('art', NA)
self.key = self.key.replace('/children', '') # FIX_BUG_50 self.key = self.key.replace('/children', '') # fixes bug #50
self.originallyAvailableAt = utils.toDatetime(data.attrib.get('originallyAvailableAt', NA), '%Y-%m-%d') self.originallyAvailableAt = utils.toDatetime(data.attrib.get('originallyAvailableAt', NA), '%Y-%m-%d')
self.parentKey = data.attrib.get('parentKey', NA) self.parentKey = data.attrib.get('parentKey', NA)
self.parentRatingKey = data.attrib.get('parentRatingKey', NA) self.parentRatingKey = data.attrib.get('parentRatingKey', NA)
@ -193,87 +159,64 @@ class Album(Audio):
self.genres = [media.Genre(self.server, e) for e in data if e.tag == media.Genre.TYPE] self.genres = [media.Genre(self.server, e) for e in data if e.tag == media.Genre.TYPE]
def tracks(self, watched=None): def tracks(self, watched=None):
"""Return all tracks to this album. """ Returns a list of :class:`plexapi.audio.Track` objects in this album. """
Args:
watched(None, False, True): Default to None.
Returns:
List: of Track
"""
path = '%s/children' % self.key path = '%s/children' % self.key
return utils.listItems(self.server, path, watched=watched) return utils.listItems(self.server, path, watched=watched)
def track(self, title): def track(self, title):
"""Return a Track that matches title. """ Returns the :class:`plexapi.audio.Track` that matches the specified title.
Args: Parameters:
title (str): Fx song name title (str): Title of the track to return.
Returns:
Track:
""" """
path = '%s/children' % self.key path = '%s/children' % self.key
return utils.findItem(self.server, path, title) return utils.findItem(self.server, path, title)
def get(self, title): def get(self, title):
"""Alias. See track.""" """ Alias of :func:`~plexapi.audio.Album.track`. """
return self.track(title) return self.track(title)
def artist(self): def artist(self):
"""Return Artist of this album.""" """ Return :func:`~plexapi.audio.Artist` of this album. """
return utils.listItems(self.server, self.parentKey)[0] return utils.listItems(self.server, self.parentKey)[0]
def watched(self):
"""Return Track that is lisson on."""
return self.tracks(watched=True)
def unwatched(self):
"""Return Track that is not lisson on."""
return self.tracks(watched=False)
@utils.register_libtype @utils.register_libtype
class Track(Audio, Playable): class Track(Audio, Playable):
"""Track. """ Represents a single audio track.
Attributes: Attributes:
art (str): Relative path fx /library/metadata/102631/art/1469310342 art (str): Track artwork (/library/metadata/<ratingkey>/art/<artid>)
chapterSource (TYPE): Description chapterSource (TYPE): Unknown
duration (TYPE): Description duration (int): Length of this album in seconds.
grandparentArt (str): Relative path grandparentArt (str): Artist artowrk.
grandparentKey (str): Relative path Fx /library/metadata/102631 grandparentKey (str): Artist API URL.
grandparentRatingKey (TYPE): Description grandparentRatingKey (str): Unique key identifying artist.
grandparentThumb (str): Relative path to Artist thumb img grandparentThumb (str): URL to artist thumbnail image.
grandparentTitle (str): Aerosmith grandparentTitle (str): Name of the artist for this track.
guid (TYPE): Description guid (str): Unknown (unique ID).
media (list): List of media.Media media (list): List of :class:`~plexapi.media.Media` objects for this track.
moods (list): List of media.Moods moods (list): List of :class:`~plexapi.media.Mood` objects for this track.
originalTitle (str): Some track title originalTitle (str): Original track title (if translated).
parentIndex (int): 1 parentIndex (int): Album index.
parentKey (str): Relative path Fx /library/metadata/102632 parentKey (str): Album API URL.
parentRatingKey (int): 1337 parentRatingKey (int): Unique key identifying album.
parentThumb (str): Relative path to Album thumb parentThumb (str): URL to album thumbnail image.
parentTitle (str): Album title parentTitle (str): Name of the album for this track.
player (None): #TODO primaryExtraKey (str): Unknown
primaryExtraKey (TYPE): #TODO ratingCount (int): Rating of this track (1-10?)
ratingCount (int): 10 viewOffset (int): Unknown
sessionKey (int): Description year (int): Year this track was released.
transcodeSession (None): sessionKey (int): Session Key (active sessions only).
TYPE (str): track username (str): Username of person playing this track (active sessions only).
username (str): username@mail.com player (str): :class:`~plexapi.client.PlexClient` for playing track (active sessions only).
viewOffset (int): 100 transcodeSession (None): :class:`~plexapi.media.TranscodeSession` for playing track (active sessions only).
year (int): 1999
""" """
TYPE = 'track' TYPE = 'track'
def _loadData(self, data): def _loadData(self, data):
"""Used to set the attributes """ Load attribute values from Plex XML response. """
Args:
data (Element): Usually built from server.query
"""
Audio._loadData(self, data) Audio._loadData(self, data)
Playable._loadData(self, data) Playable._loadData(self, data)
self.art = data.attrib.get('art', NA) self.art = data.attrib.get('art', NA)
@ -296,10 +239,8 @@ class Track(Audio, Playable):
self.viewOffset = utils.cast(int, data.attrib.get('viewOffset', 0)) self.viewOffset = utils.cast(int, data.attrib.get('viewOffset', 0))
self.year = utils.cast(int, data.attrib.get('year', NA)) self.year = utils.cast(int, data.attrib.get('year', NA))
if self.isFullObject(): # check me if self.isFullObject(): # check me
self.moods = [media.Mood(self.server, e) self.moods = [media.Mood(self.server, e) for e in data if e.tag == media.Mood.TYPE]
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]
self.media = [media.Media(self.server, e, self.initpath, self)
for e in data if e.tag == media.Media.TYPE]
# data for active sessions and history # data for active sessions and history
self.sessionKey = utils.cast(int, data.attrib.get('sessionKey', NA)) self.sessionKey = utils.cast(int, data.attrib.get('sessionKey', NA))
self.username = utils.findUsername(data) self.username = utils.findUsername(data)
@ -308,14 +249,14 @@ class Track(Audio, Playable):
@property @property
def thumbUrl(self): def thumbUrl(self):
"""Return url to thumb image.""" """ Returns the URL thumbnail image for this track's album. """
if self.parentThumb: if self.parentThumb:
return self.server.url(self.parentThumb) return self.server.url(self.parentThumb)
def album(self): def album(self):
"""Return this track's Album.""" """ Return this track's :class:`~plexapi.audio.Album`. """
return utils.listItems(self.server, self.parentKey)[0] return utils.listItems(self.server, self.parentKey)[0]
def artist(self): def artist(self):
"""Return this track's Artist.""" """ Return this track's :class:`~plexapi.audio.Artist`. """
return utils.listItems(self.server, self.grandparentKey)[0] return utils.listItems(self.server, self.grandparentKey)[0]

View file

@ -10,7 +10,7 @@ from requests.status_codes import _codes as codes
class MyPlexAccount(object): class MyPlexAccount(object):
""" MyPlex account and profile information. The easiest way to build """ MyPlex account and profile information. The easiest way to build
this object is by calling the staticmethod :func:`~myplex.MyPlexAccount.signin` this object is by calling the staticmethod :func:`~plexapi.myplex.MyPlexAccount.signin`
with your username and password. This object represents the data found Account on with your username and password. This object represents the data found Account on
the myplex.tv servers at the url https://plex.tv/users/account. the myplex.tv servers at the url https://plex.tv/users/account.