# makes a query internally to get the full story
_ARTIST_FIELDS = ['id', 'name', 'image']
-_ALBUM_FIELDS = ['id', 'name', 'image', 'artist_name', 'artist_id']
+_ALBUM_FIELDS = ['id', 'name', 'image', 'artist_name', 'artist_id', 'license_url']
_TRACK_FIELDS = ['id', 'name', 'image', 'artist_name', 'album_name', 'album_id', 'numalbum', 'duration']
_RADIO_FIELDS = ['id', 'name', 'idstr', 'image']
self.set_from_json(json)
def _needs_load(self):
- return self._needs_load_impl('name', 'image', 'albums')
+ return self._needs_load_impl('name', 'albums')
def _set_from(self, other):
return self._set_from_impl(other, 'name', 'image', 'albums')
self.image = None
self.artist_name = None
self.artist_id = None
+ self.license_url = None
self.tracks = None # None means not downloaded
if json:
self.set_from_json(json)
def _needs_load(self):
- return self._needs_load_impl('name', 'image', 'artist_name', 'artist_id', 'tracks')
+ return self._needs_load_impl('name', 'image', 'artist_name', 'artist_id', 'license_url', 'tracks')
def _set_from(self, other):
- return self._set_from_impl(other, 'name', 'image', 'artist_name', 'artist_id', 'tracks')
+ return self._set_from_impl(other, 'name', 'image', 'artist_name', 'artist_id', 'license_url', 'tracks')
class Track(LazyQuery):
def __init__(self, ID, json=None):
return _OGGURL%(self.ID)
def _needs_load(self):
- return self._needs_load_impl('name', 'image', 'artist_name', 'album_name', 'album_id', 'numalbum', 'duration')
+ return self._needs_load_impl('name', 'artist_name', 'album_name', 'album_id', 'numalbum', 'duration')
def _set_from(self, other):
return self._set_from_impl(other, 'name', 'image', 'artist_name', 'album_name', 'album_id', 'numalbum', 'duration')
# TODO: cache queries?
class Query(object):
- last_query = time.time()
- rate_limit = 1.0 # max queries per second
+ rate_limit = 1.1 # seconds between queries
+ last_query = time.time() - 1.5
@classmethod
def _ratelimit(cls):
pass
def _geturl(self, url):
- print "geturl: %s" % (url)
+ print "*** %s" % (url)
+ Query._ratelimit()
f = urllib.urlopen(url)
ret = simplejson.load(f)
f.close()
self._covers[(int(m.group(1)), int(m.group(2)))] = fl
def fetch_cover(self, albumid, size):
- Query._ratelimit() # ratelimit cover fetching too?
coverdir = _COVERDIR if _COVERDIR else '/tmp'
to = os.path.join(coverdir, '%d-%d.jpg'%(albumid, size))
if not os.path.isfile(to):
},
'tracks' : {
'url' : _GET2+'+'.join(_TRACK_FIELDS)+'/track/json/track_album+album_artist?',
- 'params' : 'album_id=%d',
+ 'params' : 'order=numalbum_asc&album_id=%d',
'constructor' : [Track]
},
'radio' : {
'url' : _GET2+'+'.join(_TRACK_FIELDS)+'/track/json/radio_track_inradioplaylist+track_album+album_artist/?',
- 'params' : 'order=numradio_asc&radio_id=%d',
+ 'params' : 'order=random_asc&radio_id=%d',
'constructor' : [Track]
},
'favorite_albums' : {
class JamendoAPIException(Exception):
def __init__(self, url):
- Exception.__init__(url)
+ Exception.__init__(self, url)
def _update_cache(cache, new_items):
if not isinstance(new_items, list):
if not a:
raise JamendoAPIException(str(q))
_update_cache(_artists, a)
+ if isinstance(a, list):
+ a = a[0]
return a
def get_albums(artist_id):
if not a:
raise JamendoAPIException(str(q))
_update_cache(_albums, a)
+ if isinstance(a, list):
+ a = a[0]
return a
def get_tracks(album_id):
if not a:
raise JamendoAPIException(str(q))
_update_cache(_tracks, a)
+ if isinstance(a, list):
+ a = a[0]
return a
def get_radio_tracks(radio_id):
if not js:
raise JamendoAPIException(str(q))
if isinstance(js, list):
- return [Radio(x['id'], json=x) for x in js]
- else:
- return Radio(radio_id, json=js)
+ ks = js[0]
+ return Radio(radio_id, json=js)
def starred_radios():
"""Returns: [Radio]"""
def _album_loader(self):
if self._needs_load():
album = get_album(self.ID)
+ album.tracks = get_tracks(self.ID)
self._set_from(album)
Album.load = _album_loader