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):
|
def list_source(list_func, *attrs):
|
||||||
ret = []
|
ret = []
|
||||||
get_attrs = oldlibrary.get_attrs
|
get_attrs = library.get_attrs
|
||||||
append = ret.append
|
append = ret.append
|
||||||
for id in list_func():
|
for id in list_func():
|
||||||
append(get_attrs(id, *attrs))
|
append(get_attrs(id, *attrs))
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def list_library(*attrs):
|
||||||
|
return list_source(library.list_ids, *attrs)
|
||||||
|
|
||||||
def list_playlist(*attrs):
|
def list_playlist(*attrs):
|
||||||
return list_source(playlist.list_ids, *attrs)
|
return list_source(playlist.list_ids, *attrs)
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,13 @@ import update
|
||||||
import tree
|
import tree
|
||||||
|
|
||||||
# Function pointers for conveniance
|
# 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():
|
def update_lib():
|
||||||
update.update()
|
update.update()
|
||||||
tree.make_tree()
|
tree.make_tree()
|
||||||
|
|
||||||
|
def num_visible():
|
||||||
|
return library.size()
|
||||||
|
|
|
@ -9,8 +9,40 @@ unlock_library = library_lock.release
|
||||||
# Map directory -> dict()
|
# Map directory -> dict()
|
||||||
lib_dict = dict()
|
lib_dict = dict()
|
||||||
|
|
||||||
|
|
||||||
def add_path(path):
|
def add_path(path):
|
||||||
lock_library()
|
lock_library()
|
||||||
lib_dict.setdefault(path, dict())
|
lib_dict.setdefault(path, dict())
|
||||||
unlock_library()
|
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