ocarina/src/core/rand.py

53 lines
1.1 KiB
Python

# This is a simple test plugin, to make sure everything is working
__author__="bjschuma"
__date__ ="$Jan 2, 2010 1:14:04 PM$"
global name, app, type, path, opt
name = "rand"
app = "ocarina"
type = "core"
path = ""
opt = []
from bt.message import write
from tools import database
import random
import settings
def next():
cur = str(settings.get("curlib"))
count = database.select("count(*)","libtrack","library="+cur).fetchone()[0]
id = random.randint(0,count)
rows = database.select("track","libtrack","library="+cur).fetchall()
id = rows[id][0]
return id,id
# Called every time the plugin is enabled
def open():
if settings.has("random") == False:
settings.set("random",False)
else:
settings.set("next",next)
# Called every time the plugin is stopped
def close():
pass
# Called when the plugin needs to perform some action
def run(args=None):
if args==None or len(args)==0:
settings.replace("random",not settings.get("random"))
random = settings.get("random")
if random == True:
settings.set("next",next)
else:
settings.pop("next")
elif args[0]=="?":
write(str(settings.get("random")))