mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-22 03:33:08 +00:00
Finish updating audio.py for Sphinx docs
This commit is contained in:
parent
10a285ec90
commit
5ba1c4df8e
3 changed files with 100 additions and 159 deletions
|
@ -44,7 +44,7 @@ napoleon_use_ivar = True
|
|||
napoleon_use_param = True
|
||||
napoleon_use_rtype = True
|
||||
napoleon_use_keyword = True
|
||||
|
||||
autodoc_member_order = 'bysource'
|
||||
|
||||
# -- General Configuration ------------------------------------------------
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
|
|
255
plexapi/audio.py
255
plexapi/audio.py
|
@ -7,45 +7,32 @@ NA = utils.NA
|
|||
|
||||
|
||||
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:
|
||||
addedAt (int): int from epoch, datetime.datetime
|
||||
index (sting): 1
|
||||
key (str): Fx /library/metadata/102631
|
||||
lastViewedAt (datetime.datetime): parse int into datetime.datetime.
|
||||
librarySectionID (int):
|
||||
listType (str): audio
|
||||
ratingKey (int): Unique key to identify this item
|
||||
summary (str): Summery of the artist, track, album
|
||||
thumb (str): Url to thumb image
|
||||
title (str): Fx Aerosmith
|
||||
titleSort (str): Defaults title if None
|
||||
TYPE (str): overwritten by subclass
|
||||
type (string, NA): Description
|
||||
updatedAt (datatime.datetime): parse int to datetime.datetime
|
||||
viewCount (int): How many time has this item been played
|
||||
Attributes:
|
||||
addedAt (datetime): Datetime this item was added to the library.
|
||||
index (sting): Index Number (often the track number).
|
||||
key (str): API URL (/library/metadata/<ratingkey>).
|
||||
lastViewedAt (datetime): Datetime item was last accessed.
|
||||
librarySectionID (int): :class:`~plexapi.library.LibrarySection` ID.
|
||||
listType (str): Hardcoded as 'audio' (useful for search filters).
|
||||
ratingKey (int): Unique key identifying this item.
|
||||
summary (str): Summary of the artist, track, or album.
|
||||
thumb (str): URL to thumbnail image.
|
||||
title (str): Artist, Album or Track title. (Jason Mraz, We Sing, Lucky, etc.)
|
||||
titleSort (str): Title to use when sorting (defaults to title).
|
||||
type (str): 'artist', 'album', or 'track'.
|
||||
updatedAt (datatime): Datetime this item was updated.
|
||||
viewCount (int): Count of times this item was accessed.
|
||||
"""
|
||||
TYPE = None
|
||||
|
||||
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)
|
||||
|
||||
def _loadData(self, data):
|
||||
"""Used to set the attributes.
|
||||
|
||||
Args:
|
||||
data (Element): XML reponse from PMS as Element
|
||||
normally built from server.query
|
||||
"""
|
||||
""" Load attribute values from Plex XML response. """
|
||||
self.listType = 'audio'
|
||||
self.addedAt = utils.toDatetime(data.attrib.get('addedAt', NA))
|
||||
self.index = data.attrib.get('index', NA)
|
||||
|
@ -63,125 +50,104 @@ class Audio(PlexPartialObject):
|
|||
|
||||
@property
|
||||
def thumbUrl(self):
|
||||
"""Return url to thumb image."""
|
||||
""" Returns the URL to this items thumbnail image. """
|
||||
if self.thumb:
|
||||
return self.server.url(self.thumb)
|
||||
|
||||
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)
|
||||
|
||||
def section(self):
|
||||
"""Library section."""
|
||||
""" Returns the :class:`~plexapi.library.LibrarySection` this item belongs to. """
|
||||
return self.server.library.sectionByID(self.librarySectionID)
|
||||
|
||||
|
||||
@utils.register_libtype
|
||||
class Artist(Audio):
|
||||
"""Artist.
|
||||
""" Represents a single audio artist.
|
||||
|
||||
Attributes:
|
||||
art (str): /library/metadata/102631/art/1469310342
|
||||
countries (list): List of media.County fx [<Country:24200:United.States>]
|
||||
genres (list): List of media.Genre fx [<Genre:25555:Classic.Rock>]
|
||||
guid (str): Fx guid com.plexapp.agents.plexmusic://gracenote/artist/05517B8701668D28?lang=en
|
||||
key (str): Fx /library/metadata/102631
|
||||
location (str): Filepath
|
||||
similar (list): List of media.Similar fx [<Similar:25220:Guns.N'.Roses>]
|
||||
TYPE (str): artist
|
||||
Attributes:
|
||||
art (str): Artist artwork (/library/metadata/<ratingkey>/art/<artid>)
|
||||
countries (list): List of :class:`~plexapi.media.Country` objects this artist respresents.
|
||||
genres (list): List of :class:`~plexapi.media.Genre` objects this artist respresents.
|
||||
guid (str): Unknown (unique ID; com.plexapp.agents.plexmusic://gracenote/artist/05517B8701668D28?lang=en)
|
||||
key (str): API URL (/library/metadata/<ratingkey>).
|
||||
location (str): Filepath this artist is found on disk.
|
||||
similar (list): List of :class:`~plexapi.media.Similar` artists.
|
||||
"""
|
||||
|
||||
TYPE = 'artist'
|
||||
|
||||
def _loadData(self, data):
|
||||
"""Used to set the attributes.
|
||||
|
||||
Args:
|
||||
data (Element): XML reponse from PMS as Element
|
||||
normally built from server.query
|
||||
"""
|
||||
""" Load attribute values from Plex XML response. """
|
||||
Audio._loadData(self, data)
|
||||
self.art = data.attrib.get('art', NA)
|
||||
self.guid = data.attrib.get('guid', NA)
|
||||
self.key = self.key.replace('/children', '') # FIX_BUG_50
|
||||
self.location = utils.findLocations(data, single=True)
|
||||
if self.isFullObject(): # check if this is needed
|
||||
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]
|
||||
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]
|
||||
|
||||
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
|
||||
return utils.listItems(self.server, path, Album.TYPE)
|
||||
|
||||
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
|
||||
return utils.findItem(self.server, path, title)
|
||||
|
||||
def tracks(self, watched=None):
|
||||
"""Return all tracks to this artist.
|
||||
|
||||
Args:
|
||||
watched(None, False, True): Default to None.
|
||||
|
||||
Returns:
|
||||
List: of Track
|
||||
"""
|
||||
def tracks(self):
|
||||
""" Returns a list of :class:`plexapi.audio.Track` objects by this artist. """
|
||||
path = '%s/allLeaves' % self.key
|
||||
return utils.listItems(self.server, path, watched=watched)
|
||||
return utils.listItems(self.server, path)
|
||||
|
||||
def track(self, title):
|
||||
"""Return a Track that matches title.
|
||||
""" Returns the :class:`plexapi.audio.Track` that matches the specified title.
|
||||
|
||||
Args:
|
||||
title (str): Fx song name
|
||||
|
||||
Returns:
|
||||
Track:
|
||||
Parameters:
|
||||
title (str): Title of the track to return.
|
||||
"""
|
||||
path = '%s/allLeaves' % self.key
|
||||
return utils.findItem(self.server, path, title)
|
||||
|
||||
def get(self, title):
|
||||
"""Alias. See track."""
|
||||
""" Alias of :func:`~plexapi.audio.Artist.track`. """
|
||||
return self.track(title)
|
||||
|
||||
|
||||
@utils.register_libtype
|
||||
class Album(Audio):
|
||||
"""Album.
|
||||
""" Represents a single audio album.
|
||||
|
||||
Attributes:
|
||||
art (str): Fx /library/metadata/102631/art/1469310342
|
||||
genres (list): List of media.Genre
|
||||
key (str): Fx /library/metadata/102632
|
||||
originallyAvailableAt (TYPE): Description
|
||||
parentKey (str): /library/metadata/102631
|
||||
parentRatingKey (int): Fx 1337
|
||||
parentThumb (TYPE): Relative url to parent thumb image
|
||||
parentTitle (str): Aerosmith
|
||||
studio (str):
|
||||
TYPE (str): album
|
||||
year (int): 1999
|
||||
art (str): Album artwork (/library/metadata/<ratingkey>/art/<artid>)
|
||||
genres (list): List of :class:`~plexapi.media.Genre` objects this album respresents.
|
||||
key (str): API URL (/library/metadata/<ratingkey>).
|
||||
originallyAvailableAt (datetime): Datetime this album was released.
|
||||
parentKey (str): API URL of this artist.
|
||||
parentRatingKey (int): Unique key identifying artist.
|
||||
parentThumb (str): URL to artist thumbnail image.
|
||||
parentTitle (str): Name of the artist for this album.
|
||||
studio (str): Studio that released this album.
|
||||
year (int): Year this album was released.
|
||||
"""
|
||||
|
||||
TYPE = 'album'
|
||||
|
||||
def _loadData(self, data):
|
||||
"""Used to set the attributes.
|
||||
|
||||
Args:
|
||||
data (Element): XML reponse from PMS as Element
|
||||
normally built from server.query
|
||||
"""
|
||||
""" Load attribute values from Plex XML response. """
|
||||
Audio._loadData(self, data)
|
||||
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.parentKey = data.attrib.get('parentKey', 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]
|
||||
|
||||
def tracks(self, watched=None):
|
||||
"""Return all tracks to this album.
|
||||
|
||||
Args:
|
||||
watched(None, False, True): Default to None.
|
||||
|
||||
Returns:
|
||||
List: of Track
|
||||
"""
|
||||
""" Returns a list of :class:`plexapi.audio.Track` objects in this album. """
|
||||
path = '%s/children' % self.key
|
||||
return utils.listItems(self.server, path, watched=watched)
|
||||
|
||||
def track(self, title):
|
||||
"""Return a Track that matches title.
|
||||
""" Returns the :class:`plexapi.audio.Track` that matches the specified title.
|
||||
|
||||
Args:
|
||||
title (str): Fx song name
|
||||
|
||||
Returns:
|
||||
Track:
|
||||
Parameters:
|
||||
title (str): Title of the track to return.
|
||||
"""
|
||||
path = '%s/children' % self.key
|
||||
return utils.findItem(self.server, path, title)
|
||||
|
||||
def get(self, title):
|
||||
"""Alias. See track."""
|
||||
""" Alias of :func:`~plexapi.audio.Album.track`. """
|
||||
return self.track(title)
|
||||
|
||||
def artist(self):
|
||||
"""Return Artist of this album."""
|
||||
""" Return :func:`~plexapi.audio.Artist` of this album. """
|
||||
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
|
||||
class Track(Audio, Playable):
|
||||
"""Track.
|
||||
""" Represents a single audio track.
|
||||
|
||||
Attributes:
|
||||
art (str): Relative path fx /library/metadata/102631/art/1469310342
|
||||
chapterSource (TYPE): Description
|
||||
duration (TYPE): Description
|
||||
grandparentArt (str): Relative path
|
||||
grandparentKey (str): Relative path Fx /library/metadata/102631
|
||||
grandparentRatingKey (TYPE): Description
|
||||
grandparentThumb (str): Relative path to Artist thumb img
|
||||
grandparentTitle (str): Aerosmith
|
||||
guid (TYPE): Description
|
||||
media (list): List of media.Media
|
||||
moods (list): List of media.Moods
|
||||
originalTitle (str): Some track title
|
||||
parentIndex (int): 1
|
||||
parentKey (str): Relative path Fx /library/metadata/102632
|
||||
parentRatingKey (int): 1337
|
||||
parentThumb (str): Relative path to Album thumb
|
||||
parentTitle (str): Album title
|
||||
player (None): #TODO
|
||||
primaryExtraKey (TYPE): #TODO
|
||||
ratingCount (int): 10
|
||||
sessionKey (int): Description
|
||||
transcodeSession (None):
|
||||
TYPE (str): track
|
||||
username (str): username@mail.com
|
||||
viewOffset (int): 100
|
||||
year (int): 1999
|
||||
art (str): Track artwork (/library/metadata/<ratingkey>/art/<artid>)
|
||||
chapterSource (TYPE): Unknown
|
||||
duration (int): Length of this album in seconds.
|
||||
grandparentArt (str): Artist artowrk.
|
||||
grandparentKey (str): Artist API URL.
|
||||
grandparentRatingKey (str): Unique key identifying artist.
|
||||
grandparentThumb (str): URL to artist thumbnail image.
|
||||
grandparentTitle (str): Name of the artist for this track.
|
||||
guid (str): Unknown (unique ID).
|
||||
media (list): List of :class:`~plexapi.media.Media` objects for this track.
|
||||
moods (list): List of :class:`~plexapi.media.Mood` objects for this track.
|
||||
originalTitle (str): Original track title (if translated).
|
||||
parentIndex (int): Album index.
|
||||
parentKey (str): Album API URL.
|
||||
parentRatingKey (int): Unique key identifying album.
|
||||
parentThumb (str): URL to album thumbnail image.
|
||||
parentTitle (str): Name of the album for this track.
|
||||
primaryExtraKey (str): Unknown
|
||||
ratingCount (int): Rating of this track (1-10?)
|
||||
viewOffset (int): Unknown
|
||||
year (int): Year this track was released.
|
||||
sessionKey (int): Session Key (active sessions only).
|
||||
username (str): Username of person playing this track (active sessions only).
|
||||
player (str): :class:`~plexapi.client.PlexClient` for playing track (active sessions only).
|
||||
transcodeSession (None): :class:`~plexapi.media.TranscodeSession` for playing track (active sessions only).
|
||||
"""
|
||||
|
||||
TYPE = 'track'
|
||||
|
||||
def _loadData(self, data):
|
||||
"""Used to set the attributes
|
||||
|
||||
Args:
|
||||
data (Element): Usually built from server.query
|
||||
"""
|
||||
""" Load attribute values from Plex XML response. """
|
||||
Audio._loadData(self, data)
|
||||
Playable._loadData(self, data)
|
||||
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.year = utils.cast(int, data.attrib.get('year', NA))
|
||||
if self.isFullObject(): # check me
|
||||
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]
|
||||
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]
|
||||
# data for active sessions and history
|
||||
self.sessionKey = utils.cast(int, data.attrib.get('sessionKey', NA))
|
||||
self.username = utils.findUsername(data)
|
||||
|
@ -308,14 +249,14 @@ class Track(Audio, Playable):
|
|||
|
||||
@property
|
||||
def thumbUrl(self):
|
||||
"""Return url to thumb image."""
|
||||
""" Returns the URL thumbnail image for this track's album. """
|
||||
if self.parentThumb:
|
||||
return self.server.url(self.parentThumb)
|
||||
|
||||
def album(self):
|
||||
"""Return this track's Album."""
|
||||
""" Return this track's :class:`~plexapi.audio.Album`. """
|
||||
return utils.listItems(self.server, self.parentKey)[0]
|
||||
|
||||
def artist(self):
|
||||
"""Return this track's Artist."""
|
||||
""" Return this track's :class:`~plexapi.audio.Artist`. """
|
||||
return utils.listItems(self.server, self.grandparentKey)[0]
|
||||
|
|
|
@ -10,7 +10,7 @@ from requests.status_codes import _codes as codes
|
|||
|
||||
class MyPlexAccount(object):
|
||||
""" 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
|
||||
the myplex.tv servers at the url https://plex.tv/users/account.
|
||||
|
||||
|
|
Loading…
Reference in a new issue