From 7f5d0cd458264125ebc8a48f9cb8d3ddb3588a7f Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Mon, 8 Nov 2010 22:15:49 -0500 Subject: [PATCH] Library get_attrs() get_attrs() will return a list of requested attributes for a given song id. For now, I have changed get_attr() into a wrapper around get_attrs that returns the first entry in the result list. --- libsaria/collection/library.py | 46 +++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/libsaria/collection/library.py b/libsaria/collection/library.py index 66a15970..4aa1dff2 100644 --- a/libsaria/collection/library.py +++ b/libsaria/collection/library.py @@ -62,31 +62,37 @@ def file_to_id(file): return res[0] def get_attr(id, attr): + print "Please don't use library.get_attr..." + return get_attrs(id, attr)[0] + +def get_attrs(id, *attrs): + res = [] rec = tracks.get(id, None) if rec == None: return None - if attr == "filepath": - cmp = rec.fs.walk_backwards() - return libsaria.path.sep.join([""] + cmp) - if attr == "playcount": - return rec.count - if attr == "year": - return rec.year - if attr == "lenstr": - return rec.lenstr - if attr == "score": - return rec.score - if attr == "art": - from libsaria import lastfm - return lastfm.get_artwork_id(id) + get = rec.__dict__.get tags = rec.tags.walk_backwards() - if attr == "artist": - return tags[0] - if attr == "album": - return tags[1] - if attr == "title": - return tags[2] + for attr in attrs: + if attr == "id": + res += [id] + elif attr == "filepath": + cmp = rec.fs.walk_backwards() + res += [libsaria.path.sep.join([""] + cmp)] + elif attr == "art": + from libsaria import lastfm + res += [lastfm.get_artwork_id(id)] + elif attr == "artist": + res += [tags[0]] + elif attr == "album": + res += [tags[1]] + elif attr == "title": + res += [tags[2]] + else: + res += [get(attr, None)] + return res + + def inc_score(id, amount=1): rec = tracks.get(id, None)