5. track module

This module contains higher level classes to query Musixmatch API and build simple dictionary-like objects representing a Track or a TracksCollection.

>>> from musixmatch.track import Track, TracksCollection
>>> import musixmatch.api
>>> 
>>> try:
...     track = Track(track_mbid=8976)
...     collection = TracksCollection.fromChart(country='us', page=1)
... except musixmatch.api.Error, e:
...     pass
class Track(dictionary=None, **keywords)

Bases: musixmatch.base.Item

This class builds a dict like object representing a track. It can get track information through the musixmatch.api.Method track.get or from an already well-formed dict. Create a Track object based on a given keyword argument:

Parameters:
  • track_id – musiXmatch track ID
  • musicbrainz_id – Musicbrainz track ID
  • track_echonest_id – Echonest track ID
  • track_data – an already well-formed dict of track data
Raises :

musixmatch.api.Error if musixmatch.api.ResponseStatusCode is not 200

Once information are collected, the following keys are available:

Parameters:
  • track_id – musiXmatch track ID
  • track_mbid – Musicbrainz track ID
  • lyrics_id – musiXmatch lyrics ID
  • instrumental – wether the track is instrumental or not
  • subtitle_id – musiXmatch subtitle ID
  • track_name – track name
  • album_coverart_100x100 – album cover URL
  • artist_id – musiXmatch artist ID
  • artist_mbid – Musicbrainz artist ID
  • artist_name – artist name

Keyword access have been overloaded thanks to the get() method which will eventually fetch the matching lyrics or subtitle.

classmethod fromMatcher(**keywords)

Returns a Track based on the result of the musiXmatch.api.Method matcher.track.get. Accepts the following keywords:

Parameters:
  • q_track – words to be searched among track titles
  • q_artist – words to be searched among artist names
get(key, default=<object object at 0x198dc50>)

If key is lyrics or subtitle try to query api for proper value, and build an musixmatch.lyrics.Lyrics or musixmatch.subtitle.Subtitle. Access to the above mentioned keys may fail with musixmatch.api.Error. Once fetched, the result is saved.

postFeedback(feedback)

Post feedback about lyrics for this track. feedback can be one of:

Parameters:
  • wrong_attribution – the lyrics shown are not by the artist that I selected.
  • bad_characters – there are strange characters and/or words that are partially scrambled.
  • lines_too_long – the text for each verse is too long!
  • wrong_verses – there are some verses missing from the beginning or at the end.
  • wrong_formatting – the text looks horrible, please fix it!
class TracksCollection(*items)

Bases: musixmatch.base.ItemsCollection

This class build a list like object representing a tracks collection. It accepts dict or Track objects.

classmethod fromAlbum(**keywords)

This classmethod builds an TracksCollection from a album.tracks.get musixmatch.api.Method call.

Parameters:album_id – musiXmatch album ID
classmethod fromSearch(**keywords)

This classmethod builds an TracksCollection from a track.search musixmatch.api.Method call.

Parameters:
  • q – a string that will be searched in every data field (q_track, q_artist, q_lyrics)
  • q_track – words to be searched among track titles
  • q_artist – words to be searched among artist names
  • q_track_artist – words to be searched among track titles or artist names
  • q_lyrics – words to be searched into the lyrics
  • page – requested page of results
  • page_size – desired number of items per result page
  • f_has_lyrics – exclude tracks without an available lyrics (automatic if q_lyrics is set)
  • f_artist_id – filter the results by the artist_id
  • f_artist_mbid – filter the results by the artist_mbid
  • quorum_factor – only works together with q and q_track_artist parameter. Possible values goes from 0.1 to 0.9. A value of 0.9 means: ‘match at least 90 percent of the words’.
classmethod fromChart(**keywords)

This classmethod builds an TracksCollection from a track.chart.get musixmatch.api.Method call.

Parameters:
  • page – requested page of results
  • page_size – desired number of items per result page
  • country – the country code of the desired country chart
  • f_has_lyrics – exclude tracks without an available lyrics (automatic if q_lyrics is set)

Previous topic

4. artist module

Next topic

6. album module

This Page