ocarina/libsaria/collection/__init__.py

79 lines
1.5 KiB
Python

# Bryan Schumaker (8/8/2010)
__all__ = ["collection"]
import libsaria
import tagpy
call = libsaria.event.call
exists = libsaria.path.exists
expand = libsaria.path.expand
FileRef = tagpy.FileRef
LIBRARY = 0
PLAYLIST = 1
QUEUE = 2
import lens
import library
import playlist
file_to_id = library.file_to_id
play_id = library.play_id
get_attrs = library.get_attrs
reset = library.reset
inc_score = library.inc_score
inc_count = library.inc_count
def init():
libsaria.init_pref("random", False)
libsaria.event.invite("POSTINIT", init)
def toggle_rand():
libsaria.prefs["random"] = not libsaria.prefs["random"]
cur_lib_id = -1
def new_source(path, bg=True):
global library
path = expand(path)
if not exists(path):
return 0
return call("NEWSOURCE", library.scan, path)
def lib_get_cur_id():
global cur_lib_id
return cur_lib_id
def plist_refresh():
return call("PLISTREFRESH")
#def choose_next():
# global playlist
# global cur_lib_id
# if libsaria.prefs["random"] == True:
# next = playlist.random()
# else:
# next = playlist.next_id(cur_lib_id)
# if next != None:
# return call("NEXT", play_id, next)
def change_score():
prcnt = libsaria.audio.get_progress()
if prcnt > 0.75:
inc_count(cur_lib_id)
inc_score(cur_lib_id)
if prcnt < 0.33:
inc_score(cur_lib_id, -1)
def plist_next():
change_score()
playlist.next()
def catch_eos(*args):
inc_count(cur_lib_id)
inc_score(cur_lib_id)
playlist.next()
libsaria.event.invite("POSTEOS", catch_eos)