Skip to content

Commit 075e7d7

Browse files
authored
Add support for artist popular tracks (#1453)
* Add artist popular tracks * Test artist popular tracks
1 parent e23cd8d commit 075e7d7

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

plexapi/audio.py

+15
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,21 @@ def download(self, savepath=None, keep_original_name=False, subfolders=False, **
281281
filepaths += track.download(_savepath, keep_original_name, **kwargs)
282282
return filepaths
283283

284+
def popularTracks(self):
285+
""" Returns a list of :class:`~plexapi.audio.Track` popular tracks by the artist. """
286+
filters = {
287+
'album.subformat!': 'Compilation,Live',
288+
'artist.id': self.ratingKey,
289+
'group': 'title',
290+
'ratingCount>>': 0,
291+
}
292+
return self.section().search(
293+
libtype='track',
294+
filters=filters,
295+
sort='ratingCount:desc',
296+
limit=100
297+
)
298+
284299
def station(self):
285300
""" Returns a :class:`~plexapi.playlist.Playlist` artist radio station or `None`. """
286301
key = f'{self.key}?includeStations=1'

plexapi/library.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2823,7 +2823,8 @@ def _manualFields(self):
28232823
additionalFields.extend([
28242824
('duration', 'integer', 'Duration'),
28252825
('viewOffset', 'integer', 'View Offset'),
2826-
('label', 'tag', 'Label')
2826+
('label', 'tag', 'Label'),
2827+
('ratingCount', 'integer', 'Rating Count'),
28272828
])
28282829
elif self.type == 'collection':
28292830
additionalFields.extend([

tests/test_audio.py

+5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ def test_audio_Artist_hubs(artist):
8888
assert isinstance(hubs, list)
8989

9090

91+
def test_audio_Artist_popularTracks(artist):
92+
tracks = artist.popularTracks()
93+
assert len(tracks)
94+
95+
9196
def test_audio_Artist_mixins_edit_advanced_settings(artist):
9297
test_mixins.edit_advanced_settings(artist)
9398

0 commit comments

Comments
 (0)