libsaria: Generic next() in sources
The sources module should choose between picking the next song from the playlist or the queue. It should also be in charge of tracking the current song id.
This commit is contained in:
parent
d99e7a4955
commit
0908588325
|
@ -36,9 +36,7 @@ def init2():
|
|||
|
||||
def pick_next():
|
||||
global pause_after
|
||||
file = queue.next()
|
||||
if file == None:
|
||||
file = playlist.next()
|
||||
file = sources.next()
|
||||
load(file)
|
||||
if pause_after == True:
|
||||
pause()
|
||||
|
|
|
@ -12,6 +12,8 @@ import queue
|
|||
controls = libsaria.controls
|
||||
|
||||
cur_source = None
|
||||
cur_id = None
|
||||
|
||||
class Source:
|
||||
def __init__(self):
|
||||
self.get_attrs = None
|
||||
|
@ -35,9 +37,8 @@ class Source:
|
|||
|
||||
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)
|
||||
if cur_id:
|
||||
return cur_source.get_attrs(cur_id, *attrs)
|
||||
return -1
|
||||
|
||||
def set_attr(attr, value):
|
||||
|
@ -60,3 +61,10 @@ def new_source(path, bg=True):
|
|||
def play_id(id):
|
||||
library.play_id(id)
|
||||
queue.rm_id(id)
|
||||
|
||||
def next():
|
||||
global cur_id
|
||||
cur_id = queue.next()
|
||||
if cur_id == None:
|
||||
cur_id = playlist.next()
|
||||
return library.get_attrs(cur_id, "filepath")
|
||||
|
|
|
@ -202,4 +202,4 @@ def next():
|
|||
recent.pop(0)
|
||||
source.set_current()
|
||||
save()
|
||||
return library.get_attrs(id, "filepath")
|
||||
return id
|
||||
|
|
|
@ -22,7 +22,6 @@ def init():
|
|||
source = libsaria.sources.Source()
|
||||
source.get_attrs = library.get_attrs
|
||||
source.set_attr = library.set_attr
|
||||
source.get_cur_id = get_cur_id
|
||||
source.save = save
|
||||
|
||||
def save():
|
||||
|
@ -50,9 +49,6 @@ def filter(text):
|
|||
visible = song_set
|
||||
filtered = False
|
||||
|
||||
def get_cur_id():
|
||||
return cur_id
|
||||
|
||||
def is_visible(id):
|
||||
if filtered == True:
|
||||
return id in visible
|
||||
|
@ -77,10 +73,5 @@ def play_id(id):
|
|||
return False
|
||||
|
||||
def next():
|
||||
global cur_id
|
||||
if len(queue.queue_list) == 0:
|
||||
return None
|
||||
cur_id = queue.pop()
|
||||
source.set_current()
|
||||
return library.get_attrs(cur_id, "filepath")
|
||||
return queue.pop()
|
||||
|
||||
|
|
Loading…
Reference in New Issue