Skip to content

Commit

Permalink
Add genres attribute to Track (#1318)
Browse files Browse the repository at this point in the history
* Add genres attribute to Track

* Test track genres

* Add GenreMixin to Tracks

* Add test for editing track genre
  • Loading branch information
JonnyWong16 authored Feb 17, 2024
1 parent b831aae commit 284a577
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions plexapi/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ class Track(
chapterSource (str): Unknown
collections (List<:class:`~plexapi.media.Collection`>): List of collection objects.
duration (int): Length of the track in milliseconds.
genres (List<:class:`~plexapi.media.Genre`>): List of genre objects.
grandparentArt (str): URL to album artist artwork (/library/metadata/<grandparentRatingKey>/art/<artid>).
grandparentGuid (str): Plex GUID for the album artist (plex://artist/5d07bcb0403c64029053ac4c).
grandparentKey (str): API URL of the album artist (/library/metadata/<grandparentRatingKey>).
Expand Down Expand Up @@ -463,6 +464,7 @@ def _loadData(self, data):
self.chapterSource = data.attrib.get('chapterSource')
self.collections = self.findItems(data, media.Collection)
self.duration = utils.cast(int, data.attrib.get('duration'))
self.genres = self.findItems(data, media.Genre)
self.grandparentArt = data.attrib.get('grandparentArt')
self.grandparentGuid = data.attrib.get('grandparentGuid')
self.grandparentKey = data.attrib.get('grandparentKey')
Expand Down
2 changes: 1 addition & 1 deletion plexapi/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ class AlbumEditMixins(
class TrackEditMixins(
ArtLockMixin, PosterLockMixin, ThemeLockMixin,
AddedAtMixin, TitleMixin, TrackArtistMixin, TrackNumberMixin, TrackDiscNumberMixin, UserRatingMixin,
CollectionMixin, LabelMixin, MoodMixin
CollectionMixin, GenreMixin, LabelMixin, MoodMixin
):
pass

Expand Down
2 changes: 2 additions & 0 deletions tests/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ def test_audio_Track_attrs(album):
assert utils.is_art(track.art)
assert track.chapterSource is None
assert utils.is_int(track.duration)
assert track.genres == []
if track.grandparentArt:
assert utils.is_art(track.grandparentArt)
assert utils.is_metadata(track.grandparentKey)
Expand Down Expand Up @@ -422,6 +423,7 @@ def test_audio_Track_mixins_fields(track):

def test_audio_Track_mixins_tags(track):
test_mixins.edit_collection(track)
test_mixins.edit_genre(track)
test_mixins.edit_label(track)
test_mixins.edit_mood(track)

Expand Down

0 comments on commit 284a577

Please sign in to comment.