libsaria: Add dynamic attributes
Dynamic attributes are attributes of a track that can change during run time (like status, playcount, etc). I only initialize these when they are first set, and I save after each change. This patch adds in the dattr framework and the "like" dattr.
This commit is contained in:
parent
466b0a2c5b
commit
49f7829706
|
@ -8,7 +8,9 @@ expand = libsaria.path.expand
|
|||
import library
|
||||
import playlist
|
||||
import queue
|
||||
import attrs
|
||||
|
||||
attrs.load_dattrs()
|
||||
cur_id = None
|
||||
|
||||
def inc_count():
|
||||
|
@ -21,11 +23,14 @@ def find_attrs(file, *attrs):
|
|||
track = library.track.Track(file)
|
||||
if track == None:
|
||||
return
|
||||
id = library.update.song_id(file)
|
||||
get = track.__dict__.get
|
||||
res = []
|
||||
for attr in attrs:
|
||||
if attr == "id":
|
||||
res.append(library.update.song_id(file))
|
||||
res.append(id)
|
||||
elif attr == "like":
|
||||
res.append(attrs.get_dattr(id, "like"))
|
||||
else:
|
||||
res.append(get(attr))
|
||||
return res
|
||||
|
@ -55,9 +60,9 @@ def is_visible(id):
|
|||
return library.is_visible(id)
|
||||
|
||||
def set_attr(attr, value):
|
||||
if cur_source:
|
||||
cur_source.set_attr(cur_id, attr, value)
|
||||
cur_source.save()
|
||||
id = get_attrs("id")[0]
|
||||
if id:
|
||||
attrs.set_dattr(id, attr, value)
|
||||
|
||||
def make_library(path):
|
||||
path = expand(path)
|
||||
|
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
import threading
|
||||
from libsaria import storage
|
||||
from libsaria.sources import attrs
|
||||
|
||||
library_lock = threading.Lock()
|
||||
lock_library = library_lock.acquire
|
||||
unlock_library = library_lock.release
|
||||
get_dattr = attrs.get_dattr
|
||||
|
||||
# Map directory -> dict()
|
||||
lib_dict = None
|
||||
|
@ -62,6 +64,8 @@ def get_attrs(id, *attrs):
|
|||
for attr in attrs:
|
||||
if attr == "id":
|
||||
res.append(id)
|
||||
elif attr == "like":
|
||||
res.append(get_dattr(id, attr))
|
||||
else:
|
||||
res.append(get(attr))
|
||||
unlock_library()
|
||||
|
|
Loading…
Reference in New Issue