From 2c26652772c8eaa9e7bec848339f966ff9919a36 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Tue, 5 Jan 2010 17:25:49 -0500 Subject: [PATCH] Can list and switch between libraries --- src/core/extract.py | 13 +++++++++++ src/core/lslib.py | 44 ++++++++++++++++++++++++++++++++++++++ src/core/next.py | 21 ++++++++++-------- src/core/rand.py | 10 +++++++-- src/core/switchlib.py | 38 ++++++++++++++++++++++++++++++++ src/core/tools/database.py | 23 +++++++++++++------- 6 files changed, 130 insertions(+), 19 deletions(-) create mode 100644 src/core/lslib.py create mode 100644 src/core/switchlib.py diff --git a/src/core/extract.py b/src/core/extract.py index 0bd6c692..261dca90 100644 --- a/src/core/extract.py +++ b/src/core/extract.py @@ -66,6 +66,15 @@ def findId(table,name): return result[0],True +def insLibTrk(trid): + libid = settings.get("curlib") + lib = str(libid) + trk = str(trid) + result = database.select("*","libtrack","track="+trk+" and library="+lib).fetchone() + if result == None: + return True,libid + return False,-1 + # Called when the plugin needs to perform some action def run(file=None): @@ -114,3 +123,7 @@ def run(file=None): if inserted == False: a = f.audioProperties() database.insert("track", (trid,arid,alid,0,a.length,title,file[len(root):])) + + ins,libid = insLibTrk(trid) + if ins == True: + database.insert("libtrack", (libid,trid)) diff --git a/src/core/lslib.py b/src/core/lslib.py new file mode 100644 index 00000000..bd14071d --- /dev/null +++ b/src/core/lslib.py @@ -0,0 +1,44 @@ +# This is a simple test plugin, to make sure everything is working + +__author__="bjschuma" +__date__ ="$Jan 5, 2010 4:15:27 PM$" + + +global name, app, type, path, opt +name = "lslib" +app = "ocarina" +type = "core" +path = "" +opt = [] + +from bt.message import write +from tools import database +import settings + + +# Called every time the plugin is enabled +def open(): + pass + + +# Called every time the plugin is stopped +def close(): + pass + + +# Called when the plugin needs to perform some action +def run(args=None): + cur = str(settings.get("curlib")) + result = database.select("name","library","id="+str(cur)).fetchone()[0] + + write("Current Library: "+result) + + result = database.select("*","library").fetchall() + if len(result) == 0: + return + + write("Name\tPath") + write("------------") + + for lib in result: + write(lib[1]+"\t"+lib[2]) diff --git a/src/core/next.py b/src/core/next.py index b90ed6cb..d8460c7d 100644 --- a/src/core/next.py +++ b/src/core/next.py @@ -19,13 +19,16 @@ 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 + cur = str(settings.get("curlib")) + count = database.select("count(*)","libtrack","library="+cur).fetchone()[0] + + curtrk = settings.get("current") + if curtrk > count: + curtrk = 0 + else: + curtrk += 1 + rows = database.select("track","libtrack","library="+cur).fetchall() + return rows[curtrk][0],curtrk @@ -47,12 +50,12 @@ def run(args=None): if settings.has("curlib") == False: return curlib = str(settings.get("curlib")) - id = settings.get("next")() + id,curtrk = settings.get("next")() 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) + settings.set("current",curtrk) manager.run("load",([a+b])) manager.run("play") diff --git a/src/core/rand.py b/src/core/rand.py index c3d88853..a3393eb7 100644 --- a/src/core/rand.py +++ b/src/core/rand.py @@ -18,14 +18,20 @@ import settings def next(): - count = database.count("track") - return random.randint(0,count) + 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 diff --git a/src/core/switchlib.py b/src/core/switchlib.py new file mode 100644 index 00000000..b2e98a52 --- /dev/null +++ b/src/core/switchlib.py @@ -0,0 +1,38 @@ +# This is a simple test plugin, to make sure everything is working + +__author__="bjschuma" +__date__ ="$Jan 5, 2010 4:15:12 PM$" + + +global name, app, type, path, opt +name = "switchlib" +app = "ocarina" +type = "core" +path = "" +opt = [] + +from bt.message import write +from tools import database +import settings + + +# Called every time the plugin is enabled +def open(): + 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 == 0: + return + + name = args[0] + write("Switching to: "+name) + + result = database.select("id","library","name=\'"+name+"\'").fetchone()[0] + settings.replace("curlib",int(result)) diff --git a/src/core/tools/database.py b/src/core/tools/database.py index a897620f..7a9d3982 100644 --- a/src/core/tools/database.py +++ b/src/core/tools/database.py @@ -72,16 +72,15 @@ def create(): path TEXT UNIQUE ); + CREATE TABLE libtrack + ( + library INTEGER, + track INTEGER + ); + """) - global vals - vals["files"] = "?" - vals["artist"]= "?,?" - vals["album"] = "?,?" - vals["library"] = "?,?,?" - vals["track"] = "?,?,?,?,?,?,?" - def open(): @@ -105,12 +104,20 @@ def commit(): def init(): - global db + global db, vals db = join(settings.get("user"),"ocarina.db") dbExists = checkPath(db) open() + # Create database if it doesn't exist yet if dbExists == False: create() + # Fill out information for all values + vals["files"] = "?" + vals["artist"]= "?,?" + vals["album"] = "?,?" + vals["library"] = "?,?,?" + vals["track"] = "?,?,?,?,?,?,?" + vals["libtrack"] = "?,?" close()