145 lines
2.9 KiB
Python
145 lines
2.9 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
|
|
library = lens.Library()
|
|
playlist = lens.Playlist()
|
|
|
|
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
|
|
library.reset()
|
|
return call("NEWSOURCE", library.scan, path)
|
|
|
|
def walk_library():
|
|
global library
|
|
for track in library.walk_tags():
|
|
yield track
|
|
|
|
def lib_get_attr(id, attr):
|
|
global library
|
|
if id >= 0:
|
|
return library.get_attr(id, attr)
|
|
|
|
def lib_inc_count(id):
|
|
global library
|
|
if id >= 0:
|
|
library.inc_count(id)
|
|
library.save()
|
|
|
|
def lib_inc_score(id, amount=1):
|
|
global library
|
|
if id >= 0:
|
|
library.inc_score(id, amount)
|
|
library.save()
|
|
|
|
def lib_play_id(id):
|
|
global cur_lib_id
|
|
cur_lib_id = id
|
|
filepath = lib_get_attr(id, "filepath")
|
|
libsaria.music.load(filepath)
|
|
libsaria.music.play()
|
|
|
|
def lib_find_id(file):
|
|
global library
|
|
return library.find_id(file)
|
|
|
|
def lib_get_cur_id():
|
|
global cur_lib_id
|
|
return cur_lib_id
|
|
|
|
def lib_filter(text):
|
|
global library
|
|
library.filter(text)
|
|
|
|
def lib_is_visible(text):
|
|
global library
|
|
return library.is_visible(text)
|
|
|
|
def walk_plist():
|
|
global playlist
|
|
global library
|
|
get_attr = library.get_attr
|
|
for id in playlist.walk_ids():
|
|
yield [get_attr(id, "artist"), get_attr(id, "album"),
|
|
get_attr(id, "title"), id, get_attr(id, "year"),
|
|
get_attr(id, "lenstr")]
|
|
|
|
def plist_save():
|
|
global playlist
|
|
playlist.save()
|
|
|
|
def plist_add_libid(lib_id):
|
|
global playlist
|
|
# Hey, Future Bryan. I really want to use a lib_get_attrs() function
|
|
# to return a list of attributes. Can you do that for me, please?
|
|
# Thank you, Past Bryan
|
|
artist = lib_get_attr(lib_id, "artist")
|
|
album = lib_get_attr(lib_id, "album")
|
|
title = lib_get_attr(lib_id, "title")
|
|
playlist.insert_tags(artist, album, title, lib_id)
|
|
|
|
def plist_is_visible(id):
|
|
global playlist
|
|
return playlist.is_visible(id)
|
|
|
|
def plist_filter(text):
|
|
global playlist
|
|
return playlist.filter(text)
|
|
|
|
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", lib_play_id, next)
|
|
|
|
def change_score():
|
|
prcnt = libsaria.music.get_progress()
|
|
if prcnt > 0.75:
|
|
lib_inc_count(cur_lib_id)
|
|
lib_inc_score(cur_lib_id)
|
|
if prcnt < 0.33:
|
|
lib_inc_score(cur_lib_id, -1)
|
|
|
|
def plist_next():
|
|
change_score()
|
|
choose_next()
|
|
|
|
def catch_eos(arg=None):
|
|
lib_inc_count(cur_lib_id)
|
|
lib_inc_score(cur_lib_id)
|
|
choose_next()
|
|
libsaria.event.invite("POSTEOS", catch_eos)
|
|
|
|
|