annotate musixmatch-master/build/lib/musixmatch/artist.py @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 8c29444cb5fd
children
rev   line source
yading@7 1 """
yading@7 2 This module contains higher level classes to query Musixmatch API and build
yading@7 3 simple dictionary-like objects representing an Artist or an ArtistsCollection.
yading@7 4
yading@7 5 >>> from musixmatch.artist import Artist, ArtistsCollection
yading@7 6 >>> import musixmatch.api
yading@7 7 >>>
yading@7 8 >>> try:
yading@7 9 ... artist = Artist(artist_id=292)
yading@7 10 ... collection = ArtistsCollection.fromChart(country='it', page=1)
yading@7 11 ... except musixmatch.api.Error, e:
yading@7 12 ... pass
yading@7 13 """
yading@7 14 import musixmatch
yading@7 15 __license__ = musixmatch.__license__
yading@7 16 __author__ = musixmatch.__author__
yading@7 17
yading@7 18 from musixmatch.base import Item, ItemsCollection
yading@7 19 from musixmatch.ws import artist
yading@7 20
yading@7 21 class Artist(Item):
yading@7 22 """
yading@7 23 This class build a :py:class:`dict` like object representing an artist. It
yading@7 24 can get artist information through the :py:class:`musixmatch.api.Method`
yading@7 25 **artist.get** or from an already well-formed :py:class:`dict`. Create an
yading@7 26 Artist object based on a given keyword argument:
yading@7 27
yading@7 28 :param artist_id: musiXmatch artist ID
yading@7 29 :param artist_mbid: Musicbrainz artist ID
yading@7 30 :param artist_data: an already well-formed :py:class:`dict` of artist data.
yading@7 31
yading@7 32 Once information are collected, the following keys are available:
yading@7 33
yading@7 34 :keyword artist_id: musiXmatch artist ID
yading@7 35 :keyword artist_mbid: Musicbrainz artist ID
yading@7 36 :keyword artist_name: Artist name
yading@7 37 """
yading@7 38 __api_method__ = artist.get
yading@7 39
yading@7 40 class ArtistsCollection(ItemsCollection):
yading@7 41 """
yading@7 42 This class build a :py:class:`list` like object representing an artists
yading@7 43 collection. It accepts :py:class:`dict` or :py:class:`Artist` objects.
yading@7 44 """
yading@7 45 __allowedin__ = Artist
yading@7 46
yading@7 47 @classmethod
yading@7 48 def fromSearch(cls, **keywords):
yading@7 49 """
yading@7 50 This classmethod builds an :py:class:`ArtistsCollection` from a
yading@7 51 **artist.search** :py:class:`musixmatch.api.Method` call.
yading@7 52
yading@7 53 :param q: a string that will be searched in every data field
yading@7 54 (q_track, q_artist, q_lyrics)
yading@7 55 :param q_track: words to be searched among track titles
yading@7 56 :param q_artist: words to be searched among artist names
yading@7 57 :param q_lyrics: words to be searched into the lyrics
yading@7 58 :param page: requested page of results
yading@7 59 :param page_size: desired number of items per result page
yading@7 60 :param f_has_lyrics: exclude tracks without an available lyrics
yading@7 61 (automatic if q_lyrics is set)
yading@7 62 :param f_artist_id: filter the results by the artist_id
yading@7 63 :param f_artist_mbid: filter the results by the artist_mbid
yading@7 64 :rtype: :py:class:`ArtistsCollection`
yading@7 65 """
yading@7 66 return cls.fromResponseMessage(artist.search(**keywords))
yading@7 67
yading@7 68 @classmethod
yading@7 69 def fromChart(cls, **keywords):
yading@7 70 """
yading@7 71 This classmethod builds an :py:class:`ArtistsCollection` from a
yading@7 72 **artist.chart.get** :py:class:`musixmatch.api.Method` call.
yading@7 73
yading@7 74 :param page: requested page of results
yading@7 75 :param page_size: desired number of items per result page
yading@7 76 :param country: the country code of the desired country chart
yading@7 77 :rtype: :py:class:`ArtistsCollection`
yading@7 78 """
yading@7 79 return cls.fromResponseMessage(artist.chart.get(**keywords))
yading@7 80