From 2565dbb9a1db66500a244068bee9ea79c45f8249 Mon Sep 17 00:00:00 2001 From: Abhinav Sarkar Date: Wed, 31 Dec 2008 06:05:34 +0000 Subject: [PATCH] added searchable mixin to album to implement album.search method --- lastfm/album.py | 30 +++++++++++++++++++++++++++--- lastfm/api.py | 5 +++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lastfm/album.py b/lastfm/album.py index be98e3c..6a24d03 100644 --- a/lastfm/album.py +++ b/lastfm/album.py @@ -5,9 +5,9 @@ __version__ = "0.2" __license__ = "GNU Lesser General Public License" from lastfm.base import LastfmBase -from lastfm.mixins import Cacheable, Taggable +from lastfm.mixins import Cacheable, Searchable, Taggable -class Album(LastfmBase, Cacheable, Taggable): +class Album(LastfmBase, Cacheable, Searchable, Taggable): """A class representing an album.""" def init(self, api, @@ -19,7 +19,8 @@ class Album(LastfmBase, Cacheable, Taggable): release_date = None, image = None, stats = None, - top_tags = None): + top_tags = None, + streamable = None): if not isinstance(api, Api): raise InvalidParametersError("api reference must be supplied as an argument") Taggable.init(self, api) @@ -39,6 +40,7 @@ class Album(LastfmBase, Cacheable, Taggable): rank = stats.rank ) self._top_tags = top_tags + self._streamable = streamable @property def name(self): @@ -91,6 +93,13 @@ class Album(LastfmBase, Cacheable, Taggable): if self._stats is None: self._fill_info() return self._stats + + @property + def streamable(self): + """is the artist streamable""" + if self._streamable is None: + self._fill_info() + return self._streamable @LastfmBase.cached_property def top_tags(self): @@ -182,6 +191,21 @@ class Album(LastfmBase, Cacheable, Taggable): for t in data.findall('toptags/tag') ] + @staticmethod + def _search_yield_func(api, album): + return Album( + api, + name = album.findtext('name'), + artist = Artist( + api, + name = album.findtext('artist') + ), + id = int(album.findtext('id')), + url = album.findtext('url'), + image = dict([(i.get('size'), i.text) for i in album.findall('image')]), + streamable = (album.findtext('streamable') == '1'), + ) + @staticmethod def _hash_func(*args, **kwds): try: diff --git a/lastfm/api.py b/lastfm/api.py index addaa26..3641298 100644 --- a/lastfm/api.py +++ b/lastfm/api.py @@ -102,6 +102,11 @@ class Api(object): artist = artist.name return Album.get_info(self, artist, album, mbid) + def search_album(self, + album, + limit = None): + return Album.search(self, search_item = album, limit = limit) + def get_artist(self, artist = None, mbid = None):