From e5dfd01a0d41d3cf3d5f1040a08b7e3e6c07ecb5 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Sat, 2 Jan 2010 13:59:16 -0500 Subject: [PATCH] Can choose a random song --- src/core/create.py | 2 ++ src/core/load.py | 1 + src/core/next.py | 55 ++++++++++++++++++++++++++++++++++++++ src/core/ocarina.py | 4 +-- src/core/rand.py | 46 +++++++++++++++++++++++++++++++ src/core/tools/database.py | 2 +- 6 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 src/core/next.py create mode 100644 src/core/rand.py diff --git a/src/core/create.py b/src/core/create.py index 6bc4c0ed..01a6eb99 100644 --- a/src/core/create.py +++ b/src/core/create.py @@ -20,6 +20,7 @@ import settings # Called every time the plugin is enabled def open(): + settings.set("curlib",-1) pass @@ -45,6 +46,7 @@ def library(args): # Insert the library into the database database.open() next = database.count('library') + settings.replace("curlib",next) database.insert('library',(next,name,root) ) database.close() diff --git a/src/core/load.py b/src/core/load.py index 8316bc94..5249e25c 100644 --- a/src/core/load.py +++ b/src/core/load.py @@ -37,6 +37,7 @@ def close(): def run(args=None): if args == None: return + gstreamer.close() if len(args) == 1: gstreamer.load(args[0]) else: diff --git a/src/core/next.py b/src/core/next.py new file mode 100644 index 00000000..b85b5348 --- /dev/null +++ b/src/core/next.py @@ -0,0 +1,55 @@ +# This is a simple test plugin, to make sure everything is working + +__author__="bjschuma" +__date__ ="$Jan 2, 2010 1:18:37 PM$" + + +global name, app, type, path, opt +name = "next" +app = "ocarina" +type = "core" +path = "" +opt = [] + +from bt.message import write +from bt.file import join +import settings +from tools import database +from manager import manager + + +def next(): + cur = settings.get("current") + database.open() + count = database.count("track") + database.close() + if cur == count: + return 0 + return cur+1 + + + +# Called every time the plugin is enabled +def open(): + settings.set("current",0) + settings.set("next",next) + pass + + +# Called every time the plugin is stopped +def close(): + pass + + +# Called when the plugin needs to perform some action +def run(args=None): + id = settings.get("next")() + curlib = str(settings.get("curlib")) + + database.open() + a = database.select("path","library","id="+curlib).fetchone()[0] + b = database.select("path","track","id="+str(id)).fetchone()[0] + database.close() + settings.set("current",id) + manager.run("load",([a+b])) + manager.run("play") diff --git a/src/core/ocarina.py b/src/core/ocarina.py index 8e52a78a..46624dc1 100644 --- a/src/core/ocarina.py +++ b/src/core/ocarina.py @@ -22,12 +22,10 @@ from manager import manager from tools import database -#settings.set("ocarina", join(settings.get("user"),".ocarina2") ) settings.set("user", join(settings.get("user"),".ocarina2")) -manager.restoresession() mkdir(settings.get("user")) +manager.restoresession() bt.proc.setname("Ocarina2") -#from tools import library # Called every time the plugin is enabled diff --git a/src/core/rand.py b/src/core/rand.py new file mode 100644 index 00000000..6aa19016 --- /dev/null +++ b/src/core/rand.py @@ -0,0 +1,46 @@ +# 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(): + count = database.count("track") + return random.randint(0,count) + + +# Called every time the plugin is enabled +def open(): + settings.set("random",False) + pass + + +# 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"))) diff --git a/src/core/tools/database.py b/src/core/tools/database.py index 10458527..a897620f 100644 --- a/src/core/tools/database.py +++ b/src/core/tools/database.py @@ -106,7 +106,7 @@ def commit(): def init(): global db - db = join(settings.get("ocarina"),"ocarina.db") + db = join(settings.get("user"),"ocarina.db") dbExists = checkPath(db) open() if dbExists == False: