From 075e7d7e12cf484c545f4e722685cf3f162dd0ae Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Sat, 17 Aug 2024 14:26:11 -0700 Subject: [PATCH] Add support for artist popular tracks (#1453) * Add artist popular tracks * Test artist popular tracks --- plexapi/audio.py | 15 +++++++++++++++ plexapi/library.py | 3 ++- tests/test_audio.py | 5 +++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/plexapi/audio.py b/plexapi/audio.py index 8f84f3be9..f1c88a1d8 100644 --- a/plexapi/audio.py +++ b/plexapi/audio.py @@ -281,6 +281,21 @@ def download(self, savepath=None, keep_original_name=False, subfolders=False, ** filepaths += track.download(_savepath, keep_original_name, **kwargs) return filepaths + def popularTracks(self): + """ Returns a list of :class:`~plexapi.audio.Track` popular tracks by the artist. """ + filters = { + 'album.subformat!': 'Compilation,Live', + 'artist.id': self.ratingKey, + 'group': 'title', + 'ratingCount>>': 0, + } + return self.section().search( + libtype='track', + filters=filters, + sort='ratingCount:desc', + limit=100 + ) + def station(self): """ Returns a :class:`~plexapi.playlist.Playlist` artist radio station or `None`. """ key = f'{self.key}?includeStations=1' diff --git a/plexapi/library.py b/plexapi/library.py index f1bf5375a..6913b8296 100644 --- a/plexapi/library.py +++ b/plexapi/library.py @@ -2823,7 +2823,8 @@ def _manualFields(self): additionalFields.extend([ ('duration', 'integer', 'Duration'), ('viewOffset', 'integer', 'View Offset'), - ('label', 'tag', 'Label') + ('label', 'tag', 'Label'), + ('ratingCount', 'integer', 'Rating Count'), ]) elif self.type == 'collection': additionalFields.extend([ diff --git a/tests/test_audio.py b/tests/test_audio.py index 8ebad4f51..4f9b5403e 100644 --- a/tests/test_audio.py +++ b/tests/test_audio.py @@ -88,6 +88,11 @@ def test_audio_Artist_hubs(artist): assert isinstance(hubs, list) +def test_audio_Artist_popularTracks(artist): + tracks = artist.popularTracks() + assert len(tracks) + + def test_audio_Artist_mixins_edit_advanced_settings(artist): test_mixins.edit_advanced_settings(artist)