2016-03-21 04:26:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2020-05-12 21:15:16 +00:00
|
|
|
from urllib.parse import quote_plus
|
|
|
|
|
2016-03-21 04:26:02 +00:00
|
|
|
from plexapi import media, utils
|
2017-02-04 19:46:51 +00:00
|
|
|
from plexapi.base import Playable, PlexPartialObject
|
2017-01-02 21:06:40 +00:00
|
|
|
|
2016-01-19 09:31:45 +00:00
|
|
|
|
2016-04-04 03:55:29 +00:00
|
|
|
class Audio(PlexPartialObject):
|
2017-01-22 06:37:39 +00:00
|
|
|
""" Base class for audio :class:`~plexapi.audio.Artist`, :class:`~plexapi.audio.Album`
|
|
|
|
and :class:`~plexapi.audio.Track` objects.
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
addedAt (datetime): Datetime this item was added to the library.
|
2020-06-05 19:42:22 +00:00
|
|
|
fields (list): List of :class:`~plexapi.media.Field`.
|
2017-01-22 06:37:39 +00:00
|
|
|
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.
|
2017-01-02 21:06:40 +00:00
|
|
|
"""
|
2018-09-08 15:25:16 +00:00
|
|
|
|
|
|
|
METADATA_TYPE = 'track'
|
|
|
|
|
2016-01-19 10:56:16 +00:00
|
|
|
def _loadData(self, data):
|
2017-01-22 06:37:39 +00:00
|
|
|
""" Load attribute values from Plex XML response. """
|
2017-02-06 04:52:10 +00:00
|
|
|
self._data = data
|
2016-04-12 02:43:21 +00:00
|
|
|
self.listType = 'audio'
|
2017-02-04 17:43:50 +00:00
|
|
|
self.addedAt = utils.toDatetime(data.attrib.get('addedAt'))
|
2020-11-22 04:02:31 +00:00
|
|
|
self.art = data.attrib.get('art')
|
|
|
|
self.artBlurHash = data.attrib.get('artBlurHash')
|
2020-06-05 19:42:22 +00:00
|
|
|
self.fields = self.findItems(data, etag='Field')
|
2017-02-04 17:43:50 +00:00
|
|
|
self.index = data.attrib.get('index')
|
|
|
|
self.key = data.attrib.get('key')
|
|
|
|
self.lastViewedAt = utils.toDatetime(data.attrib.get('lastViewedAt'))
|
|
|
|
self.librarySectionID = data.attrib.get('librarySectionID')
|
|
|
|
self.ratingKey = utils.cast(int, data.attrib.get('ratingKey'))
|
|
|
|
self.summary = data.attrib.get('summary')
|
|
|
|
self.thumb = data.attrib.get('thumb')
|
2020-11-22 04:02:31 +00:00
|
|
|
self.thumbBlurHash = data.attrib.get('thumbBlurHash')
|
2017-02-04 17:43:50 +00:00
|
|
|
self.title = data.attrib.get('title')
|
2016-03-21 04:26:02 +00:00
|
|
|
self.titleSort = data.attrib.get('titleSort', self.title)
|
2017-02-04 17:43:50 +00:00
|
|
|
self.type = data.attrib.get('type')
|
|
|
|
self.updatedAt = utils.toDatetime(data.attrib.get('updatedAt'))
|
2016-03-21 04:26:02 +00:00
|
|
|
self.viewCount = utils.cast(int, data.attrib.get('viewCount', 0))
|
2017-01-02 21:06:40 +00:00
|
|
|
|
2016-04-04 03:55:29 +00:00
|
|
|
@property
|
|
|
|
def thumbUrl(self):
|
2017-02-09 20:01:23 +00:00
|
|
|
""" Return url to for the thumbnail image. """
|
2017-02-15 05:13:22 +00:00
|
|
|
key = self.firstAttr('thumb', 'parentThumb', 'granparentThumb')
|
2018-01-05 02:44:35 +00:00
|
|
|
return self._server.url(key, includeToken=True) if key else None
|
2017-01-02 21:06:40 +00:00
|
|
|
|
2017-11-08 21:01:53 +00:00
|
|
|
@property
|
|
|
|
def artUrl(self):
|
2018-01-05 02:44:35 +00:00
|
|
|
""" Return the first art url starting on the most specific for that item."""
|
2017-11-08 21:01:53 +00:00
|
|
|
art = self.firstAttr('art', 'grandparentArt')
|
2018-01-05 02:44:35 +00:00
|
|
|
return self._server.url(art, includeToken=True) if art else None
|
2017-11-08 21:01:53 +00:00
|
|
|
|
|
|
|
def url(self, part):
|
2018-01-05 02:44:35 +00:00
|
|
|
""" Returns the full URL for this audio item. Typically used for getting a specific track. """
|
|
|
|
return self._server.url(part, includeToken=True) if part else None
|
2017-11-08 21:01:53 +00:00
|
|
|
|
2018-09-08 15:25:16 +00:00
|
|
|
def _defaultSyncTitle(self):
|
|
|
|
""" Returns str, default title for a new syncItem. """
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
def sync(self, bitrate, client=None, clientId=None, limit=None, title=None):
|
|
|
|
""" Add current audio (artist, album or track) as sync item for specified device.
|
|
|
|
See :func:`plexapi.myplex.MyPlexAccount.sync()` for possible exceptions.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
bitrate (int): maximum bitrate for synchronized music, better use one of MUSIC_BITRATE_* values from the
|
|
|
|
module :mod:`plexapi.sync`.
|
|
|
|
client (:class:`plexapi.myplex.MyPlexDevice`): sync destination, see
|
|
|
|
:func:`plexapi.myplex.MyPlexAccount.sync`.
|
|
|
|
clientId (str): sync destination, see :func:`plexapi.myplex.MyPlexAccount.sync`.
|
|
|
|
limit (int): maximum count of items to sync, unlimited if `None`.
|
|
|
|
title (str): descriptive title for the new :class:`plexapi.sync.SyncItem`, if empty the value would be
|
|
|
|
generated from metadata of current media.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`plexapi.sync.SyncItem`: an instance of created syncItem.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from plexapi.sync import SyncItem, Policy, MediaSettings
|
|
|
|
|
|
|
|
myplex = self._server.myPlexAccount()
|
|
|
|
sync_item = SyncItem(self._server, None)
|
|
|
|
sync_item.title = title if title else self._defaultSyncTitle()
|
|
|
|
sync_item.rootTitle = self.title
|
|
|
|
sync_item.contentType = self.listType
|
|
|
|
sync_item.metadataType = self.METADATA_TYPE
|
|
|
|
sync_item.machineIdentifier = self._server.machineIdentifier
|
|
|
|
|
|
|
|
section = self._server.library.sectionByID(self.librarySectionID)
|
|
|
|
|
|
|
|
sync_item.location = 'library://%s/item/%s' % (section.uuid, quote_plus(self.key))
|
|
|
|
sync_item.policy = Policy.create(limit)
|
|
|
|
sync_item.mediaSettings = MediaSettings.createMusic(bitrate)
|
|
|
|
|
|
|
|
return myplex.sync(sync_item, client=client, clientId=clientId)
|
|
|
|
|
2016-03-15 02:20:02 +00:00
|
|
|
|
2017-02-13 02:55:55 +00:00
|
|
|
@utils.registerPlexObject
|
2016-01-19 09:31:45 +00:00
|
|
|
class Artist(Audio):
|
2017-01-22 06:37:39 +00:00
|
|
|
""" Represents a single audio artist.
|
|
|
|
|
|
|
|
Attributes:
|
2017-02-14 04:32:27 +00:00
|
|
|
TAG (str): 'Directory'
|
|
|
|
TYPE (str): 'artist'
|
2017-01-22 06:37:39 +00:00
|
|
|
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.
|
2017-01-02 21:06:40 +00:00
|
|
|
"""
|
2017-02-13 02:55:55 +00:00
|
|
|
TAG = 'Directory'
|
2016-01-19 09:31:45 +00:00
|
|
|
TYPE = 'artist'
|
|
|
|
|
|
|
|
def _loadData(self, data):
|
2017-01-22 06:37:39 +00:00
|
|
|
""" Load attribute values from Plex XML response. """
|
2016-04-07 05:39:04 +00:00
|
|
|
Audio._loadData(self, data)
|
2017-02-04 17:43:50 +00:00
|
|
|
self.guid = data.attrib.get('guid')
|
2016-04-04 03:55:29 +00:00
|
|
|
self.key = self.key.replace('/children', '') # FIX_BUG_50
|
2017-02-13 03:15:47 +00:00
|
|
|
self.locations = self.listAttrs(data, 'path', etag='Location')
|
2017-02-13 02:55:55 +00:00
|
|
|
self.countries = self.findItems(data, media.Country)
|
|
|
|
self.genres = self.findItems(data, media.Genre)
|
|
|
|
self.similar = self.findItems(data, media.Similar)
|
2017-07-21 23:07:31 +00:00
|
|
|
self.collections = self.findItems(data, media.Collection)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
2017-10-09 14:07:09 +00:00
|
|
|
def __iter__(self):
|
|
|
|
for album in self.albums():
|
|
|
|
yield album
|
|
|
|
|
2016-01-19 09:31:45 +00:00
|
|
|
def album(self, title):
|
2017-01-31 04:44:03 +00:00
|
|
|
""" Returns the :class:`~plexapi.audio.Album` that matches the specified title.
|
2017-01-22 06:37:39 +00:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
title (str): Title of the album to return.
|
|
|
|
"""
|
2017-02-08 05:36:22 +00:00
|
|
|
key = '%s/children' % self.key
|
2017-02-09 06:54:38 +00:00
|
|
|
return self.fetchItem(key, title__iexact=title)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
2017-02-09 04:08:25 +00:00
|
|
|
def albums(self, **kwargs):
|
2017-02-06 04:52:10 +00:00
|
|
|
""" Returns a list of :class:`~plexapi.audio.Album` objects by this artist. """
|
|
|
|
key = '%s/children' % self.key
|
2017-02-09 04:08:25 +00:00
|
|
|
return self.fetchItems(key, **kwargs)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def track(self, title):
|
2017-01-31 04:44:03 +00:00
|
|
|
""" Returns the :class:`~plexapi.audio.Track` that matches the specified title.
|
2017-01-02 21:06:40 +00:00
|
|
|
|
2017-01-22 06:37:39 +00:00
|
|
|
Parameters:
|
|
|
|
title (str): Title of the track to return.
|
2017-01-02 21:06:40 +00:00
|
|
|
"""
|
2017-02-08 05:36:22 +00:00
|
|
|
key = '%s/allLeaves' % self.key
|
2017-02-09 06:54:38 +00:00
|
|
|
return self.fetchItem(key, title__iexact=title)
|
2017-02-06 04:52:10 +00:00
|
|
|
|
2017-02-09 04:08:25 +00:00
|
|
|
def tracks(self, **kwargs):
|
2017-02-06 04:52:10 +00:00
|
|
|
""" Returns a list of :class:`~plexapi.audio.Track` objects by this artist. """
|
|
|
|
key = '%s/allLeaves' % self.key
|
2017-02-09 04:08:25 +00:00
|
|
|
return self.fetchItems(key, **kwargs)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def get(self, title):
|
2017-01-22 06:37:39 +00:00
|
|
|
""" Alias of :func:`~plexapi.audio.Artist.track`. """
|
2016-01-19 09:31:45 +00:00
|
|
|
return self.track(title)
|
|
|
|
|
2019-01-07 13:04:53 +00:00
|
|
|
def download(self, savepath=None, keep_original_name=False, **kwargs):
|
2017-02-02 03:53:05 +00:00
|
|
|
""" Downloads all tracks for this artist to the specified location.
|
2017-02-20 05:37:00 +00:00
|
|
|
|
2017-02-02 03:53:05 +00:00
|
|
|
Parameters:
|
|
|
|
savepath (str): Title of the track to return.
|
2019-01-07 13:04:53 +00:00
|
|
|
keep_original_name (bool): Set True to keep the original filename as stored in
|
2017-02-02 03:53:05 +00:00
|
|
|
the Plex server. False will create a new filename with the format
|
|
|
|
"<Atrist> - <Album> <Track>".
|
|
|
|
kwargs (dict): If specified, a :func:`~plexapi.audio.Track.getStreamURL()` will
|
|
|
|
be returned and the additional arguments passed in will be sent to that
|
|
|
|
function. If kwargs is not specified, the media items will be downloaded
|
|
|
|
and saved to disk.
|
|
|
|
"""
|
2017-02-06 04:52:10 +00:00
|
|
|
filepaths = []
|
2017-01-09 14:21:54 +00:00
|
|
|
for album in self.albums():
|
|
|
|
for track in album.tracks():
|
2019-01-07 13:04:53 +00:00
|
|
|
filepaths += track.download(savepath, keep_original_name, **kwargs)
|
2017-02-06 04:52:10 +00:00
|
|
|
return filepaths
|
2017-01-09 14:21:54 +00:00
|
|
|
|
2016-01-19 09:31:45 +00:00
|
|
|
|
2017-02-13 02:55:55 +00:00
|
|
|
@utils.registerPlexObject
|
2016-01-19 09:31:45 +00:00
|
|
|
class Album(Audio):
|
2017-01-22 06:37:39 +00:00
|
|
|
""" Represents a single audio album.
|
2017-01-02 21:06:40 +00:00
|
|
|
|
2017-01-23 05:15:51 +00:00
|
|
|
Attributes:
|
2017-02-14 04:32:27 +00:00
|
|
|
TAG (str): 'Directory'
|
|
|
|
TYPE (str): 'album'
|
2017-01-23 05:15:51 +00:00
|
|
|
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.
|
|
|
|
"""
|
2017-02-13 02:55:55 +00:00
|
|
|
TAG = 'Directory'
|
2016-01-19 09:31:45 +00:00
|
|
|
TYPE = 'album'
|
|
|
|
|
2017-10-09 14:07:09 +00:00
|
|
|
def __iter__(self):
|
2020-08-07 17:47:26 +00:00
|
|
|
for track in self.tracks():
|
2017-10-09 14:07:09 +00:00
|
|
|
yield track
|
|
|
|
|
2016-01-19 09:31:45 +00:00
|
|
|
def _loadData(self, data):
|
2017-01-22 06:37:39 +00:00
|
|
|
""" Load attribute values from Plex XML response. """
|
2016-04-07 05:39:04 +00:00
|
|
|
Audio._loadData(self, data)
|
2017-01-22 06:37:39 +00:00
|
|
|
self.key = self.key.replace('/children', '') # fixes bug #50
|
2017-02-04 17:43:50 +00:00
|
|
|
self.originallyAvailableAt = utils.toDatetime(data.attrib.get('originallyAvailableAt'), '%Y-%m-%d')
|
|
|
|
self.parentKey = data.attrib.get('parentKey')
|
|
|
|
self.parentRatingKey = data.attrib.get('parentRatingKey')
|
|
|
|
self.parentThumb = data.attrib.get('parentThumb')
|
|
|
|
self.parentTitle = data.attrib.get('parentTitle')
|
|
|
|
self.studio = data.attrib.get('studio')
|
|
|
|
self.year = utils.cast(int, data.attrib.get('year'))
|
2017-02-13 02:55:55 +00:00
|
|
|
self.genres = self.findItems(data, media.Genre)
|
2017-07-21 23:07:31 +00:00
|
|
|
self.collections = self.findItems(data, media.Collection)
|
2018-03-01 19:39:33 +00:00
|
|
|
self.labels = self.findItems(data, media.Label)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def track(self, title):
|
2017-01-31 04:44:03 +00:00
|
|
|
""" Returns the :class:`~plexapi.audio.Track` that matches the specified title.
|
2017-01-02 21:06:40 +00:00
|
|
|
|
2017-01-22 06:37:39 +00:00
|
|
|
Parameters:
|
|
|
|
title (str): Title of the track to return.
|
2017-01-02 21:06:40 +00:00
|
|
|
"""
|
2017-02-08 05:36:22 +00:00
|
|
|
key = '%s/children' % self.key
|
2017-02-09 06:54:38 +00:00
|
|
|
return self.fetchItem(key, title__iexact=title)
|
2017-02-06 04:52:10 +00:00
|
|
|
|
2017-02-09 04:08:25 +00:00
|
|
|
def tracks(self, **kwargs):
|
2017-02-06 04:52:10 +00:00
|
|
|
""" Returns a list of :class:`~plexapi.audio.Track` objects in this album. """
|
|
|
|
key = '%s/children' % self.key
|
2017-02-09 04:08:25 +00:00
|
|
|
return self.fetchItems(key, **kwargs)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def get(self, title):
|
2017-01-22 06:37:39 +00:00
|
|
|
""" Alias of :func:`~plexapi.audio.Album.track`. """
|
2016-01-19 09:31:45 +00:00
|
|
|
return self.track(title)
|
|
|
|
|
|
|
|
def artist(self):
|
2017-01-22 06:37:39 +00:00
|
|
|
""" Return :func:`~plexapi.audio.Artist` of this album. """
|
2017-02-07 06:20:49 +00:00
|
|
|
return self.fetchItem(self.parentKey)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
2019-01-07 13:04:53 +00:00
|
|
|
def download(self, savepath=None, keep_original_name=False, **kwargs):
|
2017-02-02 03:53:05 +00:00
|
|
|
""" Downloads all tracks for this artist to the specified location.
|
2017-02-20 05:37:00 +00:00
|
|
|
|
2017-02-02 03:53:05 +00:00
|
|
|
Parameters:
|
|
|
|
savepath (str): Title of the track to return.
|
2019-01-07 13:04:53 +00:00
|
|
|
keep_original_name (bool): Set True to keep the original filename as stored in
|
2017-02-02 03:53:05 +00:00
|
|
|
the Plex server. False will create a new filename with the format
|
|
|
|
"<Atrist> - <Album> <Track>".
|
|
|
|
kwargs (dict): If specified, a :func:`~plexapi.audio.Track.getStreamURL()` will
|
|
|
|
be returned and the additional arguments passed in will be sent to that
|
|
|
|
function. If kwargs is not specified, the media items will be downloaded
|
|
|
|
and saved to disk.
|
|
|
|
"""
|
2017-02-06 04:52:10 +00:00
|
|
|
filepaths = []
|
|
|
|
for track in self.tracks():
|
2019-01-07 13:04:53 +00:00
|
|
|
filepaths += track.download(savepath, keep_original_name, **kwargs)
|
2017-02-06 04:52:10 +00:00
|
|
|
return filepaths
|
2017-01-09 14:21:54 +00:00
|
|
|
|
2018-09-08 15:25:16 +00:00
|
|
|
def _defaultSyncTitle(self):
|
|
|
|
""" Returns str, default title for a new syncItem. """
|
|
|
|
return '%s - %s' % (self.parentTitle, self.title)
|
|
|
|
|
2016-01-19 09:31:45 +00:00
|
|
|
|
2017-02-13 02:55:55 +00:00
|
|
|
@utils.registerPlexObject
|
2016-04-04 03:55:29 +00:00
|
|
|
class Track(Audio, Playable):
|
2017-01-22 06:37:39 +00:00
|
|
|
""" Represents a single audio track.
|
2017-01-02 21:06:40 +00:00
|
|
|
|
2017-01-23 05:15:51 +00:00
|
|
|
Attributes:
|
2017-02-14 04:32:27 +00:00
|
|
|
TAG (str): 'Directory'
|
|
|
|
TYPE (str): 'track'
|
2017-01-23 05:15:51 +00:00
|
|
|
art (str): Track artwork (/library/metadata/<ratingkey>/art/<artid>)
|
|
|
|
chapterSource (TYPE): Unknown
|
|
|
|
duration (int): Length of this album in seconds.
|
2019-10-30 17:38:38 +00:00
|
|
|
grandparentArt (str): Album artist artwork.
|
|
|
|
grandparentKey (str): Album artist API URL.
|
|
|
|
grandparentRatingKey (str): Unique key identifying album artist.
|
|
|
|
grandparentThumb (str): URL to album artist thumbnail image.
|
|
|
|
grandparentTitle (str): Name of the album artist for this track.
|
2017-01-23 05:15:51 +00:00
|
|
|
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.
|
2019-10-30 17:38:38 +00:00
|
|
|
originalTitle (str): Track artist.
|
2017-01-23 05:15:51 +00:00
|
|
|
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
|
2018-03-21 16:26:53 +00:00
|
|
|
ratingCount (int): Unknown
|
|
|
|
userRating (float): Rating of this track (0.0 - 10.0) equaling (0 stars - 5 stars)
|
2017-01-23 05:15:51 +00:00
|
|
|
viewOffset (int): Unknown
|
|
|
|
year (int): Year this track was released.
|
|
|
|
sessionKey (int): Session Key (active sessions only).
|
2017-10-13 22:29:52 +00:00
|
|
|
usernames (str): Username of person playing this track (active sessions only).
|
2017-01-23 05:15:51 +00:00
|
|
|
player (str): :class:`~plexapi.client.PlexClient` for playing track (active sessions only).
|
2017-10-13 22:02:21 +00:00
|
|
|
transcodeSessions (None): :class:`~plexapi.media.TranscodeSession` for playing
|
2017-01-23 05:15:51 +00:00
|
|
|
track (active sessions only).
|
|
|
|
"""
|
2017-02-13 02:55:55 +00:00
|
|
|
TAG = 'Track'
|
2016-01-19 09:31:45 +00:00
|
|
|
TYPE = 'track'
|
|
|
|
|
|
|
|
def _loadData(self, data):
|
2017-01-22 06:37:39 +00:00
|
|
|
""" Load attribute values from Plex XML response. """
|
2016-04-07 05:39:04 +00:00
|
|
|
Audio._loadData(self, data)
|
|
|
|
Playable._loadData(self, data)
|
2017-02-04 17:43:50 +00:00
|
|
|
self.chapterSource = data.attrib.get('chapterSource')
|
|
|
|
self.duration = utils.cast(int, data.attrib.get('duration'))
|
|
|
|
self.grandparentArt = data.attrib.get('grandparentArt')
|
|
|
|
self.grandparentKey = data.attrib.get('grandparentKey')
|
|
|
|
self.grandparentRatingKey = data.attrib.get('grandparentRatingKey')
|
|
|
|
self.grandparentThumb = data.attrib.get('grandparentThumb')
|
|
|
|
self.grandparentTitle = data.attrib.get('grandparentTitle')
|
|
|
|
self.guid = data.attrib.get('guid')
|
|
|
|
self.originalTitle = data.attrib.get('originalTitle')
|
|
|
|
self.parentIndex = data.attrib.get('parentIndex')
|
|
|
|
self.parentKey = data.attrib.get('parentKey')
|
|
|
|
self.parentRatingKey = data.attrib.get('parentRatingKey')
|
|
|
|
self.parentThumb = data.attrib.get('parentThumb')
|
|
|
|
self.parentTitle = data.attrib.get('parentTitle')
|
|
|
|
self.primaryExtraKey = data.attrib.get('primaryExtraKey')
|
|
|
|
self.ratingCount = utils.cast(int, data.attrib.get('ratingCount'))
|
2018-03-21 16:26:53 +00:00
|
|
|
self.userRating = utils.cast(float, data.attrib.get('userRating', 0))
|
2016-03-21 04:26:02 +00:00
|
|
|
self.viewOffset = utils.cast(int, data.attrib.get('viewOffset', 0))
|
2017-02-04 17:43:50 +00:00
|
|
|
self.year = utils.cast(int, data.attrib.get('year'))
|
2017-02-13 02:55:55 +00:00
|
|
|
self.media = self.findItems(data, media.Media)
|
|
|
|
self.moods = self.findItems(data, media.Mood)
|
2017-02-06 04:52:10 +00:00
|
|
|
|
|
|
|
def _prettyfilename(self):
|
|
|
|
""" Returns a filename for use in download. """
|
|
|
|
return '%s - %s %s' % (self.grandparentTitle, self.parentTitle, self.title)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def album(self):
|
2017-01-22 06:37:39 +00:00
|
|
|
""" Return this track's :class:`~plexapi.audio.Album`. """
|
2017-02-13 02:55:55 +00:00
|
|
|
return self.fetchItem(self.parentKey)
|
2016-01-19 09:31:45 +00:00
|
|
|
|
|
|
|
def artist(self):
|
2017-01-22 06:37:39 +00:00
|
|
|
""" Return this track's :class:`~plexapi.audio.Artist`. """
|
2017-02-13 02:55:55 +00:00
|
|
|
return self.fetchItem(self.grandparentKey)
|
2018-09-08 15:25:16 +00:00
|
|
|
|
|
|
|
def _defaultSyncTitle(self):
|
|
|
|
""" Returns str, default title for a new syncItem. """
|
2020-06-06 18:14:03 +00:00
|
|
|
return '%s - %s - %s' % (self.grandparentTitle, self.parentTitle, self.title)
|