This commit is contained in:
parent
6fad6f68d8
commit
8b9c525182
|
@ -246,7 +246,10 @@ class Api(object):
|
||||||
params.update({'api_key': self.__apiKey})
|
params.update({'api_key': self.__apiKey})
|
||||||
xml = self._fetchUrl(Api.API_ROOT_URL, params, no_cache = self._no_cache)
|
xml = self._fetchUrl(Api.API_ROOT_URL, params, no_cache = self._no_cache)
|
||||||
#print xml
|
#print xml
|
||||||
data = ElementTree.XML(xml)
|
try:
|
||||||
|
data = ElementTree.XML(xml)
|
||||||
|
except SyntaxError, e:
|
||||||
|
raise LastfmError("Error in parsing XML: %s" % e)
|
||||||
if data.get('status') != "ok":
|
if data.get('status') != "ok":
|
||||||
raise LastfmError("Error code: %s (%s)" % (data.find("error").get('code'), data.findtext('error')))
|
raise LastfmError("Error code: %s (%s)" % (data.find("error").get('code'), data.findtext('error')))
|
||||||
if parse:
|
if parse:
|
||||||
|
|
|
@ -65,7 +65,7 @@ class Artist(LastfmBase):
|
||||||
self._fillInfo()
|
self._fillInfo()
|
||||||
return self.__image
|
return self.__image
|
||||||
|
|
||||||
def getStreamable(self):
|
def isStreamable(self):
|
||||||
if self.__streamable is None:
|
if self.__streamable is None:
|
||||||
self._fillInfo()
|
self._fillInfo()
|
||||||
return self.__streamable
|
return self.__streamable
|
||||||
|
@ -89,7 +89,7 @@ class Artist(LastfmBase):
|
||||||
name = a.findtext('name'),
|
name = a.findtext('name'),
|
||||||
mbid = a.findtext('mbid'),
|
mbid = a.findtext('mbid'),
|
||||||
stats = Stats(
|
stats = Stats(
|
||||||
artist = a.findtext('name'),
|
subject = a.findtext('name'),
|
||||||
match = float(a.findtext('match')),
|
match = float(a.findtext('match')),
|
||||||
),
|
),
|
||||||
url = 'http://' + a.findtext('url'),
|
url = 'http://' + a.findtext('url'),
|
||||||
|
@ -129,7 +129,7 @@ class Artist(LastfmBase):
|
||||||
|
|
||||||
image = property(getImage, None, None, "Image's Docstring")
|
image = property(getImage, None, None, "Image's Docstring")
|
||||||
|
|
||||||
streamable = property(getStreamable, None, None, "Streamable's Docstring")
|
streamable = property(isStreamable, None, None, "Streamable's Docstring")
|
||||||
|
|
||||||
stats = property(getStats, None, None, "Stats's Docstring")
|
stats = property(getStats, None, None, "Stats's Docstring")
|
||||||
|
|
||||||
|
|
14
src/stats.py
14
src/stats.py
|
@ -10,6 +10,8 @@ class Stats(object):
|
||||||
subject,
|
subject,
|
||||||
listeners = None,
|
listeners = None,
|
||||||
playcount = None,
|
playcount = None,
|
||||||
|
tagcount = None,
|
||||||
|
count = None,
|
||||||
match = None,
|
match = None,
|
||||||
rank = None,
|
rank = None,
|
||||||
weight = None,
|
weight = None,
|
||||||
|
@ -18,6 +20,8 @@ class Stats(object):
|
||||||
self.__subject = subject
|
self.__subject = subject
|
||||||
self.__listeners = listeners
|
self.__listeners = listeners
|
||||||
self.__playcount = playcount
|
self.__playcount = playcount
|
||||||
|
self.__tagcount = tagcount
|
||||||
|
self.__count = count
|
||||||
self.__match = match
|
self.__match = match
|
||||||
self.__rank = rank
|
self.__rank = rank
|
||||||
self.__weight = weight
|
self.__weight = weight
|
||||||
|
@ -35,7 +39,13 @@ class Stats(object):
|
||||||
|
|
||||||
def getPlaycount(self):
|
def getPlaycount(self):
|
||||||
return self.__playcount
|
return self.__playcount
|
||||||
|
|
||||||
|
def getTagcount(self):
|
||||||
|
return self.__tagcount
|
||||||
|
|
||||||
|
def getCount(self):
|
||||||
|
return self.__count
|
||||||
|
|
||||||
def getMatch(self):
|
def getMatch(self):
|
||||||
return self.__match
|
return self.__match
|
||||||
|
|
||||||
|
@ -51,6 +61,10 @@ class Stats(object):
|
||||||
listeners = property(getListeners, None, None, "Listeners's Docstring")
|
listeners = property(getListeners, None, None, "Listeners's Docstring")
|
||||||
|
|
||||||
playcount = property(getPlaycount, None, None, "Plays's Docstring")
|
playcount = property(getPlaycount, None, None, "Plays's Docstring")
|
||||||
|
|
||||||
|
tagcount = property(getTagcount, None, None, "Plays's Docstring")
|
||||||
|
|
||||||
|
count = property(getCount, None, None, "Plays's Docstring")
|
||||||
|
|
||||||
match = property(getMatch, None, None, "Match's Docstring")
|
match = property(getMatch, None, None, "Match's Docstring")
|
||||||
|
|
||||||
|
|
124
src/tag.py
124
src/tag.py
|
@ -11,12 +11,18 @@ class Tag(LastfmBase):
|
||||||
def init(self,
|
def init(self,
|
||||||
api,
|
api,
|
||||||
name = None,
|
name = None,
|
||||||
url = None):
|
url = None,
|
||||||
|
streamable = None):
|
||||||
if not isinstance(api, Api):
|
if not isinstance(api, Api):
|
||||||
raise LastfmError("api reference must be supplied as an argument")
|
raise LastfmError("api reference must be supplied as an argument")
|
||||||
self.__api = api
|
self.__api = api
|
||||||
self.__name = name
|
self.__name = name
|
||||||
self.__url = url
|
self.__url = url
|
||||||
|
self.__streamable = streamable
|
||||||
|
self.__similar = None
|
||||||
|
self.__topAlbums = None
|
||||||
|
self.__topArtists = None
|
||||||
|
self.__topTracks = None
|
||||||
|
|
||||||
def getName(self):
|
def getName(self):
|
||||||
return self.__name
|
return self.__name
|
||||||
|
@ -24,21 +30,124 @@ class Tag(LastfmBase):
|
||||||
def getUrl(self):
|
def getUrl(self):
|
||||||
return self.__url
|
return self.__url
|
||||||
|
|
||||||
|
def isStreamable(self):
|
||||||
|
return self.__streamable
|
||||||
|
|
||||||
name = property(getName, None, None, "Name's Docstring")
|
name = property(getName, None, None, "Name's Docstring")
|
||||||
|
|
||||||
url = property(getUrl, None, None, "Url's Docstring")
|
url = property(getUrl, None, None, "Url's Docstring")
|
||||||
|
|
||||||
|
streamable = property(isStreamable, None, None, "Docstring")
|
||||||
|
|
||||||
def getSimilar(self):
|
def getSimilar(self):
|
||||||
pass
|
if self.__similar is None:
|
||||||
|
params = {'method': 'tag.getsimilar', 'tag': self.name}
|
||||||
|
data = self.__api._fetchData(params).find('similartags')
|
||||||
|
self.__similar = [
|
||||||
|
Tag(
|
||||||
|
self.__api,
|
||||||
|
name = t.findtext('name'),
|
||||||
|
url = t.findtext('url'),
|
||||||
|
streamable = (t.findtext('streamable') == "1"),
|
||||||
|
)
|
||||||
|
for t in data.findall('tag')
|
||||||
|
]
|
||||||
|
return self.__similar
|
||||||
|
|
||||||
|
similar = property(getSimilar, None, None, "Docstring")
|
||||||
|
|
||||||
def getTopAlbums(self):
|
def getTopAlbums(self):
|
||||||
pass
|
if self.__topAlbums is None:
|
||||||
|
params = {'method': 'tag.gettopalbums', 'tag': self.name}
|
||||||
|
data = self.__api._fetchData(params).find('topalbums')
|
||||||
|
self.__topAlbums = [
|
||||||
|
Album(
|
||||||
|
self.__api,
|
||||||
|
name = a.findtext('name'),
|
||||||
|
artist = Artist(
|
||||||
|
self.__api,
|
||||||
|
name = a.findtext('artist/name'),
|
||||||
|
mbid = a.findtext('artist/mbid'),
|
||||||
|
url = a.findtext('artist/url'),
|
||||||
|
),
|
||||||
|
mbid = a.findtext('mbid'),
|
||||||
|
url = a.findtext('url'),
|
||||||
|
image = dict([(i.get('size'), i.text) for i in a.findall('image')]),
|
||||||
|
stats = Stats(
|
||||||
|
subject = a.findtext('name'),
|
||||||
|
tagcount = a.findtext('tagcount') and int(a.findtext('tagcount')) or None,
|
||||||
|
rank = a.attrib['rank'].strip() and int(a.attrib['rank']) or None
|
||||||
|
)
|
||||||
|
)
|
||||||
|
for a in data.findall('album')
|
||||||
|
]
|
||||||
|
return self.__topAlbums
|
||||||
|
|
||||||
|
topAlbums = property(getTopAlbums, None, None, "Docstring")
|
||||||
|
topAlbum = property(
|
||||||
|
lambda self: len(self.topAlbums) and self.topAlbums[0] or None,
|
||||||
|
None, None, "Docstring"
|
||||||
|
)
|
||||||
|
|
||||||
def getTopArtists(self):
|
def getTopArtists(self):
|
||||||
pass
|
if self.__topArtists is None:
|
||||||
|
params = {'method': 'tag.gettopartists', 'tag': self.name}
|
||||||
|
data = self.__api._fetchData(params).find('topartists')
|
||||||
|
self.__topArtists = [
|
||||||
|
Artist(
|
||||||
|
self.__api,
|
||||||
|
name = a.findtext('name'),
|
||||||
|
mbid = a.findtext('mbid'),
|
||||||
|
stats = Stats(
|
||||||
|
subject = a.findtext('name'),
|
||||||
|
rank = a.attrib['rank'].strip() and int(a.attrib['rank']) or None,
|
||||||
|
tagcount = a.findtext('tagcount') and int(a.findtext('tagcount')) or None
|
||||||
|
),
|
||||||
|
url = a.findtext('url'),
|
||||||
|
streamable = (a.findtext('streamable') == "1"),
|
||||||
|
image = dict([(i.get('size'), i.text) for i in a.findall('image')]),
|
||||||
|
)
|
||||||
|
for a in data.findall('artist')
|
||||||
|
]
|
||||||
|
return self.__topArtists
|
||||||
|
|
||||||
|
topArtists = property(getTopArtists, None, None, "Docstring")
|
||||||
|
topArtist = property(
|
||||||
|
lambda self: len(self.topArtists) and self.topArtists[0] or None,
|
||||||
|
None, None, "Docstring"
|
||||||
|
)
|
||||||
|
|
||||||
def getTopTracks(self):
|
def getTopTracks(self):
|
||||||
pass
|
if self.__topTracks is None:
|
||||||
|
params = {'method': 'tag.gettoptracks', 'tag': self.name}
|
||||||
|
data = self.__api._fetchData(params).find('toptracks')
|
||||||
|
self.__topTracks = [
|
||||||
|
Track(
|
||||||
|
self.__api,
|
||||||
|
name = t.findtext('name'),
|
||||||
|
artist = Artist(
|
||||||
|
self.__api,
|
||||||
|
name = t.findtext('artist/name'),
|
||||||
|
mbid = t.findtext('artist/mbid'),
|
||||||
|
url = t.findtext('artist/url'),
|
||||||
|
),
|
||||||
|
mbid = t.findtext('mbid'),
|
||||||
|
stats = Stats(
|
||||||
|
subject = t.findtext('name'),
|
||||||
|
rank = t.attrib['rank'].strip() and int(t.attrib['rank']) or None,
|
||||||
|
tagcount = t.findtext('tagcount') and int(t.findtext('tagcount')) or None
|
||||||
|
),
|
||||||
|
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')
|
||||||
|
]
|
||||||
|
return self.__topTracks
|
||||||
|
|
||||||
|
topTracks = property(getTopTracks, None, None, "Docstring")
|
||||||
|
topTrack = property(lambda self: len(self.topTracks) and self.topTracks[0],
|
||||||
|
None, None, "docstring")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getTopTags(api):
|
def getTopTags(api):
|
||||||
|
@ -74,4 +183,5 @@ from api import Api
|
||||||
from error import LastfmError
|
from error import LastfmError
|
||||||
from album import Album
|
from album import Album
|
||||||
from artist import Artist
|
from artist import Artist
|
||||||
from track import Track
|
from track import Track
|
||||||
|
from stats import Stats
|
|
@ -44,7 +44,7 @@ class Track(LastfmBase):
|
||||||
def getUrl(self):
|
def getUrl(self):
|
||||||
return self.__url
|
return self.__url
|
||||||
|
|
||||||
def getStreamable(self):
|
def isStreamable(self):
|
||||||
return self.__streamable
|
return self.__streamable
|
||||||
|
|
||||||
def getArtist(self):
|
def getArtist(self):
|
||||||
|
@ -65,7 +65,7 @@ class Track(LastfmBase):
|
||||||
|
|
||||||
url = property(getUrl, None, None, "Url's Docstring")
|
url = property(getUrl, None, None, "Url's Docstring")
|
||||||
|
|
||||||
streamable = property(getStreamable, None, None, "Streamable's Docstring")
|
streamable = property(isStreamable, None, None, "Streamable's Docstring")
|
||||||
|
|
||||||
artist = property(getArtist, None, None, "Artist's Docstring")
|
artist = property(getArtist, None, None, "Artist's Docstring")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue