Skip to content

Commit

Permalink
Chart artist endpoint added.
Browse files Browse the repository at this point in the history
  • Loading branch information
yakupadakli committed May 29, 2018
1 parent 19ef875 commit cd7e881
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 0 additions & 1 deletion musixmatch/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@ def tracks(self, album_id, has_lyrics=None, page=1, page_size=MAX_PAGE_SIZE):
url = "/album.tracks.get"
params = {"album_id": album_id, "f_has_lyrics": has_lyrics, "page": page, "page_size": page_size + 1}
result = self._get(url, params=params)
print(result)
track_list = map(lambda x: x["track"], result["message"]["body"]["track_list"])
return TrackModel._parse_list(track_list)
13 changes: 13 additions & 0 deletions musixmatch/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from musixmatch.album import Album
from musixmatch.artist import Artist
from musixmatch.chart import Chart
from musixmatch.track import Track


Expand Down Expand Up @@ -61,3 +62,15 @@ def track(self):
subtitle: Retrieve the subtitle of a track.
"""
return Track(api=self)

@property
def chart(self):
"""
Musixmatch Track Operations
Available methods:
artist: Get the list of the top artists of a given country.
"""
return Chart(api=self)
33 changes: 33 additions & 0 deletions musixmatch/chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from musixmatch.client import Client
from musixmatch.models import Artist as ArtistModel
from musixmatch.models import Track as TrackModel


class Chart(Client):
"""Chart operations."""
MAX_PAGE_SIZE = 99

def __init__(self, **kwargs):
super(Chart, self).__init__(**kwargs)
self.fields_tag = "fields"

def artists(self, country, page=1, page_size=MAX_PAGE_SIZE):
"""
Get the list of the top artists of a given country.
:type country: string
:type page: double
:type page_size: double
:param country: A valid country code.
:param page: Define the page number for paginated results.
:param page_size: Define the page size for paginated results. Range is 1 to 99.
:return [List]: Tracks List.
"""
assert page_size <= self.MAX_PAGE_SIZE, "Page size must be lower than %s" % self.MAX_PAGE_SIZE
url = "/chart.artists.get"
params = {"country": country, "page": page, "page_size": page_size + 1}
result = self._get(url, params=params)
artist_list = map(lambda x: x["artist"], result["message"]["body"]["artist_list"])
return ArtistModel._parse_list(artist_list)

0 comments on commit cd7e881

Please sign in to comment.