Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for artist popular tracks #1453

Merged
merged 2 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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