Skip to content

Commit

Permalink
Add support for artist popular tracks (#1453)
Browse files Browse the repository at this point in the history
* Add artist popular tracks

* Test artist popular tracks
  • Loading branch information
JonnyWong16 authored Aug 17, 2024
1 parent e23cd8d commit 075e7d7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
15 changes: 15 additions & 0 deletions plexapi/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion plexapi/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
5 changes: 5 additions & 0 deletions tests/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 075e7d7

Please sign in to comment.