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.
This commit is contained in:
parent
a9b5324889
commit
7f5d0cd458
|
@ -62,31 +62,37 @@ def file_to_id(file):
|
||||||
return res[0]
|
return res[0]
|
||||||
|
|
||||||
def get_attr(id, attr):
|
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)
|
rec = tracks.get(id, None)
|
||||||
if rec == None:
|
if rec == None:
|
||||||
return 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()
|
tags = rec.tags.walk_backwards()
|
||||||
if attr == "artist":
|
for attr in attrs:
|
||||||
return tags[0]
|
if attr == "id":
|
||||||
if attr == "album":
|
res += [id]
|
||||||
return tags[1]
|
elif attr == "filepath":
|
||||||
if attr == "title":
|
cmp = rec.fs.walk_backwards()
|
||||||
return tags[2]
|
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):
|
def inc_score(id, amount=1):
|
||||||
rec = tracks.get(id, None)
|
rec = tracks.get(id, None)
|
||||||
|
|
Loading…
Reference in New Issue