This commit is contained in:
Abhinav Sarkar 2008-07-16 20:48:16 +00:00
parent bdf12b8152
commit 2a51a20bb9
8 changed files with 76 additions and 24 deletions

Binary file not shown.

BIN
dist/lastfm-0.1.tar.gz vendored

Binary file not shown.

Binary file not shown.

BIN
dist/lastfm-0.1.zip vendored

Binary file not shown.

View File

@ -63,13 +63,20 @@ class Album(LastfmBase):
def getTopTags(self):
if self.__topTags is None:
self.__topTags = Album.getInfo(
self.__api,
self.artist.name,
self.name,
self.mbid,
bypassRegistry = True
).topTags
params = {'method': 'album.getinfo'}
if self.artist and self.name:
params.update({'artist': self.artist.name, 'album': self.name})
elif self.mbid:
params.update({'mbid': self.mbid})
data = self.__api.fetchData(params).find('album')
self.__topTags = [
Tag(
self.__api,
name = t.findtext('name'),
url = t.findtext('url')
)
for t in data.findall('toptags/tag')
]
return self.__topTags
name = property(getName, None, None, "Name's Docstring")
@ -98,7 +105,7 @@ class Album(LastfmBase):
def getInfo(api,
artist = None,
album = None,
mbid = None, **kwds):
mbid = None):
params = {'method': 'album.getinfo'}
if not ((artist and album) or mbid):
raise LastfmError("either (artist and album) or mbid has to be given as argument.")
@ -130,8 +137,7 @@ class Album(LastfmBase):
url = t.findtext('url')
)
for t in data.findall('toptags/tag')
],
**kwds
]
)
@staticmethod
def hashFunc(*args, **kwds):

View File

@ -67,7 +67,8 @@ class Artist(LastfmBase):
def getSimilar(self, limit = None):
params = {
'method': 'artist.getsimilar',
'artist': self.__name}
'artist': self.__name
}
if limit is not None:
params.update({'limit': limit})
data = self.__api.fetchData(params).find('similarartists')
@ -85,10 +86,21 @@ class Artist(LastfmBase):
return self.__similar
def getTopTags(self):
if self.__topTags:
return self.__topTags
else:
pass
if self.__topTags is None or len(self.__topTags) < 6:
params = {
'method': 'artist.gettoptags',
'artist': self.__name
}
data = self.__api.fetchData(params).find('toptags')
self.__topTags = [
Tag(
self.__api,
name = t.findtext('name'),
url = t.findtext('url')
)
for t in data.findall('tag')
]
return self.__topTags
def getBio(self):
return self.__bio
@ -204,7 +216,25 @@ class Artist(LastfmBase):
None, None, "docstring")
def getTopTracks(self):
pass
params = {'method': 'artist.gettoptracks', 'artist': self.name}
data = self.__api.fetchData(params).find('toptracks')
return [
Track(
self.__api,
name = t.findtext('name'),
artist = self,
mbid = t.findtext('mbid'),
playcount = int(t.findtext('playcount')),
streamable = (t.findtext('streamable') == '1'),
fullTrack = (t.find('streamable').attrib['fulltrack'] == '1'),
image = dict([(i.get('size'), i.text) for i in t.findall('image')]),
)
for t in data.findall('track')
]
topTracks = property(getTopTracks, None, None, "Docstring")
topTrack = property(lambda self: len(self.topTracks) and self.topTracks[0],
None, None, "docstring")
@staticmethod
def search(api,
@ -365,4 +395,5 @@ from error import LastfmError
from event import Event
from geo import Country, Location, Venue
from tag import Tag
from track import Track
from user import User

View File

@ -10,16 +10,17 @@ class LastfmBase(object):
registry = {}
def __new__(cls, *args, **kwds):
key = cls.hashFunc(*args, **kwds)
inst, alreadyRegistered = LastfmBase.register(object.__new__(cls), key)
if not alreadyRegistered:
inst.init(*args, **kwds)
else:
if 'bypassRegistry' in kwds:
if 'bypassRegistry' in kwds:
del kwds['bypassRegistry']
inst = object.__new__(cls)
inst.init(*args, **kwds)
return inst
return inst
key = cls.hashFunc(*args, **kwds)
inst, alreadyRegistered = LastfmBase.register(object.__new__(cls), key)
if not alreadyRegistered:
inst.init(*args, **kwds)
return inst
@staticmethod
def register(ob, key):

View File

@ -16,7 +16,9 @@ class Track(LastfmBase):
streamable = None,
artist = None,
image = None,
match = None):
match = None,
playcount = None,
fullTrack = None):
if not isinstance(api, Api):
raise LastfmError("api reference must be supplied as an argument")
self.__api = api
@ -27,6 +29,8 @@ class Track(LastfmBase):
self.__artist = artist
self.__image = image
self.__match = match
self.__playcount = playcount
self.__fullTrack = fullTrack
def getName(self):
return self.__name
@ -48,6 +52,12 @@ class Track(LastfmBase):
def getMatch(self):
return self.__match
def getPlaycount(self):
return self.__playcount
def getFullTrack(self):
return self.__fullTrack
name = property(getName, None, None, "Name's Docstring")
@ -63,6 +73,10 @@ class Track(LastfmBase):
match = property(getMatch, None, None, "Match's Docstring")
playcount = property(getPlaycount, None, None, "Match's Docstring")
fullTrack = property(getFullTrack, None, None, "Match's Docstring")
def __checkParams(self,
params,
artist = None,