First, set_attr() needs to find the id of the current song. Second, we should save after changing attributes.
59 lines
1.1 KiB
Python
59 lines
1.1 KiB
Python
# Bryan Schumaker (8/8/2010)
|
|
|
|
import libsaria
|
|
call = libsaria.event.call
|
|
exists = libsaria.path.exists
|
|
expand = libsaria.path.expand
|
|
from libsaria import threads
|
|
|
|
import library
|
|
import playlist
|
|
import queue
|
|
|
|
controls = libsaria.controls
|
|
|
|
cur_source = None
|
|
class Source:
|
|
def __init__(self):
|
|
self.get_attrs = None
|
|
self.set_attr = None
|
|
self.get_cur_id = None
|
|
self.save = None
|
|
|
|
def set_current(self):
|
|
global cur_source
|
|
cur_source = self
|
|
|
|
def load_file(self, path):
|
|
global cur_source
|
|
# I should probably get a lock here...
|
|
try:
|
|
self.set_current()
|
|
controls.load(path)
|
|
return True
|
|
except:
|
|
return False
|
|
|
|
def get_attrs(*attrs):
|
|
# I should probably get a lock here...
|
|
if cur_source:
|
|
id = cur_source.get_cur_id()
|
|
return cur_source.get_attrs(id, *attrs)
|
|
return -1
|
|
|
|
def set_attr(attr, value):
|
|
if cur_source:
|
|
cur_source.set_attr(cur_source.get_cur_id(), attr, value)
|
|
cur_source.save()
|
|
|
|
def init_src(init_func, callback):
|
|
thr = threads.BG_Thread(init_func, callback)
|
|
thr.start()
|
|
|
|
def new_source(path, bg=True):
|
|
global library
|
|
path = expand(path)
|
|
if not exists(path):
|
|
return 0
|
|
return call("NEWSOURCE", library.scan, path)
|