libsaria: Added library getattrs
I search for attributes using the new library first. If the song isn't found in the new library, then I fall back on the old library.
This commit is contained in:
parent
66d5314b6e
commit
254483dd5b
|
@ -78,12 +78,15 @@ def next():
|
|||
|
||||
def list_source(list_func, *attrs):
|
||||
ret = []
|
||||
get_attrs = oldlibrary.get_attrs
|
||||
get_attrs = library.get_attrs
|
||||
append = ret.append
|
||||
for id in list_func():
|
||||
append(get_attrs(id, *attrs))
|
||||
return ret
|
||||
|
||||
def list_library(*attrs):
|
||||
return list_source(library.list_ids, *attrs)
|
||||
|
||||
def list_playlist(*attrs):
|
||||
return list_source(playlist.list_ids, *attrs)
|
||||
|
||||
|
|
|
@ -5,8 +5,13 @@ import update
|
|||
import tree
|
||||
|
||||
# Function pointers for conveniance
|
||||
add_path = library.add_path
|
||||
add_path = library.add_path
|
||||
get_attrs = library.get_attrs
|
||||
list_ids = tree.list_ids
|
||||
|
||||
def update_lib():
|
||||
update.update()
|
||||
tree.make_tree()
|
||||
|
||||
def num_visible():
|
||||
return library.size()
|
||||
|
|
|
@ -9,8 +9,40 @@ unlock_library = library_lock.release
|
|||
# Map directory -> dict()
|
||||
lib_dict = dict()
|
||||
|
||||
|
||||
def add_path(path):
|
||||
lock_library()
|
||||
lib_dict.setdefault(path, dict())
|
||||
unlock_library()
|
||||
|
||||
def find_id(id):
|
||||
for src, tracks in lib_dict.iteritems():
|
||||
track = tracks.get(id, None)
|
||||
if track != None:
|
||||
return track
|
||||
|
||||
def size():
|
||||
res = 0
|
||||
lock_library()
|
||||
for src, tracks in lib_dict.iteritems():
|
||||
res += len(tracks)
|
||||
unlock_library()
|
||||
return res
|
||||
|
||||
def get_attrs(id, *attrs):
|
||||
lock_library()
|
||||
track = find_id(id)
|
||||
if track == None:
|
||||
unlock_library()
|
||||
from libsaria.sources import oldlibrary
|
||||
return oldlibrary.get_attrs(id, *attrs)
|
||||
|
||||
get = track.__dict__.get
|
||||
res = []
|
||||
for attr in attrs:
|
||||
if attr == "id":
|
||||
res.append(id)
|
||||
else:
|
||||
res.append(get(attr))
|
||||
unlock_library()
|
||||
return res
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user