mirror of
https://github.com/pkkid/python-plexapi
synced 2025-02-16 21:08:27 +00:00
Merge pull request #832 from JonnyWong16/feature/album_types
Add album formats and subformats
This commit is contained in:
commit
90bfaf12c2
4 changed files with 54 additions and 6 deletions
|
@ -234,6 +234,7 @@ class Album(Audio, ArtMixin, PosterMixin, RatingMixin, UnmatchMatchMixin,
|
|||
TAG (str): 'Directory'
|
||||
TYPE (str): 'album'
|
||||
collections (List<:class:`~plexapi.media.Collection`>): List of collection objects.
|
||||
formats (List<:class:`~plexapi.media.Format`>): List of format objects.
|
||||
genres (List<:class:`~plexapi.media.Genre`>): List of genre objects.
|
||||
key (str): API URL (/library/metadata/<ratingkey>).
|
||||
labels (List<:class:`~plexapi.media.Label`>): List of label objects.
|
||||
|
@ -248,6 +249,7 @@ class Album(Audio, ArtMixin, PosterMixin, RatingMixin, UnmatchMatchMixin,
|
|||
rating (float): Album rating (7.9; 9.8; 8.1).
|
||||
studio (str): Studio that released the album.
|
||||
styles (List<:class:`~plexapi.media.Style`>): List of style objects.
|
||||
subformats (List<:class:`~plexapi.media.Subformat`>): List of subformat objects.
|
||||
viewedLeafCount (int): Number of items marked as played in the album view.
|
||||
year (int): Year the album was released.
|
||||
"""
|
||||
|
@ -258,6 +260,7 @@ class Album(Audio, ArtMixin, PosterMixin, RatingMixin, UnmatchMatchMixin,
|
|||
""" Load attribute values from Plex XML response. """
|
||||
Audio._loadData(self, data)
|
||||
self.collections = self.findItems(data, media.Collection)
|
||||
self.formats = self.findItems(data, media.Format)
|
||||
self.genres = self.findItems(data, media.Genre)
|
||||
self.key = self.key.replace('/children', '') # FIX_BUG_50
|
||||
self.labels = self.findItems(data, media.Label)
|
||||
|
@ -272,6 +275,7 @@ class Album(Audio, ArtMixin, PosterMixin, RatingMixin, UnmatchMatchMixin,
|
|||
self.rating = utils.cast(float, data.attrib.get('rating'))
|
||||
self.studio = data.attrib.get('studio')
|
||||
self.styles = self.findItems(data, media.Style)
|
||||
self.subformats = self.findItems(data, media.Subformat)
|
||||
self.viewedLeafCount = utils.cast(int, data.attrib.get('viewedLeafCount'))
|
||||
self.year = utils.cast(int, data.attrib.get('year'))
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ class MediaPart(PlexObject):
|
|||
return [stream for stream in self.streams if isinstance(stream, SubtitleStream)]
|
||||
|
||||
def lyricStreams(self):
|
||||
""" Returns a list of :class:`~plexapi.media.SubtitleStream` objects in this MediaPart. """
|
||||
""" Returns a list of :class:`~plexapi.media.LyricStream` objects in this MediaPart. """
|
||||
return [stream for stream in self.streams if isinstance(stream, LyricStream)]
|
||||
|
||||
def setDefaultAudioStream(self, stream):
|
||||
|
@ -731,6 +731,18 @@ class Director(MediaTag):
|
|||
FILTER = 'director'
|
||||
|
||||
|
||||
@utils.registerPlexObject
|
||||
class Format(MediaTag):
|
||||
""" Represents a single Format media tag.
|
||||
|
||||
Attributes:
|
||||
TAG (str): 'Format'
|
||||
FILTER (str): 'format'
|
||||
"""
|
||||
TAG = 'Format'
|
||||
FILTER = 'format'
|
||||
|
||||
|
||||
@utils.registerPlexObject
|
||||
class Genre(MediaTag):
|
||||
""" Represents a single Genre media tag.
|
||||
|
@ -815,6 +827,18 @@ class Style(MediaTag):
|
|||
FILTER = 'style'
|
||||
|
||||
|
||||
@utils.registerPlexObject
|
||||
class Subformat(MediaTag):
|
||||
""" Represents a single Subformat media tag.
|
||||
|
||||
Attributes:
|
||||
TAG (str): 'Subformat'
|
||||
FILTER (str): 'subformat'
|
||||
"""
|
||||
TAG = 'Subformat'
|
||||
FILTER = 'subformat'
|
||||
|
||||
|
||||
@utils.registerPlexObject
|
||||
class Tag(MediaTag):
|
||||
""" Represents a single Tag media tag.
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
import pytest
|
||||
from plexapi.exceptions import BadRequest
|
||||
|
||||
from . import conftest as utils
|
||||
from . import test_media, test_mixins
|
||||
|
||||
|
@ -38,9 +41,9 @@ def test_audio_Artist_attr(artist):
|
|||
assert utils.is_int(artist.viewCount, gte=0)
|
||||
|
||||
|
||||
def test_audio_Artist_get(artist, music):
|
||||
artist == music.searchArtists(**{"title": "Broke For Free"})[0]
|
||||
artist.title == "Broke For Free"
|
||||
def test_audio_Artist_get(artist):
|
||||
track = artist.get(album="Layers", title="As Colourful as Ever")
|
||||
assert track.title == "As Colourful as Ever"
|
||||
|
||||
|
||||
def test_audio_Artist_history(artist):
|
||||
|
@ -54,6 +57,8 @@ def test_audio_Artist_track(artist):
|
|||
track = artist.track(album="Layers", track=1)
|
||||
assert track.parentTitle == "Layers"
|
||||
assert track.index == 1
|
||||
with pytest.raises(BadRequest):
|
||||
artist.track()
|
||||
|
||||
|
||||
def test_audio_Artist_tracks(artist):
|
||||
|
@ -71,6 +76,11 @@ def test_audio_Artist_albums(artist):
|
|||
assert len(albums) == 1 and albums[0].title == "Layers"
|
||||
|
||||
|
||||
def test_audio_Artist_hubs(artist):
|
||||
hubs = artist.hubs()
|
||||
assert isinstance(hubs, list)
|
||||
|
||||
|
||||
def test_audio_Artist_mixins_edit_advanced_settings(artist):
|
||||
test_mixins.edit_advanced_settings(artist)
|
||||
|
||||
|
@ -119,6 +129,7 @@ def test_audio_Album_attrs(album):
|
|||
assert utils.is_datetime(album.addedAt)
|
||||
if album.art:
|
||||
assert utils.is_art(album.art)
|
||||
assert isinstance(album.formats, list)
|
||||
assert isinstance(album.genres, list)
|
||||
assert album.index == 1
|
||||
assert utils.is_metadata(album._initpath)
|
||||
|
@ -136,6 +147,7 @@ def test_audio_Album_attrs(album):
|
|||
assert album.ratingKey >= 1
|
||||
assert album._server._baseurl == utils.SERVER_BASEURL
|
||||
assert album.studio == "[no label]"
|
||||
assert isinstance(album.subformats, list)
|
||||
assert album.summary == ""
|
||||
if album.thumb:
|
||||
assert utils.is_thumb(album.thumb)
|
||||
|
@ -167,6 +179,8 @@ def test_audio_Album_track(album, track=None):
|
|||
track = track or album.track("As Colourful As Ever")
|
||||
track2 = album.track(track=1)
|
||||
assert track == track2
|
||||
with pytest.raises(BadRequest):
|
||||
album.track()
|
||||
|
||||
|
||||
def test_audio_Album_get(album):
|
||||
|
@ -233,6 +247,7 @@ def test_audio_Track_attrs(album):
|
|||
assert utils.is_thumb(track.grandparentThumb)
|
||||
assert track.grandparentTitle == "Broke For Free"
|
||||
assert track.guid.startswith("mbid://") or track.guid.startswith("plex://track/")
|
||||
assert track.hasSonicAnalysis is False
|
||||
assert track.index == 1
|
||||
assert track.trackNumber == track.index
|
||||
assert utils.is_metadata(track._initpath)
|
||||
|
@ -271,6 +286,7 @@ def test_audio_Track_attrs(album):
|
|||
assert track.viewOffset == 0
|
||||
assert track.viewedAt is None
|
||||
assert track.year is None
|
||||
assert track.url(None) is None
|
||||
assert media.aspectRatio is None
|
||||
assert media.audioChannels == 2
|
||||
assert media.audioCodec == "mp3"
|
||||
|
|
|
@ -306,14 +306,18 @@ def test_library_MusicSection_albums(music):
|
|||
assert len(music.albums())
|
||||
|
||||
|
||||
def test_library_MusicSection_searchTracks(music):
|
||||
assert len(music.searchTracks(title="As Colourful As Ever"))
|
||||
def test_library_MusicSection_searchArtists(music):
|
||||
assert len(music.searchArtists(title="Broke for Free"))
|
||||
|
||||
|
||||
def test_library_MusicSection_searchAlbums(music):
|
||||
assert len(music.searchAlbums(title="Layers"))
|
||||
|
||||
|
||||
def test_library_MusicSection_searchTracks(music):
|
||||
assert len(music.searchTracks(title="As Colourful As Ever"))
|
||||
|
||||
|
||||
def test_library_MusicSection_recentlyAdded(music, artist):
|
||||
album = artist.albums()[0]
|
||||
track = album.tracks()[0]
|
||||
|
|
Loading…
Add table
Reference in a new issue