Skip to content

Commit

Permalink
Album tracks endpoint added.
Browse files Browse the repository at this point in the history
  • Loading branch information
yakupadakli committed May 26, 2018
1 parent 5cb1ec0 commit 83c21e0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions musixmatch/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,26 @@ def get(self, album_id):
params = {"album_id": album_id}
result = self._get(url, params=params)
return AlbumModel._parse(result["message"]["body"]["album"])

def tracks(self, album_id, has_lyrics=None, page=1, page_size=MAX_PAGE_SIZE):
"""
Get the songs of an album.
:type album_id: string
:type has_lyrics: bool
:type page: double
:type page_size: double
:param album_id: The Musixmatch album id
:param has_lyrics: Filter only contents with lyrics
: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.
"""
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)
1 change: 1 addition & 0 deletions musixmatch/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ def album(self):
get: Get the album object using the Musixmatch id.
tracks: Get the songs of an album.
"""
return Album(api=self)
22 changes: 22 additions & 0 deletions musixmatch/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,25 @@ def _parse(cls, data, sub_item=False):
album.secondary_genres = Genre._parse_list(secondary_genres, sub_item=True)

return album


class Track(Model):
_remove_tag = "track_"

def __init__(self, **kwargs):
super(Track, self).__init__(**kwargs)
self._repr_values = {"name": "Name", "id": "Id", "album_name": "Album Name"}

@classmethod
def _parse(cls, data, sub_item=False):
track = super(Track, cls)._parse(data, sub_item=sub_item)

if hasattr(track, "primary_genres"):
primary_genres = map(lambda x: x.get("music_genre"), track.primary_genres.get("music_genre_list", []))
track.primary_genres = Genre._parse_list(primary_genres, sub_item=True)

if hasattr(track, "secondary_genres"):
secondary_genres = map(lambda x: x.get("music_genre"), track.secondary_genres.get("music_genre_list", []))
track.secondary_genres = Genre._parse_list(secondary_genres, sub_item=True)

return track

0 comments on commit 83c21e0

Please sign in to comment.