From 79a43919ccaa42bcceac143dc9b6fdf0ed4a008c Mon Sep 17 00:00:00 2001 From: Lukas Lipka Date: Sat, 10 Mar 2012 15:03:09 +0100 Subject: [PATCH] Add support for chart artists/tracks. --- AUTHORS | 1 + pylast.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/AUTHORS b/AUTHORS index f09ae8f..053c3a0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1 +1,2 @@ Amr Hassan +Lukas Lipka diff --git a/pylast.py b/pylast.py index aac62d9..71be2a0 100644 --- a/pylast.py +++ b/pylast.py @@ -313,6 +313,37 @@ class _Network(object): return Playlist(user, e_id, self) + def get_top_artists(self, limit=None): + """Returns a sequence of the most played artists.""" + + doc = _Request(self, "chart.getTopArtists").execute(True) + seq = [] + for node in doc.getElementsByTagName("artist"): + title = _extract(node, "name") + artist = Artist(title, self) + seq.append(artist) + + if limit: + seq = seq[:limit] + + return seq + + def get_top_tracks(self, limit=None): + """Returns a sequence of the most played tracks.""" + + doc = _Request(self, "chart.getTopTracks").execute(True) + seq = [] + for node in doc.getElementsByTagName("track"): + title = _extract(node, "name") + artist = _extract(node, "name", 1) + track = Track(artist, title, self) + seq.append(track) + + if limit: + seq = seq[:limit] + + return seq + def get_top_tags(self, limit=None): """Returns a sequence of the most used tags as a sequence of TopItem objects."""