libsaria: Introduce libsaria.sources.all_attrs()
This patch introduces a new function "all_attrs()" which will return a dictionary containing all the attributes for the current song. To help the gui, I pass this dictionary during an on_load() callback.
This commit is contained in:
parent
5a735aa625
commit
645b70b33c
|
@ -15,7 +15,8 @@ def pause():
|
||||||
|
|
||||||
on_load = null_cb
|
on_load = null_cb
|
||||||
def load_file(file):
|
def load_file(file):
|
||||||
on_load(file)
|
attrs = libsaria.sources.all_attrs()
|
||||||
|
on_load(file, attrs)
|
||||||
|
|
||||||
on_like = null_cb
|
on_like = null_cb
|
||||||
def like_song(like):
|
def like_song(like):
|
||||||
|
|
|
@ -36,6 +36,16 @@ def find_attrs(file, *attr_list):
|
||||||
res.append(get(attr))
|
res.append(get(attr))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def find_all_attrs(file, attrs):
|
||||||
|
if file == None:
|
||||||
|
return False
|
||||||
|
track = library.track.Track(file)
|
||||||
|
if track == None:
|
||||||
|
return False
|
||||||
|
id = library.update.song_id(file)
|
||||||
|
attrs.update(track.__dict__)
|
||||||
|
attrs["id"] = id
|
||||||
|
|
||||||
# Function pointer to avoid unnecessary lookups for a common function
|
# Function pointer to avoid unnecessary lookups for a common function
|
||||||
get_attrs_id = library.get_attrs
|
get_attrs_id = library.get_attrs
|
||||||
|
|
||||||
|
@ -53,6 +63,21 @@ def get_attrs(*attrs):
|
||||||
res = [None] * len(attrs)
|
res = [None] * len(attrs)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def all_attrs():
|
||||||
|
global cur_id
|
||||||
|
res = {}
|
||||||
|
found = True
|
||||||
|
if cur_id:
|
||||||
|
found = library.all_attrs(cur_id, res)
|
||||||
|
if found == False:
|
||||||
|
cur_id = None
|
||||||
|
file = libsaria.audio.get_cur_file()
|
||||||
|
found = find_all_attrs(file, res)
|
||||||
|
if found != False:
|
||||||
|
res["like"] = attrs.get_like("like")
|
||||||
|
res["count"] = attrs.get_count("count")
|
||||||
|
return res
|
||||||
|
|
||||||
def filter(text):
|
def filter(text):
|
||||||
visible = library.filter(text)
|
visible = library.filter(text)
|
||||||
playlist.set_visible(visible)
|
playlist.set_visible(visible)
|
||||||
|
|
|
@ -36,6 +36,9 @@ def set_dattr(id, attribute, value):
|
||||||
save_dattrs()
|
save_dattrs()
|
||||||
unlock_dattrs()
|
unlock_dattrs()
|
||||||
|
|
||||||
|
def get_like(id):
|
||||||
|
return get_dattr(id, "like")
|
||||||
|
|
||||||
def get_count(id):
|
def get_count(id):
|
||||||
count = get_dattr(id, "count")
|
count = get_dattr(id, "count")
|
||||||
if count != None:
|
if count != None:
|
||||||
|
|
|
@ -9,6 +9,7 @@ import index
|
||||||
# Function pointers for conveniance
|
# Function pointers for conveniance
|
||||||
add_path = library.add_path
|
add_path = library.add_path
|
||||||
get_attrs = library.get_attrs
|
get_attrs = library.get_attrs
|
||||||
|
all_attrs = library.all_attrs
|
||||||
list_ids = tree.list_ids
|
list_ids = tree.list_ids
|
||||||
filter = index.filter
|
filter = index.filter
|
||||||
is_visible = index.is_visible
|
is_visible = index.is_visible
|
||||||
|
|
|
@ -74,3 +74,13 @@ def get_attrs(id, *attrs):
|
||||||
unlock_library()
|
unlock_library()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def all_attrs(id, attrs):
|
||||||
|
lock_library()
|
||||||
|
found = False
|
||||||
|
track = find_id(id)
|
||||||
|
if track != None:
|
||||||
|
attrs.update(track.__dict__)
|
||||||
|
attrs["id"] = id
|
||||||
|
found = True
|
||||||
|
unlock_library()
|
||||||
|
return found
|
||||||
|
|
|
@ -16,7 +16,7 @@ def on_pause():
|
||||||
footer.on_pause()
|
footer.on_pause()
|
||||||
callbacks.on_pause = on_pause
|
callbacks.on_pause = on_pause
|
||||||
|
|
||||||
def on_load(file):
|
def on_load(file, attrs):
|
||||||
footer.on_load()
|
footer.on_load()
|
||||||
queue.refresh()
|
queue.refresh()
|
||||||
body.cur_page_goto()
|
body.cur_page_goto()
|
||||||
|
|
Loading…
Reference in New Issue